diff --git a/src/fe-common/core/fe-messages.c b/src/fe-common/core/fe-messages.c index 308680d6..9545af73 100644 --- a/src/fe-common/core/fe-messages.c +++ b/src/fe-common/core/fe-messages.c @@ -587,6 +587,25 @@ static void sig_message_topic(SERVER_REC *server, const char *channel, nick, channel, topic, address); } +static void sig_message_away_notify(SERVER_REC *server, const char *nick, + const char *addr, const char *awaymsg) +{ + int txt = *awaymsg == '\0' ? TXT_NOTIFY_UNAWAY_CHANNEL : + TXT_NOTIFY_AWAY_CHANNEL; + + if (!settings_get_bool("away_notify_public")) + return; + + spread_server_message_to_windows(server, FALSE, + FALSE, + MSGLEVEL_CRAP, + txt, txt, + nick, addr, + awaymsg, + awaymsg + ); +} + static int printnick_exists(NICK_REC *first, NICK_REC *ignore, const char *nick) { @@ -730,6 +749,7 @@ void fe_messages_init(void) settings_add_bool("lookandfeel", "print_active_channel", FALSE); settings_add_bool("lookandfeel", "show_quit_once", FALSE); settings_add_bool("lookandfeel", "show_own_nickchange_once", FALSE); + settings_add_bool("lookandfeel", "away_notify_public", FALSE); signal_add_last("message public", (SIGNAL_FUNC) sig_message_public); signal_add_last("message private", (SIGNAL_FUNC) sig_message_private); @@ -744,6 +764,7 @@ void fe_messages_init(void) signal_add_last("message invite", (SIGNAL_FUNC) sig_message_invite); signal_add_last("message invite_other", (SIGNAL_FUNC) sig_message_invite_other); signal_add_last("message topic", (SIGNAL_FUNC) sig_message_topic); + signal_add_last("message away_notify", (SIGNAL_FUNC) sig_message_away_notify); signal_add("nicklist new", (SIGNAL_FUNC) sig_nicklist_new); signal_add("nicklist remove", (SIGNAL_FUNC) sig_nicklist_remove); @@ -770,6 +791,7 @@ void fe_messages_deinit(void) signal_remove("message invite_other", (SIGNAL_FUNC) sig_message_invite_other); signal_remove("message invite", (SIGNAL_FUNC) sig_message_invite); signal_remove("message topic", (SIGNAL_FUNC) sig_message_topic); + signal_remove("message away_notify", (SIGNAL_FUNC) sig_message_away_notify); signal_remove("nicklist new", (SIGNAL_FUNC) sig_nicklist_new); signal_remove("nicklist remove", (SIGNAL_FUNC) sig_nicklist_remove); diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 2532d82f..83eae589 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -106,6 +106,8 @@ FORMAT_REC fecommon_core_formats[] = { { "topic_unset", "Topic unset by {nick $0} on {channel $1}", 4, { 0, 0, 0, 0 } }, { "your_nick_changed", "You're now known as {nick $1}", 4, { 0, 0, 0, 0 } }, { "nick_changed", "{channick $0} is now known as {channick_hilight $1}", 4, { 0, 0, 0, 0 } }, + { "notify_away_channel", "{channick $0} {chanhost $1} is now away: {reason $2}", 4, { 0, 0, 0, 0 } }, + { "notify_unaway_channel", "{channick_hilight $0} {chanhost $1} is no longer away", 4, { 0, 0, 0, 0 } }, { "talking_in", "You are now talking in {channel $0}", 1, { 0 } }, { "not_in_channels", "You are not on any channels", 0 }, { "current_channel", "Current channel {channel $0}", 1, { 0 } }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index c5e2c4d1..74a4dfd9 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -82,6 +82,8 @@ enum { TXT_TOPIC_UNSET, TXT_YOUR_NICK_CHANGED, TXT_NICK_CHANGED, + TXT_NOTIFY_AWAY_CHANNEL, + TXT_NOTIFY_UNAWAY_CHANNEL, TXT_TALKING_IN, TXT_NOT_IN_CHANNELS, TXT_CURRENT_CHANNEL, diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index c26f2e88..4608b949 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -237,6 +237,21 @@ static void event_mode(IRC_SERVER_REC *server, const char *data, g_free(params); } +static void event_away_notify(IRC_SERVER_REC *server, const char *data, + const char *nick, const char *addr) +{ + char *params, *awaymsg; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 1 | PARAM_FLAG_GETREST, + &awaymsg); + + signal_emit("message away_notify", 4, + server, nick, addr, awaymsg); + g_free(params); +} + static void event_pong(IRC_SERVER_REC *server, const char *data, const char *nick) { char *params, *host, *reply; @@ -458,6 +473,7 @@ void fe_events_init(void) signal_add("event error", (SIGNAL_FUNC) event_error); signal_add("event wallops", (SIGNAL_FUNC) event_wallops); signal_add("event silence", (SIGNAL_FUNC) event_silence); + signal_add("event away", (SIGNAL_FUNC) event_away_notify); signal_add("default event", (SIGNAL_FUNC) event_received); @@ -487,6 +503,7 @@ void fe_events_deinit(void) signal_remove("event error", (SIGNAL_FUNC) event_error); signal_remove("event wallops", (SIGNAL_FUNC) event_wallops); signal_remove("event silence", (SIGNAL_FUNC) event_silence); + signal_remove("event away", (SIGNAL_FUNC) event_away_notify); signal_remove("default event", (SIGNAL_FUNC) event_received); diff --git a/src/irc/core/irc-nicklist.c b/src/irc/core/irc-nicklist.c index 9073ddaa..28ac6368 100644 --- a/src/irc/core/irc-nicklist.c +++ b/src/irc/core/irc-nicklist.c @@ -467,6 +467,20 @@ static void event_setname(SERVER_REC *server, const char *data, const char *nick g_slist_free(nicks); } +static void event_away_notify(IRC_SERVER_REC *server, const char *data, const char *nick, const char *add) +{ + char *params, *awaymsg; + + if (!IS_IRC_SERVER(server)) + return; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 1 | PARAM_FLAG_GETREST, &awaymsg); + nicklist_update_flags(SERVER(server), nick, *awaymsg != '\0', -1); + g_free(params); +} + static void sig_usermode(SERVER_REC *server) { g_return_if_fail(IS_SERVER(server)); @@ -507,6 +521,7 @@ void irc_nicklist_init(void) signal_add_first("event 433", (SIGNAL_FUNC) event_nick_in_use); signal_add_first("event 437", (SIGNAL_FUNC) event_target_unavailable); signal_add_first("event 302", (SIGNAL_FUNC) event_userhost); + signal_add_first("event away", (SIGNAL_FUNC) event_away_notify); signal_add("userhost event", (SIGNAL_FUNC) event_userhost); signal_add("event setname", (SIGNAL_FUNC) event_setname); signal_add("user mode changed", (SIGNAL_FUNC) sig_usermode); @@ -530,6 +545,7 @@ void irc_nicklist_deinit(void) signal_remove("event 433", (SIGNAL_FUNC) event_nick_in_use); signal_remove("event 437", (SIGNAL_FUNC) event_target_unavailable); signal_remove("event 302", (SIGNAL_FUNC) event_userhost); + signal_remove("event away", (SIGNAL_FUNC) event_away_notify); signal_remove("userhost event", (SIGNAL_FUNC) event_userhost); signal_remove("event setname", (SIGNAL_FUNC) event_setname); signal_remove("user mode changed", (SIGNAL_FUNC) sig_usermode); diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 5e98e724..16095ed3 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -237,6 +237,7 @@ static void server_init(IRC_SERVER_REC *server) irc_cap_toggle(server, CAP_EXTENDED_JOIN, TRUE); irc_cap_toggle(server, CAP_SETNAME, TRUE); irc_cap_toggle(server, CAP_INVITE_NOTIFY, TRUE); + irc_cap_toggle(server, CAP_AWAY_NOTIFY, TRUE); irc_send_cmd_now(server, "CAP LS " CAP_LS_VERSION); diff --git a/src/irc/core/irc-servers.h b/src/irc/core/irc-servers.h index 5313c1d0..3fccfe9e 100644 --- a/src/irc/core/irc-servers.h +++ b/src/irc/core/irc-servers.h @@ -20,6 +20,7 @@ #define CAP_EXTENDED_JOIN "extended-join" #define CAP_SETNAME "draft/setname" #define CAP_INVITE_NOTIFY "invite-notify" +#define CAP_AWAY_NOTIFY "away-notify" /* returns IRC_SERVER_REC if it's IRC server, NULL if it isn't */ #define IRC_SERVER(server) \