From d2dbcc19993a8cf33258d0989b05305be34336a4 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Fri, 5 Oct 2018 15:37:27 +0200 Subject: [PATCH 1/3] Route notices intended for channels into the channel --- src/fe-common/irc/fe-irc-messages.c | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/fe-common/irc/fe-irc-messages.c b/src/fe-common/irc/fe-irc-messages.c index 89c501a8..56e479ab 100644 --- a/src/fe-common/irc/fe-irc-messages.c +++ b/src/fe-common/irc/fe-irc-messages.c @@ -202,6 +202,23 @@ static void sig_message_irc_action(IRC_SERVER_REC *server, const char *msg, static void sig_message_own_notice(IRC_SERVER_REC *server, const char *msg, const char *target) { + if (*msg == '[') { + /* check if this is a cnotice */ + char *end, *channel; + end = strpbrk(msg, " ,]"); + if (end != NULL && *end == ']') { + channel = g_strndup(msg + 1, end - msg - 1); + if (server_ischannel(SERVER(server), channel)) { + printformat(server, channel, + MSGLEVEL_NOTICES | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, + IRCTXT_OWN_NOTICE, target, msg); + g_free(channel); + return; + } + g_free(channel); + /* fall through. */ + } + } printformat(server, fe_channel_skip_prefix(server, target), MSGLEVEL_NOTICES | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, IRCTXT_OWN_NOTICE, target, msg); @@ -233,11 +250,28 @@ static void sig_message_irc_notice(SERVER_REC *server, const char *msg, msg, &level, TRUE)) return; - if (server_ischannel(SERVER(server), target)) { + if (server_ischannel(SERVER(server), target)) { /* notice in some channel */ printformat(server, target, level, IRCTXT_NOTICE_PUBLIC, nick, oldtarget, msg); } else { + if (*msg == '[') { + /* check if this is a cnotice */ + char *end, *channel; + end = strpbrk(msg, " ,]"); + if (end != NULL && *end == ']') { + channel = g_strndup(msg + 1, end - msg - 1); + if (server_ischannel(SERVER(server), channel)) { + printformat(server, channel, level, IRCTXT_NOTICE_PRIVATE, + nick, address, msg); + g_free(channel); + return; + } + g_free(channel); + /* fall through. */ + } + } + /* private notice */ privmsg_get_query(SERVER(server), nick, FALSE, MSGLEVEL_NOTICES); From 08ac2ee5beebdfd374caccf76a7e63da67b40798 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Fri, 5 Oct 2018 16:13:47 +0200 Subject: [PATCH 2/3] refactor cnotice test into function --- src/fe-common/irc/fe-irc-messages.c | 58 +++++++++++++---------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/src/fe-common/irc/fe-irc-messages.c b/src/fe-common/irc/fe-irc-messages.c index 56e479ab..21b98e6c 100644 --- a/src/fe-common/irc/fe-irc-messages.c +++ b/src/fe-common/irc/fe-irc-messages.c @@ -199,29 +199,31 @@ static void sig_message_irc_action(IRC_SERVER_REC *server, const char *msg, g_free_not_null(freemsg); } -static void sig_message_own_notice(IRC_SERVER_REC *server, const char *msg, - const char *target) +static char *notice_channel_context(SERVER_REC *server, const char *msg) { if (*msg == '[') { - /* check if this is a cnotice */ char *end, *channel; end = strpbrk(msg, " ,]"); if (end != NULL && *end == ']') { channel = g_strndup(msg + 1, end - msg - 1); if (server_ischannel(SERVER(server), channel)) { - printformat(server, channel, - MSGLEVEL_NOTICES | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, - IRCTXT_OWN_NOTICE, target, msg); - g_free(channel); - return; + return channel; } g_free(channel); - /* fall through. */ } } - printformat(server, fe_channel_skip_prefix(server, target), MSGLEVEL_NOTICES | - MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, - IRCTXT_OWN_NOTICE, target, msg); + return NULL; +} + +static void sig_message_own_notice(IRC_SERVER_REC *server, const char *msg, const char *target) +{ + char *channel; + /* check if this is a cnotice */ + channel = notice_channel_context((SERVER_REC *) server, msg); + printformat(server, channel != NULL ? channel : fe_channel_skip_prefix(server, target), + MSGLEVEL_NOTICES | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, IRCTXT_OWN_NOTICE, + target, msg); + g_free(channel); } static void sig_message_irc_notice(SERVER_REC *server, const char *msg, @@ -255,28 +257,18 @@ static void sig_message_irc_notice(SERVER_REC *server, const char *msg, printformat(server, target, level, IRCTXT_NOTICE_PUBLIC, nick, oldtarget, msg); } else { - if (*msg == '[') { - /* check if this is a cnotice */ - char *end, *channel; - end = strpbrk(msg, " ,]"); - if (end != NULL && *end == ']') { - channel = g_strndup(msg + 1, end - msg - 1); - if (server_ischannel(SERVER(server), channel)) { - printformat(server, channel, level, IRCTXT_NOTICE_PRIVATE, - nick, address, msg); - g_free(channel); - return; - } - g_free(channel); - /* fall through. */ - } - } + char *channel; + /* check if this is a cnotice */ + channel = notice_channel_context(server, msg); - /* private notice */ - privmsg_get_query(SERVER(server), nick, FALSE, - MSGLEVEL_NOTICES); - printformat(server, nick, level, - IRCTXT_NOTICE_PRIVATE, nick, address, msg); + if (channel == NULL) { + /* private notice */ + privmsg_get_query(SERVER(server), nick, FALSE, MSGLEVEL_NOTICES); + } + printformat(server, channel == NULL ? nick : channel, level, IRCTXT_NOTICE_PRIVATE, + nick, address, msg); + + g_free(channel); } } From cdcb50f413537177ff50478b766b570fb7bae057 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Mon, 8 Oct 2018 17:41:46 +0200 Subject: [PATCH 3/3] add a setting --- src/fe-common/irc/fe-irc-messages.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fe-common/irc/fe-irc-messages.c b/src/fe-common/irc/fe-irc-messages.c index 21b98e6c..27aee5e2 100644 --- a/src/fe-common/irc/fe-irc-messages.c +++ b/src/fe-common/irc/fe-irc-messages.c @@ -201,12 +201,15 @@ static void sig_message_irc_action(IRC_SERVER_REC *server, const char *msg, static char *notice_channel_context(SERVER_REC *server, const char *msg) { + if (!settings_get_bool("notice_channel_context")) + return NULL; + if (*msg == '[') { char *end, *channel; end = strpbrk(msg, " ,]"); if (end != NULL && *end == ']') { channel = g_strndup(msg + 1, end - msg - 1); - if (server_ischannel(SERVER(server), channel)) { + if (server_ischannel(server, channel)) { return channel; } g_free(channel); @@ -294,6 +297,8 @@ static void sig_message_irc_ctcp(IRC_SERVER_REC *server, const char *cmd, void fe_irc_messages_init(void) { + settings_add_bool("misc", "notice_channel_context", TRUE); + signal_add_last("message own_public", (SIGNAL_FUNC) sig_message_own_public); signal_add_last("message irc op_public", (SIGNAL_FUNC) sig_message_irc_op_public); signal_add_last("message irc own_wall", (SIGNAL_FUNC) sig_message_own_wall);