Skip to content
1 change: 1 addition & 0 deletions src/command/cmd_ac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 4 additions & 2 deletions src/command/cmd_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <seconds>")
CMD_DESC(
"Configure desktop notifications. "
"To configure presence update messages in the console, chat and chat room windows, see '/help presence'.")
Expand Down Expand Up @@ -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 <seconds>", "Notification idle period before a notification can be sent."})
CMD_EXAMPLES(
"/notify chat on",
"/notify chat text on",
Expand Down
12 changes: 12 additions & 0 deletions src/command/cmd_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions src/config/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/config/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/event/server_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/ui/chatwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down