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

relay/api: replace "context" by "buffer_id" (issue #2081)

This commit is contained in:
Sébastien Helleu
2024-03-10 14:28:44 +01:00
parent 48ca390f79
commit bb346f8c6c
3 changed files with 27 additions and 28 deletions
+19 -8
View File
@@ -116,13 +116,15 @@ relay_api_msg_send_json_internal (struct t_relay_client *client,
const char *message,
const char *event_name,
const char *event_type,
const char *event_context,
struct t_gui_buffer *event_buffer,
const char *headers,
cJSON *json_body)
{
cJSON *json, *json_event;
int num_bytes;
char *string;
const char *ptr_id;
char *string, *error;
long long id;
if (!client || !message)
return -1;
@@ -151,9 +153,18 @@ relay_api_msg_send_json_internal (struct t_relay_client *client,
cJSON_AddItemToObject (
json_event, "type",
cJSON_CreateString ((event_type) ? event_type : ""));
id = -1;
if (event_buffer)
{
ptr_id = weechat_buffer_get_string (event_buffer, "id");
error = NULL;
id = strtoll (ptr_id, &error, 10);
if (!error || error[0])
id = -1;
}
cJSON_AddItemToObject (
json_event, "context",
cJSON_CreateString ((event_context) ? event_context : ""));
json_event, "buffer_id",
cJSON_CreateNumber (id));
cJSON_AddItemToObject (json, "event", json_event);
}
}
@@ -200,7 +211,7 @@ relay_api_msg_send_json (struct t_relay_client *client,
message,
NULL, /* event_name */
NULL, /* event_type */
NULL, /* event_context */
NULL, /* event_buffer */
NULL, /* headers */
json_body);
}
@@ -247,7 +258,7 @@ relay_api_msg_send_error_json (struct t_relay_client *client,
message,
NULL, /* event_name */
NULL, /* event_type */
NULL, /* event_context */
NULL, /* event_buffer */
headers,
json);
cJSON_Delete (json);
@@ -285,14 +296,14 @@ int
relay_api_msg_send_event (struct t_relay_client *client,
const char *name,
const char *type,
const char *context,
struct t_gui_buffer *buffer,
cJSON *json_body)
{
return relay_api_msg_send_json_internal (client,
RELAY_API_HTTP_0_EVENT,
name,
type,
context,
buffer,
NULL, /* headers */
json_body);
}
+1 -1
View File
@@ -34,7 +34,7 @@ extern int relay_api_msg_send_error_json (struct t_relay_client *client,
extern int relay_api_msg_send_event (struct t_relay_client *client,
const char *name,
const char *type,
const char *context,
struct t_gui_buffer *buffer,
cJSON *json_body);
extern cJSON *relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer,
long lines,
+7 -19
View File
@@ -103,7 +103,7 @@ relay_api_protocol_signal_buffer_cb (const void *pointer, void *data,
ptr_buffer, lines, 0, RELAY_API_DATA(ptr_client, sync_colors));
if (json)
{
relay_api_msg_send_event (ptr_client, signal, "buffer", "", json);
relay_api_msg_send_event (ptr_client, signal, "buffer", NULL, json);
cJSON_Delete (json);
}
}
@@ -127,12 +127,8 @@ relay_api_protocol_signal_buffer_cb (const void *pointer, void *data,
ptr_line_data, RELAY_API_DATA(ptr_client, sync_colors));
if (json)
{
relay_api_msg_send_event (
ptr_client,
signal,
"line",
weechat_buffer_get_string (ptr_buffer, "full_name"),
json);
relay_api_msg_send_event (ptr_client, signal, "line", ptr_buffer,
json);
cJSON_Delete (json);
}
}
@@ -178,12 +174,8 @@ relay_api_protocol_hsignal_nicklist_cb (const void *pointer, void *data,
json = relay_api_msg_nick_group_to_json (ptr_group);
if (json)
{
relay_api_msg_send_event (
ptr_client,
signal,
"nick_group",
weechat_buffer_get_string (ptr_buffer, "full_name"),
json);
relay_api_msg_send_event (ptr_client, signal, "nick_group",
ptr_buffer, json);
cJSON_Delete (json);
}
}
@@ -194,12 +186,8 @@ relay_api_protocol_hsignal_nicklist_cb (const void *pointer, void *data,
json = relay_api_msg_nick_to_json (ptr_nick);
if (json)
{
relay_api_msg_send_event (
ptr_client,
signal,
"nick",
weechat_buffer_get_string (ptr_buffer, "full_name"),
json);
relay_api_msg_send_event (ptr_client, signal, "nick", ptr_buffer,
json);
cJSON_Delete (json);
}
}