diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-notify.c | 51 | ||||
-rw-r--r-- | src/plugins/irc/irc-notify.h | 5 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 20 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-protocol.cpp | 57 |
5 files changed, 115 insertions, 19 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 533ac7732..9eb09e4fe 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -47,6 +47,7 @@ Bug fixes:: * core: display an error on startup if environment variable "HOME" is not set * core: fix crash when a custom bar item name is already used by a default bar item (issue #2034) * core: fix random timeouts when a lot of concurrent processes are launched with hook_process (issue #2033) + * irc: display messages 730/731 (monitored nicks online/offline) even if command `/notify` was not used (issue #2049) * irc: remove trailing "\r\n" in signals "irc_out" and "irc_outtags" when messages are queued * irc: fix target buffer of IRC message 337 (whois reply: "is hiding their idle time") * irc: revert compute of nick colors to case sensitive way, deprecate again infos "irc_nick_color" and "irc_nick_color_name" (issue #194, issue #2032) diff --git a/src/plugins/irc/irc-notify.c b/src/plugins/irc/irc-notify.c index 86e828c9e..085faa5aa 100644 --- a/src/plugins/irc/irc-notify.c +++ b/src/plugins/irc/irc-notify.c @@ -672,28 +672,26 @@ irc_notify_send_signal (struct t_irc_notify *notify, } /* - * Sets flag "is_on_server" for a notify and display message if user was not on - * server. + * Display message about nick: "is connected", "is offline", "has connected", + * "has quit". + * + * If "notify" is NULL, only "is connected" or "is offline" can be displayed. */ void -irc_notify_set_is_on_server (struct t_irc_notify *notify, const char *host, - int is_on_server) +irc_notify_display_is_on (struct t_irc_server *server, + const char *nick, + const char *host, + struct t_irc_notify *notify, + int is_on_server) { - if (!notify) - return; - - /* same status, then do nothing */ - if (notify->is_on_server == is_on_server) - return; - weechat_printf_date_tags ( - notify->server->buffer, + server->buffer, 0, irc_notify_get_tags (irc_config_look_notify_tags_ison, (is_on_server) ? "join" : "quit", - notify->nick), - (notify->is_on_server < 0) ? + nick), + (!notify || (notify->is_on_server < 0)) ? ((is_on_server) ? _("%snotify: %s%s%s%s%s%s%s%s%s is connected") : _("%snotify: %s%s%s%s%s%s%s%s%s is offline")) : @@ -701,8 +699,8 @@ irc_notify_set_is_on_server (struct t_irc_notify *notify, const char *host, _("%snotify: %s%s%s%s%s%s%s%s%s has connected") : _("%snotify: %s%s%s%s%s%s%s%s%s has quit")), weechat_prefix ("network"), - irc_nick_color_for_msg (notify->server, 1, NULL, notify->nick), - notify->nick, + irc_nick_color_for_msg (server, 1, NULL, nick), + nick, (host && host[0]) ? IRC_COLOR_CHAT_DELIMITERS : "", (host && host[0]) ? " (" : "", (host && host[0]) ? IRC_COLOR_CHAT_HOST : "", @@ -710,6 +708,27 @@ irc_notify_set_is_on_server (struct t_irc_notify *notify, const char *host, (host && host[0]) ? IRC_COLOR_CHAT_DELIMITERS : "", (host && host[0]) ? ")" : "", (is_on_server) ? IRC_COLOR_MESSAGE_JOIN : IRC_COLOR_MESSAGE_QUIT); +} + +/* + * Sets flag "is_on_server" for a notify and display message if user was not on + * server. + */ + +void +irc_notify_set_is_on_server (struct t_irc_notify *notify, const char *host, + int is_on_server) +{ + if (!notify) + return; + + /* same status, then do nothing */ + if (notify->is_on_server == is_on_server) + return; + + irc_notify_display_is_on (notify->server, notify->nick, host, + notify, is_on_server); + irc_notify_send_signal (notify, (is_on_server) ? "join" : "quit", NULL); notify->is_on_server = is_on_server; diff --git a/src/plugins/irc/irc-notify.h b/src/plugins/irc/irc-notify.h index b12a56bf9..29e429ab3 100644 --- a/src/plugins/irc/irc-notify.h +++ b/src/plugins/irc/irc-notify.h @@ -55,6 +55,11 @@ extern void irc_notify_new_for_server (struct t_irc_server *server); extern void irc_notify_new_for_all_servers (); extern void irc_notify_free (struct t_irc_server *server, struct t_irc_notify *notify, int remove_monitor); +extern void irc_notify_display_is_on (struct t_irc_server *server, + const char *nick, + const char *host, + struct t_irc_notify *notify, + int is_on_server); extern void irc_notify_set_is_on_server (struct t_irc_notify *notify, const char *host, int is_on_server); extern void irc_notify_free_all (struct t_irc_server *server); diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index dc343d25a..7e3381544 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -7640,7 +7640,17 @@ IRC_PROTOCOL_CALLBACK(730) monitor_host++; ptr_notify = irc_notify_search (ctxt->server, monitor_nick); if (ptr_notify) + { irc_notify_set_is_on_server (ptr_notify, monitor_host, 1); + } + else + { + irc_notify_display_is_on (ctxt->server, + monitor_nick, + monitor_host, + NULL, /* notify */ + 1); + } } weechat_string_free_split (nicks); } @@ -7688,7 +7698,17 @@ IRC_PROTOCOL_CALLBACK(731) monitor_host++; ptr_notify = irc_notify_search (ctxt->server, monitor_nick); if (ptr_notify) + { irc_notify_set_is_on_server (ptr_notify, monitor_host, 0); + } + else + { + irc_notify_display_is_on (ctxt->server, + monitor_nick, + monitor_host, + NULL, /* notify */ + 0); + } } weechat_string_free_split (nicks); } diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index f394c0dab..7f3d3087f 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -6017,29 +6017,80 @@ TEST(IrcProtocolWithServer, 730) RECV(":server 731 alice"); CHECK_ERROR_PARAMS("731", 1, 2); + /* without notify */ RECV(":server 730 alice :nick1!user1@host1,nick2!user2@host2"); - CHECK_NO_MSG; + CHECK_SRV("--", "notify: nick1 (user1@host1) is connected", + "irc_notify,irc_notify_join,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is connected", + "irc_notify,irc_notify_join,nick_nick2,notify_message,log3"); + RECV(":server 730 alice :nick1!user1@host1,nick2!user2@host2"); + CHECK_SRV("--", "notify: nick1 (user1@host1) is connected", + "irc_notify,irc_notify_join,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is connected", + "irc_notify,irc_notify_join,nick_nick2,notify_message,log3"); RECV(":server 731 alice :nick1!user1@host1,nick2!user2@host2"); - CHECK_NO_MSG; + CHECK_SRV("--", "notify: nick1 (user1@host1) is offline", + "irc_notify,irc_notify_quit,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is offline", + "irc_notify,irc_notify_quit,nick_nick2,notify_message,log3"); + RECV(":server 731 alice :nick1!user1@host1,nick2!user2@host2"); + CHECK_SRV("--", "notify: nick1 (user1@host1) is offline", + "irc_notify,irc_notify_quit,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is offline", + "irc_notify,irc_notify_quit,nick_nick2,notify_message,log3"); /* with notify on nick1 */ run_cmd_quiet ("/notify add nick1 " IRC_FAKE_SERVER); + RECV(":server 730 alice :nick1!user1@host1,nick2!user2@host2"); CHECK_SRV("--", "notify: nick1 (user1@host1) is connected", "irc_notify,irc_notify_join,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is connected", + "irc_notify,irc_notify_join,nick_nick2,notify_message,log3"); + RECV(":server 730 alice :nick1!user1@host1,nick2!user2@host2"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is connected", + "irc_notify,irc_notify_join,nick_nick2,notify_message,log3"); + RECV(":server 731 alice :nick1!user1@host1,nick2!user2@host2"); CHECK_SRV("--", "notify: nick1 (user1@host1) has quit", "irc_notify,irc_notify_quit,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is offline", + "irc_notify,irc_notify_quit,nick_nick2,notify_message,log3"); + RECV(":server 731 alice :nick1!user1@host1,nick2!user2@host2"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is offline", + "irc_notify,irc_notify_quit,nick_nick2,notify_message,log3"); + + RECV(":server 730 alice :nick1!user1@host1,nick2!user2@host2"); + CHECK_SRV("--", "notify: nick1 (user1@host1) has connected", + "irc_notify,irc_notify_join,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) is connected", + "irc_notify,irc_notify_join,nick_nick2,notify_message,log3"); + + run_cmd_quiet ("/mute /notify del nick1 " IRC_FAKE_SERVER); /* with notify on nick1 and nick2 */ + run_cmd_quiet ("/notify add nick1 " IRC_FAKE_SERVER); run_cmd_quiet ("/notify add nick2 " IRC_FAKE_SERVER); + RECV(":server 730 alice :nick1!user1@host1,nick2!user2@host2"); - CHECK_SRV("--", "notify: nick1 (user1@host1) has connected", + CHECK_SRV("--", "notify: nick1 (user1@host1) is connected", "irc_notify,irc_notify_join,nick_nick1,notify_message,log3"); CHECK_SRV("--", "notify: nick2 (user2@host2) is connected", "irc_notify,irc_notify_join,nick_nick2,notify_message,log3"); + RECV(":server 731 alice :nick1!user1@host1,nick2!user2@host2"); + CHECK_SRV("--", "notify: nick1 (user1@host1) has quit", + "irc_notify,irc_notify_quit,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) has quit", + "irc_notify,irc_notify_quit,nick_nick2,notify_message,log3"); + + RECV(":server 730 alice :nick1!user1@host1,nick2!user2@host2"); + CHECK_SRV("--", "notify: nick1 (user1@host1) has connected", + "irc_notify,irc_notify_join,nick_nick1,notify_message,log3"); + CHECK_SRV("--", "notify: nick2 (user2@host2) has connected", + "irc_notify,irc_notify_join,nick_nick2,notify_message,log3"); + run_cmd_quiet ("/mute /notify del nick1 " IRC_FAKE_SERVER); run_cmd_quiet ("/mute /notify del nick2 " IRC_FAKE_SERVER); } |