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

irc: add IRC message tags in messages displayed (closes #1680)

This commit is contained in:
Sébastien Helleu
2021-12-30 21:11:22 +01:00
parent 5c6fc8c4bd
commit b66298d369
9 changed files with 305 additions and 160 deletions
+1
View File
@@ -20,6 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
New features::
* irc: add IRC message tags in messages displayed (issue #1680)
* relay: add `zstd` (https://facebook.github.io/zstd/[Zstandard]) compression in weechat protocol, remove option `compression` from `init` command, rename option relay.network.compression_level to relay.network.compression
Bug fixes::
+1
View File
@@ -1442,6 +1442,7 @@ irc_channel_display_nick_back_in_pv (struct t_irc_server *server,
irc_protocol_tags (
"nick_back",
NULL,
NULL,
(nick) ? nick->name : NULL,
(nick) ? nick->host : NULL),
_("%s%s%s %s(%s%s%s)%s is back on server"),
+3
View File
@@ -915,6 +915,7 @@ irc_command_me_channel_display (struct t_irc_server *server,
channel->buffer,
0,
irc_protocol_tags ("privmsg",
NULL,
"irc_action,self_msg,notify_none,no_highlight",
server->nick, NULL),
"%s%s%s%s%s%s%s",
@@ -1746,6 +1747,7 @@ IRC_COMMAND_CALLBACK(ctcp)
ptr_server, ctcp_target, NULL, "ctcp", NULL),
0,
irc_protocol_tags ("privmsg",
NULL,
"irc_ctcp,self_msg,notify_none,no_highlight",
NULL, NULL),
_("%sCTCP query to %s%s%s: %s%s%s%s%s"),
@@ -3579,6 +3581,7 @@ IRC_COMMAND_CALLBACK(msg)
0,
irc_protocol_tags (
"privmsg",
NULL,
"self_msg,notify_none,no_highlight",
ptr_server->nick, NULL),
"%sMSG%s(%s%s%s)%s: %s",
+29 -17
View File
@@ -111,6 +111,7 @@ irc_ctcp_get_reply (struct t_irc_server *server, const char *ctcp)
void
irc_ctcp_display_request (struct t_irc_server *server,
time_t date,
struct t_hashtable *tags,
const char *command,
struct t_irc_channel *channel,
const char *nick,
@@ -129,7 +130,7 @@ irc_ctcp_display_request (struct t_irc_server *server,
server, nick, NULL, "ctcp",
(channel) ? channel->buffer : NULL),
date,
irc_protocol_tags (command, "irc_ctcp", NULL, address),
irc_protocol_tags (command, tags, "irc_ctcp", NULL, address),
_("%sCTCP requested by %s%s%s: %s%s%s%s%s%s"),
weechat_prefix ("network"),
irc_nick_color_for_msg (server, 0, NULL, nick),
@@ -149,6 +150,7 @@ irc_ctcp_display_request (struct t_irc_server *server,
void
irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
struct t_hashtable *tags,
const char *command, const char *nick,
const char *address, const char *arguments)
{
@@ -196,7 +198,7 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
irc_msgbuffer_get_target_buffer (
server, nick, NULL, "ctcp", NULL),
date,
irc_protocol_tags (command, "irc_ctcp", NULL, NULL),
irc_protocol_tags (command, tags, "irc_ctcp", NULL, NULL),
/* TRANSLATORS: %.3fs is a float number + "s" ("seconds") */
_("%sCTCP reply from %s%s%s: %s%s%s %.3fs"),
weechat_prefix ("network"),
@@ -215,7 +217,7 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
irc_msgbuffer_get_target_buffer (
server, nick, NULL, "ctcp", NULL),
date,
irc_protocol_tags (command, "irc_ctcp", NULL, address),
irc_protocol_tags (command, tags, "irc_ctcp", NULL, address),
_("%sCTCP reply from %s%s%s: %s%s%s%s%s"),
weechat_prefix ("network"),
irc_nick_color_for_msg (server, 0, NULL, nick),
@@ -234,7 +236,7 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
irc_msgbuffer_get_target_buffer (
server, nick, NULL, "ctcp", NULL),
date,
irc_protocol_tags (command, NULL, NULL, address),
irc_protocol_tags (command, tags, NULL, NULL, address),
_("%sCTCP reply from %s%s%s: %s%s%s%s%s"),
weechat_prefix ("network"),
irc_nick_color_for_msg (server, 0, NULL, nick),
@@ -259,9 +261,11 @@ irc_ctcp_display_reply_from_nick (struct t_irc_server *server, time_t date,
void
irc_ctcp_reply_to_nick (struct t_irc_server *server,
struct t_hashtable *tags,
const char *command,
struct t_irc_channel *channel,
const char *nick, const char *ctcp,
const char *nick,
const char *ctcp,
const char *arguments)
{
struct t_hashtable *hashtable;
@@ -307,6 +311,7 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
0,
irc_protocol_tags (
command,
tags,
"irc_ctcp,irc_ctcp_reply,self_msg,notify_none,"
"no_highlight",
NULL, NULL),
@@ -994,7 +999,8 @@ irc_ctcp_recv_dcc (struct t_irc_server *server, const char *nick,
*/
void
irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
irc_ctcp_recv (struct t_irc_server *server, time_t date,
struct t_hashtable *tags, const char *command,
struct t_irc_channel *channel, const char *address,
const char *nick, const char *remote_nick,
const char *arguments, const char *message)
@@ -1056,6 +1062,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
date,
irc_protocol_tags (
command,
tags,
(nick_is_me) ?
"irc_action,self_msg,notify_none,no_highlight" :
"irc_action,notify_message",
@@ -1098,6 +1105,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
date,
irc_protocol_tags (
command,
tags,
(nick_is_me) ?
"irc_action,self_msg,notify_none,no_highlight" :
"irc_action,notify_private",
@@ -1120,8 +1128,9 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
else if (weechat_strcasecmp (ptr_args + 1, "PING") == 0)
{
reply = irc_ctcp_get_reply (server, ptr_args + 1);
irc_ctcp_display_request (server, date, command, channel, nick,
address, ptr_args + 1, pos_args, reply);
irc_ctcp_display_request (server, date, tags, command, channel,
nick, address, ptr_args + 1, pos_args,
reply);
if (!reply || reply[0])
{
if (reply)
@@ -1129,15 +1138,16 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
decoded_reply = irc_ctcp_replace_variables (server, reply);
if (decoded_reply)
{
irc_ctcp_reply_to_nick (server, command, channel, nick,
ptr_args + 1, decoded_reply);
irc_ctcp_reply_to_nick (server, tags, command, channel,
nick, ptr_args + 1,
decoded_reply);
free (decoded_reply);
}
}
else
{
irc_ctcp_reply_to_nick (server, command, channel, nick,
ptr_args + 1, pos_args);
irc_ctcp_reply_to_nick (server, tags, command, channel,
nick, ptr_args + 1, pos_args);
}
}
}
@@ -1152,8 +1162,8 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
reply = irc_ctcp_get_reply (server, ptr_args + 1);
if (reply)
{
irc_ctcp_display_request (server, date, command, channel, nick,
address, ptr_args + 1, pos_args,
irc_ctcp_display_request (server, date, tags, command, channel,
nick, address, ptr_args + 1, pos_args,
reply);
if (reply[0])
@@ -1161,8 +1171,9 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
decoded_reply = irc_ctcp_replace_variables (server, reply);
if (decoded_reply)
{
irc_ctcp_reply_to_nick (server, command, channel, nick,
ptr_args + 1, decoded_reply);
irc_ctcp_reply_to_nick (server, tags, command, channel,
nick, ptr_args + 1,
decoded_reply);
free (decoded_reply);
}
}
@@ -1176,7 +1187,8 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
server, nick, NULL, "ctcp",
(channel) ? channel->buffer : NULL),
date,
irc_protocol_tags (command, "irc_ctcp", NULL, address),
irc_protocol_tags (command, tags, "irc_ctcp", NULL,
address),
_("%sUnknown CTCP requested by %s%s%s: %s%s%s%s%s"),
weechat_prefix ("network"),
irc_nick_color_for_msg (server, 0, NULL, nick),
+3 -1
View File
@@ -36,6 +36,7 @@ extern const char *irc_ctcp_get_reply (struct t_irc_server *server,
const char *ctcp);
extern void irc_ctcp_display_reply_from_nick (struct t_irc_server *server,
time_t date,
struct t_hashtable *tags,
const char *command,
const char *nick,
const char *address,
@@ -43,7 +44,8 @@ extern void irc_ctcp_display_reply_from_nick (struct t_irc_server *server,
extern char *irc_ctcp_replace_variables (struct t_irc_server *server,
const char *format);
extern void irc_ctcp_recv (struct t_irc_server *server, time_t date,
const char *command, struct t_irc_channel *channel,
struct t_hashtable *tags, const char *command,
struct t_irc_channel *channel,
const char *address, const char *nick,
const char *remote_nick, const char *arguments,
const char *message);
+6 -2
View File
@@ -102,7 +102,9 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, int action,
buffer,
0,
irc_protocol_tags (
"privmsg", str_tags,
"privmsg",
NULL,
str_tags,
(ptr_nick) ? ptr_nick->name : ptr_server->nick,
NULL),
"%s%s%s%s%s %s",
@@ -119,7 +121,9 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, int action,
buffer,
0,
irc_protocol_tags (
"privmsg", str_tags,
"privmsg",
NULL,
str_tags,
(ptr_nick) ? ptr_nick->name : ptr_server->nick,
NULL),
"%s%s",
File diff suppressed because it is too large Load Diff
+5 -2
View File
@@ -93,8 +93,11 @@ struct t_irc_protocol_msg
t_irc_recv_func *recv_function; /* function called when msg is received */
};
extern const char *irc_protocol_tags (const char *command, const char *tags,
const char *nick, const char *address);
extern const char *irc_protocol_tags (const char *command,
struct t_hashtable *irc_msg_tags,
const char *extra_tags,
const char *nick,
const char *address);
extern time_t irc_protocol_parse_time (const char *time);
extern void irc_protocol_recv_command (struct t_irc_server *server,
const char *irc_message,
+71 -31
View File
@@ -238,51 +238,91 @@ TEST(IrcProtocol, LogLevelForCommand)
TEST(IrcProtocol, Tags)
{
POINTERS_EQUAL(NULL, irc_protocol_tags (NULL, NULL, NULL, NULL));
struct t_hashtable *tags_empty, *tags_1, *tags_2;
tags_empty = hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
tags_1 = hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
hashtable_set (tags_1, "key1", "value1");
tags_2 = hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
hashtable_set (tags_2, "key1", "value1");
hashtable_set (tags_2, "key_2,comma", "value2,comma");
POINTERS_EQUAL(NULL, irc_protocol_tags (NULL, NULL, NULL, NULL, NULL));
/* command */
STRCMP_EQUAL("irc_privmsg,log1",
irc_protocol_tags ("privmsg", NULL, NULL, NULL));
irc_protocol_tags ("privmsg", NULL, NULL, NULL, NULL));
STRCMP_EQUAL("irc_join,log4",
irc_protocol_tags ("join", NULL, NULL, NULL));
irc_protocol_tags ("join", NULL, NULL, NULL, NULL));
/* command and empty tags */
/* command + irc_msg_tags */
STRCMP_EQUAL("irc_privmsg,log1",
irc_protocol_tags ("privmsg", "", NULL, NULL));
irc_protocol_tags ("privmsg", tags_empty, NULL, NULL, NULL));
STRCMP_EQUAL("irc_join,log4",
irc_protocol_tags ("join", "", NULL, NULL));
irc_protocol_tags ("join", tags_empty, NULL, NULL, NULL));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,log1",
irc_protocol_tags ("privmsg", tags_1, NULL, NULL, NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,log4",
irc_protocol_tags ("join", tags_1, NULL, NULL, NULL));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,log1",
irc_protocol_tags ("privmsg", tags_2, NULL, NULL, NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,log4",
irc_protocol_tags ("join", tags_2, NULL, NULL, NULL));
/* command and tags */
/* command + extra_tags */
STRCMP_EQUAL("irc_privmsg,log1",
irc_protocol_tags ("privmsg", NULL, "", NULL, NULL));
STRCMP_EQUAL("irc_join,log4",
irc_protocol_tags ("join", NULL, "", NULL, NULL));
STRCMP_EQUAL("irc_privmsg,tag1,tag2,log1",
irc_protocol_tags ("privmsg", "tag1,tag2", NULL, NULL));
irc_protocol_tags ("privmsg", NULL, "tag1,tag2", NULL, NULL));
STRCMP_EQUAL("irc_join,tag1,tag2,log4",
irc_protocol_tags ("join", "tag1,tag2", NULL, NULL));
irc_protocol_tags ("join", NULL, "tag1,tag2", NULL, NULL));
/* command, tags and empty nick */
STRCMP_EQUAL("irc_privmsg,tag1,tag2,log1",
irc_protocol_tags ("privmsg", "tag1,tag2", "", NULL));
STRCMP_EQUAL("irc_join,tag1,tag2,log4",
irc_protocol_tags ("join", "tag1,tag2", "", NULL));
/* command + irc_msg_tags + extra_tags + nick */
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,log1",
irc_protocol_tags ("privmsg", tags_2, "tag1,tag2", "", NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,log4",
irc_protocol_tags ("join", tags_2, "tag1,tag2", "", NULL));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_alice,log1",
irc_protocol_tags ("privmsg", tags_2, "tag1,tag2", "alice", NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_bob,log4",
irc_protocol_tags ("join", tags_2, "tag1,tag2", "bob", NULL));
/* command, tags and nick */
STRCMP_EQUAL("irc_privmsg,tag1,tag2,nick_alice,log1",
irc_protocol_tags ("privmsg", "tag1,tag2", "alice", NULL));
STRCMP_EQUAL("irc_join,tag1,tag2,nick_bob,log4",
irc_protocol_tags ("join", "tag1,tag2", "bob", NULL));
/* command, tags, nick and empty address */
STRCMP_EQUAL("irc_privmsg,tag1,tag2,nick_alice,log1",
irc_protocol_tags ("privmsg", "tag1,tag2", "alice", ""));
STRCMP_EQUAL("irc_join,tag1,tag2,nick_bob,log4",
irc_protocol_tags ("join", "tag1,tag2", "bob", ""));
/* command, tags, nick and address */
STRCMP_EQUAL("irc_privmsg,tag1,tag2,nick_alice,host_example.com,log1",
irc_protocol_tags ("privmsg", "tag1,tag2", "alice",
/* command + irc_msg_tags + extra_tags + nick + address */
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_alice,log1",
irc_protocol_tags ("privmsg", tags_2, "tag1,tag2", "alice", ""));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_bob,log4",
irc_protocol_tags ("join", tags_2, "tag1,tag2", "bob", ""));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_alice,host_example.com,log1",
irc_protocol_tags ("privmsg", tags_2, "tag1,tag2", "alice",
"example.com"));
STRCMP_EQUAL("irc_join,tag1,tag2,nick_bob,host_example.com,log4",
irc_protocol_tags ("join", "tag1,tag2", "bob",
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_bob,host_example.com,log4",
irc_protocol_tags ("join", tags_2, "tag1,tag2", "bob",
"example.com"));
hashtable_free (tags_empty);
hashtable_free (tags_1);
hashtable_free (tags_2);
}
/*