From 4d24aa19cbd40884a2ce353fe588f4ec4de5042d Mon Sep 17 00:00:00 2001 From: Deurachavich Date: Wed, 5 Mar 2025 12:37:48 +0200 Subject: [PATCH 1/4] Notifications no longer show when the received message is from the selected chat window. --- src/event/server_events.c | 13 +++++++------ src/ui/chatwin.c | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index aa93d9f7e..5f7d61240 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -389,6 +389,13 @@ sv_ev_room_message(ProfMessage* message) if (triggers) { mucwin->unread_triggers = TRUE; } + + if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->from_jid->resourcepart, message->plain, mention, triggers != NULL)) { + auto_jid Jid* jidp = jid_create(mucwin->roomjid); + if (jidp) { + notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain); + } + } } // save timestamp of last received muc message @@ -397,12 +404,6 @@ 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)) { - auto_jid Jid* jidp = jid_create(mucwin->roomjid); - if (jidp) { - notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain); - } - } if (triggers) { g_list_free_full(triggers, free); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index edb8f96aa..c18369c89 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -382,6 +382,10 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr if (show_message) { win_print_incoming(window, display_name, message); } + + if (notify) { + notify_message(display_name, num, message->plain); + } } if (!message->is_mam) { @@ -393,10 +397,6 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr } } - if (notify) { - 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; From 6f1f43ea9ae61847833eb1cf4420381c08b9b40c Mon Sep 17 00:00:00 2001 From: Deurachavich Date: Thu, 6 Mar 2025 13:39:54 +0200 Subject: [PATCH 2/4] Allow notifications of selected window whenever the client is inactive --- src/event/server_events.c | 13 ++++++------- src/ui/chatwin.c | 7 +++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 5f7d61240..4e5347867 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -389,13 +389,6 @@ sv_ev_room_message(ProfMessage* message) if (triggers) { mucwin->unread_triggers = TRUE; } - - if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->from_jid->resourcepart, message->plain, mention, triggers != NULL)) { - auto_jid Jid* jidp = jid_create(mucwin->roomjid); - if (jidp) { - notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain); - } - } } // save timestamp of last received muc message @@ -404,6 +397,12 @@ 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) && !wins_is_current(window)) || ui_get_idle_time() > 1000) { + auto_jid Jid* jidp = jid_create(mucwin->roomjid); + if (jidp) { + notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain); + } + } if (triggers) { g_list_free_full(triggers, free); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index c18369c89..3c70985a4 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -382,10 +382,6 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr if (show_message) { win_print_incoming(window, display_name, message); } - - if (notify) { - notify_message(display_name, num, message->plain); - } } if (!message->is_mam) { @@ -397,6 +393,9 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr } } + 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; From b3e4916ecd3c5441a74412bd4149673782dd26aa Mon Sep 17 00:00:00 2001 From: Bionic Git man Date: Mon, 25 Aug 2025 08:46:45 +0300 Subject: [PATCH 3/4] Update src/ui/chatwin.c Co-authored-by: Kerim Kabirov --- src/ui/chatwin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index e206d20b8..e2a14e10b 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -393,7 +393,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr } } - if ((notify && !wins_is_current(window)) || ui_get_idle_time() > 1000) { + 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); From cc7d22814c28c2898bcf81b7d0245a73ff841d38 Mon Sep 17 00:00:00 2001 From: Deurachavich Date: Wed, 27 Aug 2025 11:13:59 +0300 Subject: [PATCH 4/4] Add idle as an configuration setting --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 6 ++++-- src/command/cmd_funcs.c | 12 ++++++++++++ src/config/preferences.c | 20 ++++++++++++++++++++ src/config/preferences.h | 3 +++ src/event/server_events.c | 2 +- 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 036782b9c..641f1032a 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 e33dcdb16..779db11e6 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1368,7 +1368,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'.") @@ -1397,7 +1398,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 7ebfa7d8c..2f601f429 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5795,6 +5795,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 d306066b9..a8282a3fb 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1700,6 +1700,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) { @@ -1814,6 +1831,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: @@ -1962,6 +1980,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 e59041495..cbed703e9 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 @@ -246,6 +247,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 38ab2b5cc..0b964ffd7 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) && !wins_is_current(window)) || ui_get_idle_time() > 1000) { + 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);