diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index d353abcfb..f3d282c98 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -509,6 +509,7 @@ cmd_ac_init(void) autocomplete_add(notify_ac, "mention"); autocomplete_add(notify_ac, "trigger"); autocomplete_add(notify_ac, "reset"); + autocomplete_add(notify_ac, "idle"); autocomplete_add(notify_chat_ac, "on"); autocomplete_add(notify_chat_ac, "off"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index f864f38de..be4af2397 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1372,7 +1372,8 @@ static const struct cmd_t command_defs[] = { "/notify typing on|off", "/notify typing current on|off", "/notify invite on|off", - "/notify sub on|off") + "/notify sub on|off", + "/notify idle ") CMD_DESC( "Configure desktop notifications. " "To configure presence update messages in the console, chat and chat room windows, see '/help presence'.") @@ -1401,7 +1402,8 @@ static const struct cmd_t command_defs[] = { { "typing on|off", "Notifications when contacts are typing." }, { "typing current on|off", "Whether typing notifications are triggered for the current window." }, { "invite on|off", "Notifications for chat room invites." }, - { "sub on|off", "Notifications for subscription requests." }) + { "sub on|off", "Notifications for subscription requests." }, + { "idle ", "Notification idle period before a notification can be sent."}) CMD_EXAMPLES( "/notify chat on", "/notify chat text on", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 9946f68e2..1e9edfb15 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5741,6 +5741,18 @@ cmd_notify(ProfWin* window, const char* const command, gchar** args) } } } + } else if (g_strcmp0(args[0], "idle") == 0) { + if (!args[1]) { + cons_bad_cmd_usage(command); + } else { + gint idle = atoi(args[1]); + if (idle <= 0) { + cons_show("Invalid idle value (%d)", idle); + } else { + prefs_set_notify_idle(idle); + win_println(window, THEME_DEFAULT, "!", "Message idle period set to %d seconds.", idle); + } + } } else { cons_bad_cmd_usage(command); } diff --git a/src/config/preferences.c b/src/config/preferences.c index 22bf02037..b29fb2389 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1770,6 +1770,23 @@ prefs_free_aliases(GList* aliases) g_list_free_full(aliases, (GDestroyNotify)_free_alias); } +void +prefs_set_notify_idle(gint value) +{ + // The argument is supposed to be in seconds so its multiplied by 1000 to record it as microseconds. + g_key_file_set_integer(prefs, PREF_GROUP_NOTIFICATIONS, "idle", value * 1000); +} + +gint +prefs_get_notify_idle(void) +{ + if (!g_key_file_has_key(prefs, PREF_GROUP_NOTIFICATIONS, "idle", NULL)) { + return 1000; + } else { + return g_key_file_get_integer(prefs, PREF_GROUP_NOTIFICATIONS, "idle", NULL); + } +} + static void _save_prefs(void) { @@ -1884,6 +1901,7 @@ _get_group(preference_t pref) case PREF_TRAY: case PREF_TRAY_READ: case PREF_ADV_NOTIFY_DISCO_OR_VERSION: + case PREF_NOTIFY_IDLE: return PREF_GROUP_NOTIFICATIONS; case PREF_DBLOG: case PREF_CHLOG: @@ -2032,6 +2050,8 @@ _get_key(preference_t pref) return "room.mention.casesensitive"; case PREF_NOTIFY_MENTION_WHOLE_WORD: return "room.mention.wholeword"; + case PREF_NOTIFY_IDLE: + return "idle"; case PREF_CHLOG: return "chlog"; case PREF_DBLOG: diff --git a/src/config/preferences.h b/src/config/preferences.h index e844f814d..763030f9f 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -187,6 +187,7 @@ typedef enum { PREF_STROPHE_SM_RESEND, PREF_VCARD_PHOTO_CMD, PREF_STATUSBAR_TABMODE, + PREF_NOTIFY_IDLE } preference_t; typedef struct prof_alias_t @@ -247,6 +248,8 @@ gint prefs_get_autoaway_time(void); void prefs_set_autoaway_time(gint value); gint prefs_get_autoxa_time(void); void prefs_set_autoxa_time(gint value); +gint prefs_get_notify_idle(void); +void prefs_set_notify_idle(gint value); gchar** prefs_get_plugins(void); void prefs_add_plugin(const char* const name); diff --git a/src/event/server_events.c b/src/event/server_events.c index 4712977bc..228b985a2 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -397,7 +397,7 @@ sv_ev_room_message(ProfMessage* message) } mucwin->last_msg_timestamp = g_date_time_new_now_local(); - if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->from_jid->resourcepart, message->plain, mention, triggers != NULL)) { + if ((prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->from_jid->resourcepart, message->plain, mention, triggers != NULL) && !wins_is_current(window)) || ui_get_idle_time() > prefs_get_notify_idle()) { auto_jid Jid* jidp = jid_create(mucwin->roomjid); if (jidp) { notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index f05bf1c1e..a2726a581 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -393,10 +393,9 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr } } - if (notify) { + if (notify && (!wins_is_current(window) || ui_get_idle_time() > 1000)) notify_message(display_name, num, message->plain); } - plugins_post_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain); message->plain = old_plain;