1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

relay: flatten JSON event object sent to api relay clients

This commit is contained in:
Sébastien Helleu
2024-06-29 18:43:08 +02:00
parent 86c4f3979a
commit 2184af9d99
5 changed files with 47 additions and 81 deletions
+1
View File
@@ -4,6 +4,7 @@
### Changed
- **breaking:** relay: flatten JSON event object sent to api relay clients
- **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))
+17 -30
View File
@@ -1457,16 +1457,15 @@ The messages sent to client have the following fields:
* `code`: `0`
* `message`: `Event`
* `event`: object with the following fields:
** `name` (string): the event name (name of signal or hsignal)
** `buffer_id` (integer): the buffer unique identifier, set only for sub-objects,
-1 in other cases
* `event_name` (string): the event name (name of signal or hsignal)
* `buffer_id` (integer): the buffer unique identifier, set only for sub-objects,
-1 in other cases
The following events are sent to the client, according to synchronization options:
[width="100%",cols="5,3,3,5",options="header"]
|===
| Event | Buffer id | Body type | Body
| Event name | Buffer id | Body type | Body
| `buffer_opened` | buffer id | `buffer` | buffer with all lines and nicks
| `buffer_type_changed` | buffer id | `buffer` | buffer
| `buffer_moved` | buffer id | `buffer` | buffer
@@ -1497,7 +1496,7 @@ The following events are sent to the client, according to synchronization option
|===
[NOTE]
^(1)^ The `upgrade` and `upgrade_ended` events are sent only if the client is
^(1)^ The events `upgrade` and `upgrade_ended` are sent only if the client is
connected with plain text (no TLS), because with TLS the client is disconnected
before the upgrade is done (upgrade of TLS connections is not supported).
@@ -1508,10 +1507,8 @@ Example: new buffer: channel `#weechat` has been joined:
{
"code": 0,
"message": "Event",
"event": {
"name": "buffer_opened",
"buffer_id": 1709932823649069
},
"event_name": "buffer_opened",
"buffer_id": 1709932823649069,
"body_type": "buffer",
"body": {
"id": 1709932823649069,
@@ -1550,10 +1547,8 @@ Example: new line displayed on channel `#weechat`:
{
"code": 0,
"message": "Event",
"event": {
"name": "buffer_line_added",
"buffer_id": 1709932823649069
},
"event_name": "buffer_line_added",
"buffer_id": 1709932823649069,
"body_type": "line",
"body": {
"id": 5,
@@ -1585,10 +1580,8 @@ Example: nick `bob` added with operator status in channel `#weechat`:
{
"code": 0,
"message": "Event",
"event": {
"name": "nicklist_nick_added",
"buffer_id": 1709932823649069
},
"event_name": "nicklist_nick_added",
"buffer_id": 1709932823649069,
"body_type": "nick",
"body": {
"id": 1709932823649902,
@@ -1611,10 +1604,8 @@ Example: channel buffer `#weechat` has been closed:
{
"code": 0,
"message": "Event",
"event": {
"name": "buffer_closed",
"buffer_id": 1709932823649069
}
"event_name": "buffer_closed",
"buffer_id": 1709932823649069
}
----
@@ -1625,10 +1616,8 @@ Example: WeeChat is upgrading:
{
"code": 0,
"message": "Event",
"event": {
"name": "upgrade",
"buffer_id": -1
}
"event_name": "upgrade",
"buffer_id": -1
}
----
@@ -1639,9 +1628,7 @@ Example: upgrade of WeeChat is done:
{
"code": 0,
"message": "Event",
"event": {
"name": "upgrade_ended",
"buffer_id": -1
}
"event_name": "upgrade_ended",
"buffer_id": -1
}
----
+16 -29
View File
@@ -1483,16 +1483,15 @@ Les messages envoyés au client ont les champs suivants :
* `code` : `0`
* `message` : `Event`
* `event` : objet avec les champs suivants :
** `name` (chaîne) : le nom de l'évènement (nom du signal ou hsignal)
** `buffer_id` (entier) : l'identifiant unique du tampon, défini seulement pour
les sous-objets, -1 dans les autres cas
* `event_name` (chaîne) : le nom de l'évènement (nom du signal ou hsignal)
* `buffer_id` (entier) : l'identifiant unique du tampon, défini seulement pour
les sous-objets, -1 dans les autres cas
Les évènements suivants sont envoyés au client, selon les options de synchronisation :
[width="100%",cols="5,3,3,5",options="header"]
|===
| Évènement | Id tampon | Type de corps | Corps
| Nom d'évènement | Id tampon | Type de corps | Corps
| `buffer_opened` | id tampon | `buffer` | tampon avec les lignes et pseudos
| `buffer_type_changed` | id tampon | `buffer` | tampon
| `buffer_moved` | id tampon | `buffer` | tampon
@@ -1535,10 +1534,8 @@ Exemple : nouveau tampon : le canal `#weechat` a été rejoint :
{
"code": 0,
"message": "Event",
"event": {
"name": "buffer_opened",
"buffer_id": 1709932823649069
},
"event_name": "buffer_opened",
"buffer_id": 1709932823649069,
"body_type": "buffer",
"body": {
"id": 1709932823649069,
@@ -1577,10 +1574,8 @@ Exemple : nouvelle ligne affichée sur le canal `#weechat` :
{
"code": 0,
"message": "Event",
"event": {
"name": "buffer_line_added",
"buffer_id": 1709932823649069
},
"event_name": "buffer_line_added",
"buffer_id": 1709932823649069,
"body_type": "line",
"body": {
"id": 5,
@@ -1612,10 +1607,8 @@ Exemple : le pseudo `bob` est ajouté avec le statut opérateur sur le canal `#
{
"code": 0,
"message": "Event",
"event": {
"name": "nicklist_nick_added",
"buffer_id": 1709932823649069
},
"event_name": "nicklist_nick_added",
"buffer_id": 1709932823649069,
"body_type": "nick",
"body": {
"id": 1709932823649902,
@@ -1638,10 +1631,8 @@ Exemple : le tampon du canal `#weechat` a été fermé :
{
"code": 0,
"message": "Event",
"event": {
"name": "buffer_closed",
"buffer_id": 1709932823649069
}
"event_name": "buffer_closed",
"buffer_id": 1709932823649069
}
----
@@ -1652,10 +1643,8 @@ Exemple : WeeChat est en cours de mise à jour :
{
"code": 0,
"message": "Event",
"event": {
"name": "upgrade",
"buffer_id": -1
}
"event_name": "upgrade",
"buffer_id": -1
}
----
@@ -1666,9 +1655,7 @@ Exemple : la mise à jour de WeeChat est terminée :
{
"code": 0,
"message": "Event",
"event": {
"name": "upgrade_ended",
"buffer_id": -1
}
"event_name": "upgrade_ended",
"buffer_id": -1
}
----
+7 -12
View File
@@ -130,7 +130,7 @@ relay_api_msg_send_json_internal (struct t_relay_client *client,
const char *body_type,
cJSON *json_body)
{
cJSON *json, *json_event;
cJSON *json;
char *string, *request;
int num_bytes, length;
@@ -152,17 +152,12 @@ relay_api_msg_send_json_internal (struct t_relay_client *client,
cJSON_AddItemToObject (json, "message", cJSON_CreateString (message));
if (event_name)
{
json_event = cJSON_CreateObject ();
if (json_event)
{
cJSON_AddItemToObject (
json_event, "name",
cJSON_CreateString ((event_name) ? event_name : ""));
cJSON_AddItemToObject (
json_event, "buffer_id",
cJSON_CreateNumber (event_buffer_id));
cJSON_AddItemToObject (json, "event", json_event);
}
cJSON_AddItemToObject (
json, "event_name",
cJSON_CreateString ((event_name) ? event_name : ""));
cJSON_AddItemToObject (
json, "buffer_id",
cJSON_CreateNumber (event_buffer_id));
}
else
{
@@ -1079,8 +1079,8 @@ end:
void
relay_remote_event_recv (struct t_relay_remote *remote, const char *data)
{
cJSON *json, *json_body, *json_event, *json_obj;
const char *body_type, *name;
cJSON *json, *json_body, *json_obj;
const char *body_type, *event_name;
long long buffer_id;
int i, rc, code;
struct t_relay_remote_event_cb event_cb[] = {
@@ -1121,19 +1121,15 @@ relay_remote_event_recv (struct t_relay_remote *remote, const char *data)
JSON_GET_NUM(json, code, -1);
JSON_GET_STR(json, body_type);
json_event = cJSON_GetObjectItem (json, "event");
json_body = cJSON_GetObjectItem (json, "body");
if (!body_type && ((code == 200) || (code == 204)))
return;
if (json_event && cJSON_IsObject (json_event))
{
JSON_GET_STR(json_event, name);
event.name = name;
JSON_GET_NUM(json_event, buffer_id, -1);
event.buffer = relay_remote_event_search_buffer (remote, buffer_id);
}
JSON_GET_STR(json, event_name);
event.name = event_name;
JSON_GET_NUM(json, buffer_id, -1);
event.buffer = relay_remote_event_search_buffer (remote, buffer_id);
callback = NULL;