diff --git a/CHANGELOG.md b/CHANGELOG.md index b55c8e7a5..e2bca45e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - core: add condition on connected relay api clients in default value of option weechat.look.hotlist_add_conditions - core: add `/mute` in default command for key `Alt`+`=` (toggle filters) +- relay/api: add field "last_read_line_id" in GET /api/buffers ### Added diff --git a/doc/en/weechat_relay_api.en.adoc b/doc/en/weechat_relay_api.en.adoc index 2913bede4..492201bf1 100644 --- a/doc/en/weechat_relay_api.en.adoc +++ b/doc/en/weechat_relay_api.en.adoc @@ -541,7 +541,8 @@ HTTP/1.1 200 OK "plugin": "core", "name": "weechat" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 }, { "id": 1709932823423765, @@ -571,7 +572,8 @@ HTTP/1.1 200 OK "tls_version": "TLS1.3", "host": "~alice@example.com" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 }, { "id": 1709932823649069, @@ -599,7 +601,8 @@ HTTP/1.1 200 OK "nick": "alice", "host": "~alice@example.com" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 } ] ---- @@ -655,7 +658,8 @@ HTTP/1.1 200 OK "message": "Plugins loaded: alias, buflist, charset, exec, fifo, fset, guile, irc, javascript, logger, lua, perl, php, python, relay, ruby, script, spell, tcl, trigger, typing, xfer", "tags": [] } - ] + ], + "last_read_line_id": -1 } ---- @@ -702,6 +706,7 @@ HTTP/1.1 200 OK "host": "~alice@example.com" }, "keys": [], + "last_read_line_id": -1, "nicklist_root": { "id": 0, "parent_group_id": -1, @@ -900,7 +905,8 @@ HTTP/1.1 200 OK "key": "up", "command": "/fset -up" } - ] + ], + "last_read_line_id": -1 } ---- diff --git a/doc/fr/weechat_relay_api.fr.adoc b/doc/fr/weechat_relay_api.fr.adoc index 7fe0ef68e..366440772 100644 --- a/doc/fr/weechat_relay_api.fr.adoc +++ b/doc/fr/weechat_relay_api.fr.adoc @@ -551,7 +551,8 @@ HTTP/1.1 200 OK "plugin": "core", "name": "weechat" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 }, { "id": 1709932823423765, @@ -580,7 +581,8 @@ HTTP/1.1 200 OK "tls_version": "TLS1.3", "host": "~alice@example.com" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 }, { "id": 1709932823649069, @@ -607,7 +609,8 @@ HTTP/1.1 200 OK "nick": "alice", "host": "~alice@example.com" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 } ] ---- @@ -663,7 +666,8 @@ HTTP/1.1 200 OK "message": "Plugins loaded: alias, buflist, charset, exec, fifo, fset, guile, irc, javascript, logger, lua, perl, php, python, relay, ruby, script, spell, tcl, trigger, typing, xfer", "tags": [] } - ] + ], + "last_read_line_id": -1 } ---- @@ -709,6 +713,7 @@ HTTP/1.1 200 OK "host": "~alice@example.com" }, "keys": [], + "last_read_line_id": -1, "nicklist_root": { "id": 0, "parent_group_id": -1, @@ -906,7 +911,8 @@ HTTP/1.1 200 OK "key": "up", "command": "/fset -up" } - ] + ], + "last_read_line_id": -1 } ---- diff --git a/doc/sr/weechat_relay_api.sr.adoc b/doc/sr/weechat_relay_api.sr.adoc index 5abe80fcd..385d92a3a 100644 --- a/doc/sr/weechat_relay_api.sr.adoc +++ b/doc/sr/weechat_relay_api.sr.adoc @@ -543,7 +543,8 @@ HTTP/1.1 200 OK "plugin": "core", "name": "weechat" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 }, { "id": 1709932823423765, @@ -573,7 +574,8 @@ HTTP/1.1 200 OK "tls_version": "TLS1.3", "host": "~alice@example.com" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 }, { "id": 1709932823649069, @@ -601,7 +603,8 @@ HTTP/1.1 200 OK "nick": "alice", "host": "~alice@example.com" }, - "keys": [] + "keys": [], + "last_read_line_id": -1 } ] ---- @@ -657,7 +660,8 @@ HTTP/1.1 200 OK "message": "Учитани додаци: alias, buflist, charset, exec, fifo, fset, guile, irc, javascript, logger, lua, perl, php, python, relay, ruby, script, spell, tcl, trigger, typing, xfer", "tags": [] } - ] + ], + "last_read_line_id": -1 } ---- @@ -704,6 +708,7 @@ HTTP/1.1 200 OK "host": "~alice@example.com" }, "keys": [], + "last_read_line_id": -1, "nicklist_root": { "id": 0, "parent_group_id": -1, @@ -902,7 +907,8 @@ HTTP/1.1 200 OK "key": "up", "command": "/fset -up" } - ] + ], + "last_read_line_id": -1 } ---- diff --git a/src/plugins/relay/api/relay-api-msg.c b/src/plugins/relay/api/relay-api-msg.c index 0d62305b8..e018ba0e0 100644 --- a/src/plugins/relay/api/relay-api-msg.c +++ b/src/plugins/relay/api/relay-api-msg.c @@ -350,9 +350,13 @@ relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer, { struct t_hdata *hdata; struct t_gui_buffer *pointer; + struct t_gui_lines *ptr_lines; + struct t_gui_line *ptr_line; + struct t_gui_line_data *ptr_line_data; cJSON *json, *json_local_vars, *json_lines, *json_nicklist_root; const char *ptr_string; char *string; + int last_read_line_id; hdata = relay_hdata_buffer; pointer = buffer; @@ -405,6 +409,24 @@ relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer, if (json_lines) cJSON_AddItemToObject (json, "lines", json_lines); } + last_read_line_id = -1; + ptr_lines = weechat_hdata_pointer (relay_hdata_buffer, buffer, "own_lines"); + if (ptr_lines) + { + ptr_line = weechat_hdata_pointer (relay_hdata_lines, ptr_lines, "last_read_line"); + if (ptr_line) + { + ptr_line_data = weechat_hdata_pointer (relay_hdata_line, ptr_line, "data"); + if (ptr_line_data) + { + last_read_line_id = weechat_hdata_integer (relay_hdata_line_data, + ptr_line_data, "id"); + } + } + } + cJSON_AddItemToObject ( + json, "last_read_line_id", + cJSON_CreateNumber (last_read_line_id)); /* nicks */ if (nicks) diff --git a/src/plugins/relay/api/relay-api.h b/src/plugins/relay/api/relay-api.h index 30caf1fb2..60fab404c 100644 --- a/src/plugins/relay/api/relay-api.h +++ b/src/plugins/relay/api/relay-api.h @@ -26,8 +26,8 @@ struct t_relay_client; enum t_relay_status; #define RELAY_API_VERSION_MAJOR 0 -#define RELAY_API_VERSION_MINOR 4 -#define RELAY_API_VERSION_PATCH 1 +#define RELAY_API_VERSION_MINOR 5 +#define RELAY_API_VERSION_PATCH 0 #define RELAY_API_VERSION_NUMBER \ ((RELAY_API_VERSION_MAJOR << 16) \ + (RELAY_API_VERSION_MINOR << 8) \ diff --git a/src/plugins/relay/api/weechat-relay-api.yaml b/src/plugins/relay/api/weechat-relay-api.yaml index bd626c119..f44ec5aea 100644 --- a/src/plugins/relay/api/weechat-relay-api.yaml +++ b/src/plugins/relay/api/weechat-relay-api.yaml @@ -17,7 +17,7 @@ info: license: name: CC BY-NC-SA 4.0 url: https://creativecommons.org/licenses/by-nc-sa/4.0/ - version: 0.4.1 + version: 0.5.0 externalDocs: url: https://weechat.org/doc/ @@ -1043,6 +1043,11 @@ components: type: array items: $ref: '#/components/schemas/Line' + last_read_line_id: + type: integer + format: int64 + description: identifier of the last line read in the buffer (-1 if read marker is not displayed) + example: -1 nicklist_root: $ref: '#/components/schemas/NickGroup' required: diff --git a/tests/unit/plugins/relay/api/test-relay-api-msg.cpp b/tests/unit/plugins/relay/api/test-relay-api-msg.cpp index 72d92960f..2d273b9f8 100644 --- a/tests/unit/plugins/relay/api/test-relay-api-msg.cpp +++ b/tests/unit/plugins/relay/api/test-relay-api-msg.cpp @@ -177,6 +177,7 @@ TEST(RelayApiMsg, BufferToJson) WEE_CHECK_OBJ_STR("core", json_local_vars, "plugin"); WEE_CHECK_OBJ_STR("weechat", json_local_vars, "name"); POINTERS_EQUAL(NULL, cJSON_GetObjectItem (json, "lines")); + WEE_CHECK_OBJ_NUM(-1, json, "last_read_line_id"); POINTERS_EQUAL(NULL, cJSON_GetObjectItem (json, "nicks")); cJSON_Delete (json);