From cac5717b41def8e6334bd45dd1ade08a6ded984f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 30 Jun 2024 13:01:29 +0200 Subject: [PATCH] relay/api: add body types `buffers` and `lines` (array) --- CHANGELOG.md | 2 +- doc/en/weechat_relay_api.en.adoc | 21 +++++++++------ doc/fr/weechat_relay_api.fr.adoc | 21 +++++++++------ src/plugins/relay/api/relay-api-protocol.c | 30 ++++++++++++++-------- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b0202a16..838d28252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Changed -- **breaking:** relay/api: flatten JSON event object sent to clients, always set "body_type" and "body" (null if there is no body) in websocket frame, add field "request_id" in websocket frame (request and response) +- **breaking:** relay/api: flatten JSON event object sent to clients, always set "body_type" and "body" (null if there is no body) in websocket frame, add body types `buffers` and `lines` (array), add field "request_id" in websocket frame (request and response) - **breaking:** core, plugins: force "short_name" in buffers to non-empty value (name by default), remove buffer property "short_name_is_set" - **breaking:** alias: display an error with `/alias add` or `/alias addcompletion` when the alias already exists, add options `addreplace` and `addreplacecompletion` in command `/alias` ([#2095](https://github.com/weechat/weechat/issues/2095)) - **breaking:** irc: rename parameter `-re` to `-raw` in command `/list` ([#2124](https://github.com/weechat/weechat/issues/2124)) diff --git a/doc/en/weechat_relay_api.en.adoc b/doc/en/weechat_relay_api.en.adoc index 1b3743717..6d444022e 100644 --- a/doc/en/weechat_relay_api.en.adoc +++ b/doc/en/weechat_relay_api.en.adoc @@ -1390,14 +1390,19 @@ Responses to client are made with a JSON object containing these fields: Body types that can be returned: -* `handshake` -* `version` -* `buffer` -* `line` -* `nick_group` -* `nick` -* `hotlist` -* `ping` +* `handshake` (object) +* `version` (object) +* `buffers` (array) +* `buffer` (object) +* `lines` (array) +* `line` (object) +* `nick_group` (object) +* `nick` (object) +* `hotlist` (object) +* `ping` (object) + +[TIP] +You can browse these schemas online: https://weechat.org/api/[WeeChat Relay API ^↗^^]. Request example: get version: diff --git a/doc/fr/weechat_relay_api.fr.adoc b/doc/fr/weechat_relay_api.fr.adoc index 24058cba3..6030f20a9 100644 --- a/doc/fr/weechat_relay_api.fr.adoc +++ b/doc/fr/weechat_relay_api.fr.adoc @@ -1417,14 +1417,19 @@ les champs suivants : Les types de corps qui peuvent être retournés : -* `handshake` -* `version` -* `buffer` -* `line` -* `nick_group` -* `nick` -* `hotlist` -* `ping` +* `handshake` (objet) +* `version` (objet) +* `buffers` (tableau) +* `buffer` (objet) +* `lines` (tableau) +* `line` (objet) +* `nick_group` (objet) +* `nick` (objet) +* `hotlist` (objet) +* `ping` (objet) + +[TIP] +Vous pouvez parcourir les schémas en ligne : https://weechat.org/api/[API relay WeeChat ^↗^^]. Exemple de requête : obtenir la version : diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c index f0f41f4b0..69982b5c6 100644 --- a/src/plugins/relay/api/relay-api-protocol.c +++ b/src/plugins/relay/api/relay-api-protocol.c @@ -576,16 +576,21 @@ RELAY_API_PROTOCOL_CALLBACK(buffers) return RELAY_API_PROTOCOL_RC_OK; } json = relay_api_msg_line_data_to_json (ptr_line_data, colors); + if (json) + { + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, NULL, + "line", json); + } } else { lines = relay_http_get_param_long (client->http_req, "lines", LONG_MAX); json = relay_api_msg_lines_to_json (ptr_buffer, lines, colors); - } - if (json) - { - relay_api_msg_send_json (client, RELAY_HTTP_200_OK, NULL, - "line", json); + if (json) + { + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, NULL, + "lines", json); + } } } else if (strcmp (client->http_req->path_items[3], "nicks") == 0) @@ -619,6 +624,11 @@ RELAY_API_PROTOCOL_CALLBACK(buffers) { json = relay_api_msg_buffer_to_json (ptr_buffer, lines, lines_free, nicks, colors); + if (json) + { + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, NULL, + "buffer", json); + } } else { @@ -635,11 +645,11 @@ RELAY_API_PROTOCOL_CALLBACK(buffers) nicks, colors)); ptr_buffer = weechat_hdata_move (relay_hdata_buffer, ptr_buffer, 1); } - } - if (json) - { - relay_api_msg_send_json (client, RELAY_HTTP_200_OK, NULL, - "buffer", json); + if (json) + { + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, NULL, + "buffers", json); + } } }