1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Split long IRC `ACTION' messages

Add line splitting logic to commands `/me' and `/action'.
This commit is contained in:
Sebastian Thorarensen 2014-06-17 18:17:28 +02:00
parent 90f3dd612e
commit bb7bafc93c
3 changed files with 42 additions and 8 deletions

View File

@ -44,6 +44,9 @@
static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{ {
const char *target; const char *target;
char *subdata;
char **splitdata;
int n = 0;
CMD_IRC_SERVER(server); CMD_IRC_SERVER(server);
if (!IS_IRC_ITEM(item)) if (!IS_IRC_ITEM(item))
@ -53,10 +56,13 @@ static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
cmd_return_error(CMDERR_NOT_CONNECTED); cmd_return_error(CMDERR_NOT_CONNECTED);
target = window_item_get_target(item); target = window_item_get_target(item);
irc_server_send_action(server, target, data); splitdata = irc_server_split_action(server, target, data);
while ((subdata = splitdata[n++])) {
signal_emit("message irc own_action", 3, server, data, irc_server_send_action(server, target, subdata);
item->visible_name); signal_emit("message irc own_action", 3, server, subdata,
item->visible_name);
}
g_strfreev(splitdata);
} }
/* SYNTAX: ACTION [-<server tag>] <target> <message> */ /* SYNTAX: ACTION [-<server tag>] <target> <message> */
@ -64,6 +70,9 @@ static void cmd_action(const char *data, IRC_SERVER_REC *server)
{ {
GHashTable *optlist; GHashTable *optlist;
const char *target, *text; const char *target, *text;
char *subtext;
char **splittexts;
int n = 0;
void *free_arg; void *free_arg;
CMD_IRC_SERVER(server); CMD_IRC_SERVER(server);
@ -79,10 +88,14 @@ static void cmd_action(const char *data, IRC_SERVER_REC *server)
if (server == NULL || !server->connected) if (server == NULL || !server->connected)
cmd_param_error(CMDERR_NOT_CONNECTED); cmd_param_error(CMDERR_NOT_CONNECTED);
irc_server_send_action(server, target, text); splittexts = irc_server_split_action(server, target, text);
while ((subtext = splittexts[n++])) {
signal_emit("message irc own_action", 3, server, text, target); irc_server_send_action(server, target, subtext);
signal_emit("message irc own_action", 3, server, subtext,
target);
}
g_strfreev(splittexts);
cmd_params_free(free_arg); cmd_params_free(free_arg);
} }

View File

@ -450,6 +450,24 @@ void irc_server_send_action(IRC_SERVER_REC *server, const char *target, const ch
g_free(recoded); g_free(recoded);
} }
char **irc_server_split_action(IRC_SERVER_REC *server, const char *target,
const char *data)
{
/* See split_message() on how the maximum length is calculated. */
int userhostlen = 63 + 10 + 1;
g_return_val_if_fail(server != NULL, NULL);
g_return_val_if_fail(target != NULL, NULL);
g_return_val_if_fail(data != NULL, NULL);
if (server->userhost != NULL)
userhostlen = strlen(server->userhost);
return split_line(SERVER(server), data, target,
510 - strlen(":! PRIVMSG :\001ACTION \001") -
strlen(server->nick) - userhostlen - strlen(target));
}
void irc_server_send_away(IRC_SERVER_REC *server, const char *reason) void irc_server_send_away(IRC_SERVER_REC *server, const char *reason)
{ {
char *recoded = NULL; char *recoded = NULL;

View File

@ -117,7 +117,10 @@ void irc_server_purge_output(IRC_SERVER_REC *server, const char *target);
char *irc_server_get_channels(IRC_SERVER_REC *server); char *irc_server_get_channels(IRC_SERVER_REC *server);
/* INTERNAL: */ /* INTERNAL: */
void irc_server_send_action(IRC_SERVER_REC *server, const char *target, const char *data); void irc_server_send_action(IRC_SERVER_REC *server, const char *target,
const char *data);
char **irc_server_split_action(IRC_SERVER_REC *server, const char *target,
const char *data);
void irc_server_send_away(IRC_SERVER_REC *server, const char *reason); void irc_server_send_away(IRC_SERVER_REC *server, const char *reason);
void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len); void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len);
void irc_server_init_isupport(IRC_SERVER_REC *server); void irc_server_init_isupport(IRC_SERVER_REC *server);