From b00f94dc70f25487e2945f867e205b2bcf93ef2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 10 Aug 2024 10:25:23 +0200 Subject: [PATCH] relay/api: add field "hidden" in GET /api/buffers (issue #2159) --- CHANGELOG.md | 1 + doc/en/weechat_relay_api.en.adoc | 7 +++++++ src/plugins/relay/api/relay-api-msg.c | 1 + src/plugins/relay/api/weechat-relay-api.yaml | 5 +++++ tests/unit/plugins/relay/api/test-relay-api-msg.cpp | 11 +++++++++++ 5 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f47bae1..48b852bba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - core: allow buffer id in commands `/buffer` and `/print`, in addition to number and name - core: allow mask in command `/item refresh` - relay: enable websocket extension "permessage-deflate" with "api" relay only ([#1549](https://github.com/weechat/weechat/issues/1549)) +- relay/api: add field "hidden" in GET /api/buffers ([#2159](https://github.com/weechat/weechat/issues/2159)) - relay/weechat: add line id in buffer lines sent to clients - relay: display connection status in output of commands `/remote list` and `/remote listfull` - relay: add option `reconnect` in command `/remote` ([#2160](https://github.com/weechat/weechat/issues/2160)) diff --git a/doc/en/weechat_relay_api.en.adoc b/doc/en/weechat_relay_api.en.adoc index b0c0b529d..5d2d5f64d 100644 --- a/doc/en/weechat_relay_api.en.adoc +++ b/doc/en/weechat_relay_api.en.adoc @@ -489,6 +489,7 @@ HTTP/1.1 200 OK "short_name": "weechat", "number": 1, "type": "formatted", + "hidden": false, "title": "WeeChat 4.2.0-dev (C) 2003-2023 - https://weechat.org/", "modes": "", "input_prompt": "", @@ -510,6 +511,7 @@ HTTP/1.1 200 OK "short_name": "libera", "number": 2, "type": "formatted", + "hidden": false, "title": "IRC: irc.libera.chat/6697 (2001:4b7a:a008::6667)", "modes": "", "input_prompt": "", @@ -538,6 +540,7 @@ HTTP/1.1 200 OK "short_name": "#weechat", "number": 3, "type": "formatted", + "hidden": false, "title": "Welcome to the WeeChat official support channel", "modes": "+nt", "input_prompt": "\u001b[92m@\u001b[96malice\u001b[48;5;22m(\u001b[39mi\u001b[48;5;22m)", @@ -583,6 +586,7 @@ HTTP/1.1 200 OK "short_name": "weechat", "number": 1, "type": "formatted", + "hidden": false, "title": "WeeChat 4.2.0-dev (C) 2003-2023 - https://weechat.org/", "modes": "", "input_prompt": "", @@ -636,6 +640,7 @@ HTTP/1.1 200 OK "short_name": "#weechat", "number": 3, "type": "formatted", + "hidden": false, "title": "Welcome to the WeeChat official support channel", "modes": "+nt", "input_prompt": "\u001b[92m@\u001b[96malice\u001b[48;5;22m(\u001b[39mi\u001b[48;5;22m)", @@ -743,6 +748,7 @@ HTTP/1.1 200 OK "short_name": "", "number": 4, "type": "free", + "hidden": false, "title": "\u001b[96m1/\u001b[36m3565 | Filter: \u001b[93m* | Sort: \u001b[97m~name | Key(input): alt+space=toggle boolean, alt+'-'(-)=subtract 1 or set, alt+'+'(+)=add 1 or append, alt+f,alt+r(r)=reset, alt+f,alt+u(u)=unset, alt+enter(s)=set, alt+f,alt+n(n)=set new value, alt+f,alt+a(a)=append, alt+','=mark/unmark, shift+down=mark and move down, shift+up=move up and mark, ($)=refresh, ($$)=unmark/refresh, (m)=mark matching options, (u)=unmark matching options, alt+p(p)=toggle plugins desc, alt+v(v)=toggle help bar, ctrl+x(x)=switch format, (q)=close buffer", "modes": "", "input_prompt": "", @@ -1533,6 +1539,7 @@ Example: new buffer: channel `#weechat` has been joined: "short_name": "", "number": 4, "type": "formatted", + "hidden": false, "title": "", "modes": "+nt", "input_prompt": "\u001b[92m@\u001b[96malice\u001b[48;5;22m(\u001b[39mi\u001b[48;5;22m)", diff --git a/src/plugins/relay/api/relay-api-msg.c b/src/plugins/relay/api/relay-api-msg.c index 6c8cc8a8f..894d15c17 100644 --- a/src/plugins/relay/api/relay-api-msg.c +++ b/src/plugins/relay/api/relay-api-msg.c @@ -380,6 +380,7 @@ relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer, if (weechat_strcmp (ptr_string, "free") == 0) lines = lines_free; MSG_ADD_STR_PTR("type", ptr_string); + MSG_ADD_HDATA_VAR(Bool, "hidden", integer, "hidden"); MSG_ADD_HDATA_STR_COLORS("title", "title"); MSG_ADD_HDATA_STR_COLORS("modes", "modes"); MSG_ADD_HDATA_STR_COLORS("input_prompt", "input_prompt"); diff --git a/src/plugins/relay/api/weechat-relay-api.yaml b/src/plugins/relay/api/weechat-relay-api.yaml index 640d13157..0eb9d85c0 100644 --- a/src/plugins/relay/api/weechat-relay-api.yaml +++ b/src/plugins/relay/api/weechat-relay-api.yaml @@ -592,6 +592,10 @@ components: - free description: the buffer type example: formatted + hidden: + type: boolean + description: buffer is hidden + example: false title: type: string description: the buffer title (can contain colors) @@ -656,6 +660,7 @@ components: - short_name - number - type + - hidden - title - modes - input_prompt 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 ffa6945c4..fbf2fa11d 100644 --- a/tests/unit/plugins/relay/api/test-relay-api-msg.cpp +++ b/tests/unit/plugins/relay/api/test-relay-api-msg.cpp @@ -146,6 +146,7 @@ TEST(RelayApiMsg, BufferToJson) WEE_CHECK_OBJ_STR("weechat", json, "short_name"); WEE_CHECK_OBJ_NUM(1, json, "number"); WEE_CHECK_OBJ_STR("formatted", json, "type"); + WEE_CHECK_OBJ_BOOL(0, json, "hidden"); WEE_CHECK_OBJ_STRN("WeeChat", 7, json, "title"); WEE_CHECK_OBJ_BOOL(0, json, "nicklist"); WEE_CHECK_OBJ_BOOL(0, json, "nicklist_case_sensitive"); @@ -170,6 +171,16 @@ TEST(RelayApiMsg, BufferToJson) POINTERS_EQUAL(NULL, cJSON_GetObjectItem (json, "nicks")); cJSON_Delete (json); + gui_buffer_hide (gui_buffers); + + json = relay_api_msg_buffer_to_json (gui_buffers, 0L, 0L, 0, RELAY_API_COLORS_ANSI); + CHECK(json); + CHECK(cJSON_IsObject (json)); + WEE_CHECK_OBJ_BOOL(1, json, "hidden"); + cJSON_Delete (json); + + gui_buffer_unhide (gui_buffers); + /* buffer with 2 lines, without nicks */ json = relay_api_msg_buffer_to_json (gui_buffers, 2L, 0L, 0, RELAY_API_COLORS_ANSI); CHECK(json);