diff --git a/CHANGELOG.md b/CHANGELOG.md index cfafabe8e..4b0c9c96e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Changed -- **breaking:** relay: flatten JSON event object sent to api relay clients +- **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 - **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 f248f0467..7984cf8bf 100644 --- a/doc/en/weechat_relay_api.en.adoc +++ b/doc/en/weechat_relay_api.en.adoc @@ -1276,7 +1276,13 @@ Response: ---- { "code": 204, - "message": "No Content" + "message": "No Content", + "request": "POST /api/sync", + "request_body": { + "nicks":false + }, + "body_type": null, + "body": null } ---- @@ -1376,11 +1382,9 @@ Responses to client are made with a JSON object containing these fields: * `message` (string): message for the code (example: `OK`) * `request` (string): the request (example: `GET /api/buffers?lines=-100`) * `request_body` (object): the request body, or `null` if the request had no body - -When the response has a body, these two extra fields are returned: - -* `body_type` (string): type of objects returned in body (see below) -* `body` (object or array): the body returned +* `body_type` (string): type of objects returned in body (see below), or `null` + if the response has no body +* `body` (object or array): the body returned, or `null` if the response has no body Body types that can be returned: @@ -1446,7 +1450,9 @@ Response: "request_body": { "buffer_name": "irc.libera.#weechat", "command": "hello!" - } + }, + "body_type": null, + "body": null } ---- @@ -1480,13 +1486,13 @@ The following events are sent to the client, according to synchronization option | `buffer_localvar_removed` | buffer id | `buffer` | buffer | `buffer_cleared` | buffer id | `buffer` | buffer | `buffer_closing` | buffer id | `buffer` | buffer -| `buffer_closed` | buffer id | (not defined) | (not defined) +| `buffer_closed` | buffer id | null | null | `buffer_line_added` | buffer id | `line` | buffer line | `buffer_line_data_changed` | buffer id | `line` | buffer line | `input_text_changed` | buffer id | `buffer` | buffer | `input_text_cursor_moved` | buffer id | `buffer` | buffer -| `upgrade` ^(1)^ | -1 | (not defined) | (not defined) -| `upgrade_ended` ^(1)^ | -1 | (not defined) | (not defined) +| `upgrade` ^(1)^ | -1 | null | null +| `upgrade_ended` ^(1)^ | -1 | null | null | `nicklist_group_changed` | buffer id | `nick_group` | nick group | `nicklist_group_added` | buffer id | `nick_group` | nick group | `nicklist_group_removing` | buffer id | `nick_group` | nick group @@ -1605,7 +1611,9 @@ Example: channel buffer `#weechat` has been closed: "code": 0, "message": "Event", "event_name": "buffer_closed", - "buffer_id": 1709932823649069 + "buffer_id": 1709932823649069, + "body_type": null, + "body": null } ---- @@ -1617,7 +1625,9 @@ Example: WeeChat is upgrading: "code": 0, "message": "Event", "event_name": "upgrade", - "buffer_id": -1 + "buffer_id": -1, + "body_type": null, + "body": null } ---- @@ -1629,6 +1639,8 @@ Example: upgrade of WeeChat is done: "code": 0, "message": "Event", "event_name": "upgrade_ended", - "buffer_id": -1 + "buffer_id": -1, + "body_type": null, + "body": null } ---- diff --git a/doc/fr/weechat_relay_api.fr.adoc b/doc/fr/weechat_relay_api.fr.adoc index 35cf5ccef..9d41d954a 100644 --- a/doc/fr/weechat_relay_api.fr.adoc +++ b/doc/fr/weechat_relay_api.fr.adoc @@ -1297,7 +1297,13 @@ Réponse : ---- { "code": 204, - "message": "No Content" + "message": "No Content", + "request": "POST /api/sync", + "request_body": { + "nicks": false + }, + "body_type": null, + "body": null } ---- @@ -1401,11 +1407,10 @@ les champs suivants : * `request` (chaîne) : la requête (exemple : `GET /api/buffers?lines=-100`) * `request_body` (objet) : le corps de la requête, ou `null` si la requête n'avait pas de corps - -Lorsque la réponse a un corps, ces deux champs supplémentaires sont retournés : - -* `body_type` (chaîne) : type des objets retournés dans le corps (voir ci-dessous) -* `body` (objet ou tableau) : le corps retourné +* `body_type` (chaîne) : type des objets retournés dans le corps (voir ci-dessous), + ou `null` si la réponse n'a pas de corps +* `body` (objet ou tableau) : le corps retourné, ou `null` si la réponse n'a pas + de corps Les types de corps qui peuvent être retournés : @@ -1471,7 +1476,9 @@ Réponse : "request_body": { "buffer_name": "irc.libera.#weechat", "command": "hello!" - } + }, + "body_type": null, + "body": null } ---- @@ -1506,13 +1513,13 @@ Les évènements suivants sont envoyés au client, selon les options de synchron | `buffer_localvar_removed` | id tampon | `buffer` | tampon | `buffer_cleared` | id tampon | `buffer` | tampon | `buffer_closing` | id tampon | `buffer` | tampon -| `buffer_closed` | id tampon | (non défini) | (non défini) +| `buffer_closed` | id tampon | null | null | `buffer_line_added` | id tampon | `line` | ligne de tampon | `buffer_line_data_changed` | id tampon | `line` | ligne de tampon | `input_text_changed` | id tampon | `buffer` | tampon | `input_text_cursor_moved` | id tampon | `buffer` | tampon -| `upgrade` ^(1)^ | -1 | (non défini) | (non défini) -| `upgrade_ended` ^(1)^ | -1 | (non défini) | (non défini) +| `upgrade` ^(1)^ | -1 | null | null +| `upgrade_ended` ^(1)^ | -1 | null | null | `nicklist_group_changed` | id tampon | `nick_group` | groupe de pseudos | `nicklist_group_added` | id tampon | `nick_group` | groupe de pseudos | `nicklist_group_removing` | id tampon | `nick_group` | groupe de pseudos @@ -1632,7 +1639,9 @@ Exemple : le tampon du canal `#weechat` a été fermé : "code": 0, "message": "Event", "event_name": "buffer_closed", - "buffer_id": 1709932823649069 + "buffer_id": 1709932823649069, + "body_type": null, + "body": null } ---- @@ -1644,7 +1653,9 @@ Exemple : WeeChat est en cours de mise à jour : "code": 0, "message": "Event", "event_name": "upgrade", - "buffer_id": -1 + "buffer_id": -1, + "body_type": null, + "body": null } ---- @@ -1656,6 +1667,8 @@ Exemple : la mise à jour de WeeChat est terminée : "code": 0, "message": "Event", "event_name": "upgrade_ended", - "buffer_id": -1 + "buffer_id": -1, + "body_type": null, + "body": null } ---- diff --git a/src/plugins/relay/api/relay-api-msg.c b/src/plugins/relay/api/relay-api-msg.c index 8c4c7883e..15a8404c8 100644 --- a/src/plugins/relay/api/relay-api-msg.c +++ b/src/plugins/relay/api/relay-api-msg.c @@ -174,17 +174,17 @@ relay_api_msg_send_json_internal (struct t_relay_client *client, cJSON_AddItemToObject ( json, "request_body", (client->http_req->body) ? - cJSON_Parse (client->http_req->body) :cJSON_CreateNull ()); + cJSON_Parse (client->http_req->body) : cJSON_CreateNull ()); free (request); } } - if (body_type) - { - cJSON_AddItemToObject (json, "body_type", - cJSON_CreateString (body_type)); - } - if (json_body) - cJSON_AddItemToObject (json, "body", json_body); + cJSON_AddItemToObject ( + json, "body_type", + (body_type) ? + cJSON_CreateString (body_type) : cJSON_CreateNull ()); + cJSON_AddItemToObject ( + json, "body", + (json_body) ? json_body : cJSON_CreateNull ()); string = cJSON_PrintUnformatted (json); num_bytes = relay_client_send ( client, diff --git a/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp b/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp index 1f30085ee..ff8e41b9f 100644 --- a/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp +++ b/tests/unit/plugins/relay/api/test-relay-api-protocol.cpp @@ -58,7 +58,9 @@ extern int relay_api_protocol_command_delay; STRCMP_EQUAL("{\"code\":" #__code "," \ "\"message\":\"" __message "\"," \ "\"request\":\"" __request "\"," \ - "\"request_body\":" __body "" \ + "\"request_body\":" __body "," \ + "\"body_type\":null," \ + "\"body\":null" \ "}", \ data_sent);