diff --git a/profrc.example b/profrc.example index a8113825..c8909acb 100644 --- a/profrc.example +++ b/profrc.example @@ -35,6 +35,7 @@ typing=true typing.current=false message.text=true room.text=true +room.offline=true [alias] colour=/color diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 3024ab17..ac4e3726 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -146,6 +146,7 @@ static Autocomplete notify_chat_ac; static Autocomplete notify_room_ac; static Autocomplete notify_typing_ac; static Autocomplete notify_mention_ac; +static Autocomplete notify_offline_ac; static Autocomplete notify_trigger_ac; static Autocomplete prefs_ac; static Autocomplete sub_ac; @@ -344,6 +345,7 @@ cmd_ac_init(void) autocomplete_add(notify_room_ac, "on"); autocomplete_add(notify_room_ac, "off"); autocomplete_add(notify_room_ac, "mention"); + autocomplete_add(notify_room_ac, "offline"); autocomplete_add(notify_room_ac, "current"); autocomplete_add(notify_room_ac, "text"); autocomplete_add(notify_room_ac, "trigger"); @@ -361,6 +363,10 @@ cmd_ac_init(void) autocomplete_add(notify_mention_ac, "word_whole"); autocomplete_add(notify_mention_ac, "word_part"); + notify_offline_ac = autocomplete_new(); + autocomplete_add(notify_offline_ac, "on"); + autocomplete_add(notify_offline_ac, "off"); + notify_trigger_ac = autocomplete_new(); autocomplete_add(notify_trigger_ac, "add"); autocomplete_add(notify_trigger_ac, "remove"); @@ -2338,6 +2344,11 @@ _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous return result; } + result = autocomplete_param_with_ac(input, "/notify room offline", notify_offline_ac, TRUE, previous); + if (result) { + return result; + } + result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE, previous); if (result) { return result; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 281d21c6..e18b3bff 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1436,6 +1436,7 @@ static struct cmd_t command_defs[] = { "/notify room mention on|off", "/notify room mention case_sensitive|case_insensitive", "/notify room mention word_whole|word_part", + "/notify room offline on|off", "/notify room current on|off", "/notify room text on|off", "/notify room trigger add ", @@ -1464,6 +1465,7 @@ static struct cmd_t command_defs[] = { { "room mention case_insensitive", "Set room mention notifications as case insensitive." }, { "room mention word_whole", "Set room mention notifications only on whole word match, i.e. when nickname is not part of a larger word." }, { "room mention word_part", "Set room mention notifications on partial word match, i.e. nickname may be part of a larger word." }, + { "room offline on|off", "Notifications for chat room messages that were sent while you were offline." }, { "room current on|off", "Whether to show all chat room messages notifications when the window is focused." }, { "room text on|off", "Show message text in chat room message notifications." }, { "room trigger add ", "Notify when specified text included in all chat room messages." }, @@ -1483,6 +1485,7 @@ static struct cmd_t command_defs[] = { "/notify chat on", "/notify chat text on", "/notify room mention on", + "/notify room offline on", "/notify room trigger add beer", "/notify room trigger on", "/notify room current off", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 15bf5d7c..fccb937e 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5775,6 +5775,16 @@ cmd_notify(ProfWin* window, const char* const command, gchar** args) } else { cons_show("Usage: /notify room mention on|off"); } + } else if (g_strcmp0(args[1], "offline") == 0) { + if (g_strcmp0(args[2], "on") == 0) { + cons_show("Room notifications for offline messages enabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_OFFLINE, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Room notifications for offline messages disabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_OFFLINE, FALSE); + } else { + cons_show("Usage: /notify room offline on|off"); + } } else if (g_strcmp0(args[1], "current") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Current window chat room message notifications enabled."); diff --git a/src/config/preferences.c b/src/config/preferences.c index 2f7a350e..7b261c2c 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1828,6 +1828,7 @@ _get_group(preference_t pref) case PREF_NOTIFY_CHAT_TEXT: case PREF_NOTIFY_ROOM: case PREF_NOTIFY_ROOM_MENTION: + case PREF_NOTIFY_ROOM_OFFLINE: case PREF_NOTIFY_ROOM_TRIGGER: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_ROOM_TEXT: @@ -1964,6 +1965,8 @@ _get_key(preference_t pref) return "room.trigger"; case PREF_NOTIFY_ROOM_MENTION: return "room.mention"; + case PREF_NOTIFY_ROOM_OFFLINE: + return "room.offline"; case PREF_NOTIFY_ROOM_CURRENT: return "room.current"; case PREF_NOTIFY_ROOM_TEXT: diff --git a/src/config/preferences.h b/src/config/preferences.h index 25fc16ad..761f92bf 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -176,6 +176,7 @@ typedef enum { PREF_URL_SAVE_CMD, PREF_COMPOSE_EDITOR, PREF_SILENCE_NON_ROSTER, + PREF_NOTIFY_ROOM_OFFLINE, } preference_t; typedef struct prof_alias_t diff --git a/src/event/server_events.c b/src/event/server_events.c index 4a35302f..620a8b2d 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -50,6 +50,7 @@ #include "config/cafile.h" #include "config/scripts.h" #include "event/client_events.h" +#include "event/server_events.h" #include "event/common.h" #include "plugins/plugins.h" #include "ui/window_list.h" @@ -272,6 +273,33 @@ sv_ev_room_subject(const char* const room, const char* const nick, const char* c void sv_ev_room_history(ProfMessage* message) { + if (prefs_get_boolean(PREF_NOTIFY_ROOM_OFFLINE)) { + // check if this message was sent while we were offline. + // if so, treat it as a new message rather than a history event. + char* account_name = session_get_account_name(); + char* last_activity = accounts_get_last_activity(account_name); + int msg_is_new = 0; + + if (last_activity) { + GTimeVal lasttv; + + if (g_time_val_from_iso8601(last_activity, &lasttv)) { + GDateTime* lastdt = g_date_time_new_from_timeval_utc(&lasttv); + GDateTime* msgdt = message->timestamp; + GTimeSpan time_diff = g_date_time_difference(msgdt, lastdt); + + msg_is_new = (time_diff > 0); + g_date_time_unref(lastdt); + } + g_free(last_activity); + + if (msg_is_new) { + sv_ev_room_message(message); + return; + } + } + } + ProfMucWin* mucwin = wins_get_muc(message->from_jid->barejid); if (mucwin) { // if this is the first successful connection diff --git a/src/event/server_events.h b/src/event/server_events.h index 55818642..53bb27f0 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -55,7 +55,7 @@ void sv_ev_delayed_private_message(ProfMessage* message); void sv_ev_typing(char* barejid, char* resource); void sv_ev_paused(char* barejid, char* resource); void sv_ev_inactive(char* barejid, char* resource); -void sv_ev_activity(char* barejid, char* resource, gboolean send_states); +void sv_ev_activity(const char* barejid, const char* resource, gboolean send_states); void sv_ev_gone(const char* const barejid, const char* const resource); void sv_ev_subscription(const char* from, jabber_subscr_t type); void sv_ev_message_receipt(const char* const barejid, const char* const id); diff --git a/src/ui/console.c b/src/ui/console.c index 170def7c..08ccba17 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1717,6 +1717,11 @@ cons_notify_setting(void) else cons_show("Room mention (/notify room) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_ROOM_OFFLINE)) + cons_show("Room offline messages (/notify room): ON"); + else + cons_show("Room offline messages (/notify room): OFF"); + if (prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE)) cons_show("Room mention case (/notify room) : Case sensitive"); else