diff --git a/src/command/command.c b/src/command/command.c index 3e9adc9c..6ca09b82 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1054,18 +1054,27 @@ static struct cmd_t command_defs[] = }, { "/notify", - cmd_notify, parse_args, 2, 3, &cons_notify_setting, + cmd_notify, parse_args_with_freetext, 0, 4, NULL, CMD_TAGS( CMD_TAG_UI, CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) CMD_SYN( - "/notify message on|off", - "/notify message current on|off", - "/notify message text on|off", - "/notify room on|off|mention", + "/notify chat on|off", + "/notify chat current on|off", + "/notify chat text on|off", + "/notify room on|off", + "/notify room mention on|off", "/notify room current on|off", "/notify room text on|off", + "/notify room trigger add ", + "/notify room trigger remove ", + "/notify room trigger list", + "/notify room trigger on|off", + "/notify on|off", + "/notify mention on|off", + "/notify trigger on|off", + "/notify reset", "/notify remind ", "/notify typing on|off", "/notify typing current on|off", @@ -1074,24 +1083,34 @@ static struct cmd_t command_defs[] = CMD_DESC( "Settings for various kinds of desktop notifications.") CMD_ARGS( - { "message on|off", "Notifications for regular chat messages." }, - { "message current on|off", "Whether messages in the current window trigger notifications." }, - { "message text on|off", "Show message text in regular message notifications." }, - { "room on|off|mention", "Notifications for chat room messages, mention triggers notifications only when your nick is mentioned." }, - { "room current on|off", "Whether chat room messages in the current window trigger notifications." }, - { "room text on|off", "Show message text in chat room message notifications." }, - { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, - { "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." }) + { "chat on|off", "Notifications for regular chat messages." }, + { "chat current on|off", "Whether to show regular chat message notifications when the window is focussed." }, + { "chat text on|off", "Show message text in regular message notifications." }, + { "room on|off", "Notifications for all chat room messages, 'mention' only notifies when your nick is mentioned." }, + { "room mention on|off", "Notifications for all chat room messages when your nick is mentioned." }, + { "room current on|off", "Whether to show all chat room messages notifications when the window is focussed." }, + { "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." }, + { "room trigger remove ", "Remove chat room notification trigger." }, + { "room trigger list", "List all chat room triggers." }, + { "room trigger on|off", "Enable or disable all chat room notification triggers." }, + { "on|off", "Override the global message setting for the current chat room." }, + { "mention on|off", "Override the global 'mention' setting for the current chat room." }, + { "trigger on|off", "Override the global 'trigger' setting for the current chat room." }, + { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, + { "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." }) CMD_EXAMPLES( - "/notify message on", - "/notify message text on", - "/notify room mention", + "/notify chat on", + "/notify chat text on", + "/notify room mention on", + "/notify room trigger add beer", + "/notify room trigger on", "/notify room current off", "/notify room text off", - "/notify remind 10", + "/notify remind 60", "/notify typing on", "/notify invite on") }, @@ -1788,9 +1807,10 @@ static Autocomplete who_roster_ac; static Autocomplete help_ac; static Autocomplete help_commands_ac; static Autocomplete notify_ac; +static Autocomplete notify_chat_ac; static Autocomplete notify_room_ac; -static Autocomplete notify_message_ac; static Autocomplete notify_typing_ac; +static Autocomplete notify_trigger_ac; static Autocomplete prefs_ac; static Autocomplete sub_ac; static Autocomplete log_ac; @@ -1917,18 +1937,23 @@ cmd_init(void) autocomplete_add(prefs_ac, "pgp"); notify_ac = autocomplete_new(); - autocomplete_add(notify_ac, "message"); + autocomplete_add(notify_ac, "chat"); autocomplete_add(notify_ac, "room"); autocomplete_add(notify_ac, "typing"); autocomplete_add(notify_ac, "remind"); autocomplete_add(notify_ac, "invite"); autocomplete_add(notify_ac, "sub"); + autocomplete_add(notify_ac, "on"); + autocomplete_add(notify_ac, "off"); + autocomplete_add(notify_ac, "mention"); + autocomplete_add(notify_ac, "trigger"); + autocomplete_add(notify_ac, "reset"); - notify_message_ac = autocomplete_new(); - autocomplete_add(notify_message_ac, "on"); - autocomplete_add(notify_message_ac, "off"); - autocomplete_add(notify_message_ac, "current"); - autocomplete_add(notify_message_ac, "text"); + notify_chat_ac = autocomplete_new(); + autocomplete_add(notify_chat_ac, "on"); + autocomplete_add(notify_chat_ac, "off"); + autocomplete_add(notify_chat_ac, "current"); + autocomplete_add(notify_chat_ac, "text"); notify_room_ac = autocomplete_new(); autocomplete_add(notify_room_ac, "on"); @@ -1936,12 +1961,20 @@ cmd_init(void) autocomplete_add(notify_room_ac, "mention"); autocomplete_add(notify_room_ac, "current"); autocomplete_add(notify_room_ac, "text"); + autocomplete_add(notify_room_ac, "trigger"); notify_typing_ac = autocomplete_new(); autocomplete_add(notify_typing_ac, "on"); autocomplete_add(notify_typing_ac, "off"); autocomplete_add(notify_typing_ac, "current"); + notify_trigger_ac = autocomplete_new(); + autocomplete_add(notify_trigger_ac, "add"); + autocomplete_add(notify_trigger_ac, "remove"); + autocomplete_add(notify_trigger_ac, "list"); + autocomplete_add(notify_trigger_ac, "on"); + autocomplete_add(notify_trigger_ac, "off"); + sub_ac = autocomplete_new(); autocomplete_add(sub_ac, "request"); autocomplete_add(sub_ac, "allow"); @@ -2335,9 +2368,10 @@ cmd_uninit(void) autocomplete_free(help_ac); autocomplete_free(help_commands_ac); autocomplete_free(notify_ac); - autocomplete_free(notify_message_ac); + autocomplete_free(notify_chat_ac); autocomplete_free(notify_room_ac); autocomplete_free(notify_typing_ac); + autocomplete_free(notify_trigger_ac); autocomplete_free(sub_ac); autocomplete_free(titlebar_ac); autocomplete_free(log_ac); @@ -2521,9 +2555,10 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(help_ac); autocomplete_reset(help_commands_ac); autocomplete_reset(notify_ac); - autocomplete_reset(notify_message_ac); + autocomplete_reset(notify_chat_ac); autocomplete_reset(notify_room_ac); autocomplete_reset(notify_typing_ac); + autocomplete_reset(notify_trigger_ac); autocomplete_reset(sub_ac); autocomplete_reset(who_room_ac); @@ -2622,6 +2657,7 @@ cmd_reset_autocomplete(ProfWin *window) } bookmark_autocomplete_reset(); + prefs_reset_room_trigger_ac(); } gboolean @@ -3136,27 +3172,21 @@ _notify_autocomplete(ProfWin *window, const char *const input) int i = 0; char *result = NULL; - result = autocomplete_param_with_func(input, "/notify room current", prefs_autocomplete_boolean_choice); + result = autocomplete_param_with_func(input, "/notify room trigger remove", prefs_autocomplete_room_trigger); if (result) { return result; } - result = autocomplete_param_with_func(input, "/notify message current", prefs_autocomplete_boolean_choice); - if (result) { - return result; + gchar *boolean_choices1[] = { "/notify room current", "/notify chat current", "/notify typing current", + "/notify room text", "/notify room mention", "/notify chat text" }; + for (i = 0; i < ARRAY_SIZE(boolean_choices1); i++) { + result = autocomplete_param_with_func(input, boolean_choices1[i], prefs_autocomplete_boolean_choice); + if (result) { + return result; + } } - result = autocomplete_param_with_func(input, "/notify typing current", prefs_autocomplete_boolean_choice); - if (result) { - return result; - } - - result = autocomplete_param_with_func(input, "/notify room text", prefs_autocomplete_boolean_choice); - if (result) { - return result; - } - - result = autocomplete_param_with_func(input, "/notify message text", prefs_autocomplete_boolean_choice); + result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE); if (result) { return result; } @@ -3166,7 +3196,7 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - result = autocomplete_param_with_ac(input, "/notify message", notify_message_ac, TRUE); + result = autocomplete_param_with_ac(input, "/notify chat", notify_chat_ac, TRUE); if (result) { return result; } @@ -3176,10 +3206,9 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - gchar *boolean_choices[] = { "/notify invite", "/notify sub" }; - for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { - result = autocomplete_param_with_func(input, boolean_choices[i], - prefs_autocomplete_boolean_choice); + gchar *boolean_choices2[] = { "/notify invite", "/notify sub", "/notify mention", "/notify trigger"}; + for (i = 0; i < ARRAY_SIZE(boolean_choices2); i++) { + result = autocomplete_param_with_func(input, boolean_choices2[i], prefs_autocomplete_boolean_choice); if (result) { return result; } diff --git a/src/command/commands.c b/src/command/commands.c index 5781ae5c..042fbb1c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4266,58 +4266,111 @@ cmd_gone(ProfWin *window, const char *const command, gchar **args) gboolean cmd_notify(ProfWin *window, const char *const command, gchar **args) { - char *kind = args[0]; + if (!args[0]) { + ProfWin *current = wins_get_current(); + if (current->type == WIN_MUC) { + win_println(current, 0, ""); + ProfMucWin *mucwin = (ProfMucWin *)current; - // bad kind - if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) && - (strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0) && - (strcmp(kind, "sub") != 0) && (strcmp(kind, "room") != 0)) { - cons_bad_cmd_usage(command); - - // set message setting - } else if (strcmp(kind, "message") == 0) { - if (strcmp(args[1], "on") == 0) { - cons_show("Message notifications enabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE, TRUE); - } else if (strcmp(args[1], "off") == 0) { - cons_show("Message notifications disabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE, FALSE); - } else if (strcmp(args[1], "current") == 0) { - if (g_strcmp0(args[2], "on") == 0) { - cons_show("Current window message notifications enabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, TRUE); - } else if (g_strcmp0(args[2], "off") == 0) { - cons_show("Current window message notifications disabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, FALSE); + win_vprintln_ch(window, '!', "Notification settings for %s:", mucwin->roomjid); + if (prefs_has_room_notify(mucwin->roomjid)) { + if (prefs_get_room_notify(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Message : ON"); + } else { + win_vprintln_ch(window, '!', " Message : OFF"); + } } else { - cons_show("Usage: /notify message current on|off"); + if (prefs_get_boolean(PREF_NOTIFY_ROOM)) { + win_vprintln_ch(window, '!', " Message : ON (global setting)"); + } else { + win_vprintln_ch(window, '!', " Message : OFF (global setting)"); + } } - } else if (strcmp(args[1], "text") == 0) { - if (g_strcmp0(args[2], "on") == 0) { - cons_show("Showing text in message notifications enabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_TEXT, TRUE); - } else if (g_strcmp0(args[2], "off") == 0) { - cons_show("Showing text in message notifications disabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_TEXT, FALSE); + if (prefs_has_room_notify_mention(mucwin->roomjid)) { + if (prefs_get_room_notify_mention(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Mention : ON"); + } else { + win_vprintln_ch(window, '!', " Mention : OFF"); + } } else { - cons_show("Usage: /notify message text on|off"); + if (prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION)) { + win_vprintln_ch(window, '!', " Mention : ON (global setting)"); + } else { + win_vprintln_ch(window, '!', " Mention : OFF (global setting)"); + } } + if (prefs_has_room_notify_trigger(mucwin->roomjid)) { + if (prefs_get_room_notify_trigger(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Triggers : ON"); + } else { + win_vprintln_ch(window, '!', " Triggers : OFF"); + } + } else { + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) { + win_vprintln_ch(window, '!', " Triggers : ON (global setting)"); + } else { + win_vprintln_ch(window, '!', " Triggers : OFF (global setting)"); + } + } + win_println(current, 0, ""); } else { - cons_show("Usage: /notify message on|off"); + cons_show(""); + cons_notify_setting(); + cons_bad_cmd_usage(command); + + } + return TRUE; + } + + // chat settings + if (g_strcmp0(args[0], "chat") == 0) { + if (g_strcmp0(args[1], "on") == 0) { + cons_show("Chat notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT, TRUE); + } else if (g_strcmp0(args[1], "off") == 0) { + cons_show("Chat notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT, FALSE); + } else if (g_strcmp0(args[1], "current") == 0) { + if (g_strcmp0(args[2], "on") == 0) { + cons_show("Current window chat notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_CURRENT, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Current window chat notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_CURRENT, FALSE); + } else { + cons_show("Usage: /notify chat current on|off"); + } + } else if (g_strcmp0(args[1], "text") == 0) { + if (g_strcmp0(args[2], "on") == 0) { + cons_show("Showing text in chat notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_TEXT, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Showing text in chat notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_TEXT, FALSE); + } else { + cons_show("Usage: /notify chat text on|off"); + } } - // set room setting - } else if (strcmp(kind, "room") == 0) { - if (strcmp(args[1], "on") == 0) { - cons_show("Chat room notifications enabled."); - prefs_set_string(PREF_NOTIFY_ROOM, "on"); - } else if (strcmp(args[1], "off") == 0) { - cons_show("Chat room notifications disabled."); - prefs_set_string(PREF_NOTIFY_ROOM, "off"); - } else if (strcmp(args[1], "mention") == 0) { - cons_show("Chat room notifications enabled on mention."); - prefs_set_string(PREF_NOTIFY_ROOM, "mention"); - } else if (strcmp(args[1], "current") == 0) { + // chat room settings + } else if (g_strcmp0(args[0], "room") == 0) { + if (g_strcmp0(args[1], "on") == 0) { + cons_show("Room notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM, TRUE); + } else if (g_strcmp0(args[1], "off") == 0) { + cons_show("Room notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM, FALSE); + } else if (g_strcmp0(args[1], "mention") == 0) { + if (g_strcmp0(args[2], "on") == 0) { + cons_show("Room notifications with mention enabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Room notifications with mention disabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, FALSE); + } else { + cons_show("Usage: /notify room mention 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."); prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, TRUE); @@ -4327,7 +4380,7 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Usage: /notify room current on|off"); } - } else if (strcmp(args[1], "text") == 0) { + } else if (g_strcmp0(args[1], "text") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Showing text in chat room message notifications enabled."); prefs_set_boolean(PREF_NOTIFY_ROOM_TEXT, TRUE); @@ -4337,19 +4390,64 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Usage: /notify room text on|off"); } + } else if (g_strcmp0(args[1], "trigger") == 0) { + if (g_strcmp0(args[2], "add") == 0) { + if (!args[3]) { + cons_bad_cmd_usage(command); + } else { + gboolean res = prefs_add_room_notify_trigger(args[3]); + if (res) { + cons_show("Adding room notification trigger: %s", args[3]); + } else { + cons_show("Room notification trigger already exists: %s", args[3]); + } + } + } else if (g_strcmp0(args[2], "remove") == 0) { + if (!args[3]) { + cons_bad_cmd_usage(command); + } else { + gboolean res = prefs_remove_room_notify_trigger(args[3]); + if (res) { + cons_show("Removing room notification trigger: %s", args[3]); + } else { + cons_show("Room notification trigger does not exist: %s", args[3]); + } + } + } else if (g_strcmp0(args[2], "list") == 0) { + GList *triggers = prefs_get_room_notify_triggers(); + GList *curr = triggers; + if (curr) { + cons_show("Room notification triggers:"); + } else { + cons_show("No room notification triggers"); + } + while (curr) { + cons_show(" %s", curr->data); + curr = g_list_next(curr); + } + g_list_free_full(triggers, free); + } else if (g_strcmp0(args[2], "on") == 0) { + cons_show("Enabling room notification triggers"); + prefs_set_boolean(PREF_NOTIFY_ROOM_TRIGGER, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Disabling room notification triggers"); + prefs_set_boolean(PREF_NOTIFY_ROOM_TRIGGER, FALSE); + } else { + cons_bad_cmd_usage(command); + } } else { cons_show("Usage: /notify room on|off|mention"); } - // set typing setting - } else if (strcmp(kind, "typing") == 0) { - if (strcmp(args[1], "on") == 0) { + // typing settings + } else if (g_strcmp0(args[0], "typing") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Typing notifications enabled."); prefs_set_boolean(PREF_NOTIFY_TYPING, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Typing notifications disabled."); prefs_set_boolean(PREF_NOTIFY_TYPING, FALSE); - } else if (strcmp(args[1], "current") == 0) { + } else if (g_strcmp0(args[1], "current") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Current window typing notifications enabled."); prefs_set_boolean(PREF_NOTIFY_TYPING_CURRENT, TRUE); @@ -4363,44 +4461,154 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) cons_show("Usage: /notify typing on|off"); } - // set invite setting - } else if (strcmp(kind, "invite") == 0) { - if (strcmp(args[1], "on") == 0) { + // invite settings + } else if (g_strcmp0(args[0], "invite") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Chat room invite notifications enabled."); prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Chat room invite notifications disabled."); prefs_set_boolean(PREF_NOTIFY_INVITE, FALSE); } else { cons_show("Usage: /notify invite on|off"); } - // set subscription setting - } else if (strcmp(kind, "sub") == 0) { - if (strcmp(args[1], "on") == 0) { + // subscription settings + } else if (g_strcmp0(args[0], "sub") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Subscription notifications enabled."); prefs_set_boolean(PREF_NOTIFY_SUB, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Subscription notifications disabled."); prefs_set_boolean(PREF_NOTIFY_SUB, FALSE); } else { cons_show("Usage: /notify sub on|off"); } - // set remind setting - } else if (strcmp(kind, "remind") == 0) { - gint period = atoi(args[1]); - prefs_set_notify_remind(period); - if (period == 0) { - cons_show("Message reminders disabled."); - } else if (period == 1) { - cons_show("Message reminder period set to 1 second."); + // remind settings + } else if (g_strcmp0(args[0], "remind") == 0) { + if (!args[1]) { + cons_bad_cmd_usage(command); } else { - cons_show("Message reminder period set to %d seconds.", period); + gint period = atoi(args[1]); + prefs_set_notify_remind(period); + if (period == 0) { + cons_show("Message reminders disabled."); + } else if (period == 1) { + cons_show("Message reminder period set to 1 second."); + } else { + cons_show("Message reminder period set to %d seconds.", period); + } } + // current chat room settings + } else if (g_strcmp0(args[0], "on") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify(mucwin->roomjid, TRUE); + win_vprintln_ch(window, '!', "Notifications enabled for %s", mucwin->roomjid); + } + } + } else if (g_strcmp0(args[0], "off") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify(mucwin->roomjid, FALSE); + win_vprintln_ch(window, '!', "Notifications disabled for %s", mucwin->roomjid); + } + } + } else if (g_strcmp0(args[0], "mention") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + if (g_strcmp0(args[1], "on") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_mention(mucwin->roomjid, TRUE); + win_vprintln_ch(window, '!', "Mention notifications enabled for %s", mucwin->roomjid); + } + } else if (g_strcmp0(args[1], "off") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat rooms."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_mention(mucwin->roomjid, FALSE); + win_vprintln_ch(window, '!', "Mention notifications disabled for %s", mucwin->roomjid); + } + } else { + cons_bad_cmd_usage(command); + } + } + } else if (g_strcmp0(args[0], "trigger") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + if (g_strcmp0(args[1], "on") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_trigger(mucwin->roomjid, TRUE); + win_vprintln_ch(window, '!', "Custom trigger notifications enabled for %s", mucwin->roomjid); + } + } else if (g_strcmp0(args[1], "off") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat rooms."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_trigger(mucwin->roomjid, FALSE); + win_vprintln_ch(window, '!', "Custom trigger notifications disabled for %s", mucwin->roomjid); + } + } else { + cons_bad_cmd_usage(command); + } + } + } else if (g_strcmp0(args[0], "reset") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + gboolean res = prefs_reset_room_notify(mucwin->roomjid); + if (res) { + win_vprintln_ch(window, '!', "Notification settings set to global defaults for %s", mucwin->roomjid); + } else { + win_vprintln_ch(window, '!', "No custom notification settings for %s", mucwin->roomjid); + } + } + } } else { - cons_show("Unknown command: %s.", kind); + cons_bad_cmd_usage(command); } return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index 07985efc..a343f611 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -45,6 +45,7 @@ #include "log.h" #include "preferences.h" #include "tools/autocomplete.h" +#include "config/conflists.h" // preference groups refer to the sections in .profrc, for example [ui] #define PREF_GROUP_LOGGING "logging" @@ -64,6 +65,7 @@ static GKeyFile *prefs; gint log_maxsize = 0; static Autocomplete boolean_choice_ac; +static Autocomplete room_trigger_ac; static void _save_prefs(void); static gchar* _get_preferences_file(void); @@ -127,17 +129,41 @@ prefs_load(void) prefs_free_string(time); } + // move pre 0.4.8 notify settings + if (g_key_file_has_key(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL)) { + char *value = g_key_file_get_string(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL); + if (g_strcmp0(value, "on") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", TRUE); + } else if (g_strcmp0(value, "off") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); + } else if (g_strcmp0(value, "mention") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room.mention", TRUE); + } + } + _save_prefs(); boolean_choice_ac = autocomplete_new(); autocomplete_add(boolean_choice_ac, "on"); autocomplete_add(boolean_choice_ac, "off"); + + room_trigger_ac = autocomplete_new(); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + + int i = 0; + for (i = 0; i < len; i++) { + autocomplete_add(room_trigger_ac, triggers[i]); + } + g_strfreev(triggers); } void prefs_close(void) { autocomplete_free(boolean_choice_ac); + autocomplete_free(room_trigger_ac); g_key_file_free(prefs); prefs = NULL; } @@ -154,6 +180,180 @@ prefs_reset_boolean_choice(void) autocomplete_reset(boolean_choice_ac); } +char* +prefs_autocomplete_room_trigger(const char *const prefix) +{ + return autocomplete_complete(room_trigger_ac, prefix, TRUE); +} + +void +prefs_reset_room_trigger_ac(void) +{ + autocomplete_reset(room_trigger_ac); +} + +gboolean +prefs_do_chat_notify(gboolean current_win, const char *const message) +{ + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_CHAT_CURRENT); + gboolean notify_window = FALSE; + if (!current_win || (current_win && notify_current) ) { + notify_window = TRUE; + } + if (!notify_window) { + return FALSE; + } + + gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_CHAT); + if (notify_message) { + return TRUE; + } + + return FALSE; +} + +gboolean +prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, + const char *const message) +{ + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT); + gboolean notify_window = FALSE; + if (!current_win || (current_win && notify_current) ) { + notify_window = TRUE; + } + if (!notify_window) { + return FALSE; + } + + gboolean notify_room = FALSE; + if (g_key_file_has_key(prefs, roomjid, "notify", NULL)) { + notify_room = g_key_file_get_boolean(prefs, roomjid, "notify", NULL); + } else { + notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM); + } + if (notify_room) { + return TRUE; + } + + gboolean notify_mention = FALSE; + if (g_key_file_has_key(prefs, roomjid, "notify.mention", NULL)) { + notify_mention = g_key_file_get_boolean(prefs, roomjid, "notify.mention", NULL); + } else { + notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION); + } + if (notify_mention) { + char *message_lower = g_utf8_strdown(message, -1); + char *nick_lower = g_utf8_strdown(nick, -1); + if (g_strrstr(message_lower, nick_lower)) { + g_free(message_lower); + g_free(nick_lower); + return TRUE; + } + g_free(message_lower); + g_free(nick_lower); + } + + gboolean notify_trigger = FALSE; + if (g_key_file_has_key(prefs, roomjid, "notify.trigger", NULL)) { + notify_trigger = g_key_file_get_boolean(prefs, roomjid, "notify.trigger", NULL); + } else { + notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER); + } + if (notify_trigger) { + gboolean trigger_found = FALSE; + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } + g_free(trigger_lower); + } + g_strfreev(triggers); + g_free(message_lower); + + if (trigger_found) { + return TRUE; + } + } + + return FALSE; +} + +void +prefs_set_room_notify(const char *const roomjid, gboolean value) +{ + g_key_file_set_boolean(prefs, roomjid, "notify", value); + _save_prefs(); +} + +void +prefs_set_room_notify_mention(const char *const roomjid, gboolean value) +{ + g_key_file_set_boolean(prefs, roomjid, "notify.mention", value); + _save_prefs(); +} + +void +prefs_set_room_notify_trigger(const char *const roomjid, gboolean value) +{ + g_key_file_set_boolean(prefs, roomjid, "notify.trigger", value); + _save_prefs(); +} + +gboolean +prefs_has_room_notify(const char *const roomjid) +{ + return g_key_file_has_key(prefs, roomjid, "notify", NULL); +} + +gboolean +prefs_has_room_notify_mention(const char *const roomjid) +{ + return g_key_file_has_key(prefs, roomjid, "notify.mention", NULL); +} + +gboolean +prefs_has_room_notify_trigger(const char *const roomjid) +{ + return g_key_file_has_key(prefs, roomjid, "notify.trigger", NULL); +} + +gboolean +prefs_get_room_notify(const char *const roomjid) +{ + return g_key_file_get_boolean(prefs, roomjid, "notify", NULL); +} + +gboolean +prefs_get_room_notify_mention(const char *const roomjid) +{ + return g_key_file_get_boolean(prefs, roomjid, "notify.mention", NULL); +} + +gboolean +prefs_get_room_notify_trigger(const char *const roomjid) +{ + return g_key_file_get_boolean(prefs, roomjid, "notify.trigger", NULL); +} + +gboolean +prefs_reset_room_notify(const char *const roomjid) +{ + if (g_key_file_has_group(prefs, roomjid)) { + g_key_file_remove_group(prefs, roomjid, NULL); + _save_prefs(); + return TRUE; + } + + return FALSE; +} + gboolean prefs_get_boolean(preference_t pref) { @@ -606,6 +806,49 @@ prefs_set_roster_presence_indent(gint value) _save_prefs(); } +gboolean +prefs_add_room_notify_trigger(const char * const text) +{ + gboolean res = conf_string_list_add(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", text); + _save_prefs(); + + if (res) { + autocomplete_add(room_trigger_ac, text); + } + + return res; +} + +gboolean +prefs_remove_room_notify_trigger(const char * const text) +{ + gboolean res = conf_string_list_remove(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", text); + _save_prefs(); + + if (res) { + autocomplete_remove(room_trigger_ac, text); + } + + return res; +} + +GList* +prefs_get_room_notify_triggers(void) +{ + GList *result = NULL; + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + + int i; + for (i = 0; i < len; i++) { + result = g_list_append(result, strdup(triggers[i])); + } + + g_strfreev(triggers); + + return result; +} + gboolean prefs_add_alias(const char *const name, const char *const value) { @@ -779,10 +1022,12 @@ _get_group(preference_t pref) return PREF_GROUP_CHATSTATES; case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: - case PREF_NOTIFY_MESSAGE: - case PREF_NOTIFY_MESSAGE_CURRENT: - case PREF_NOTIFY_MESSAGE_TEXT: + case PREF_NOTIFY_CHAT: + case PREF_NOTIFY_CHAT_CURRENT: + case PREF_NOTIFY_CHAT_TEXT: case PREF_NOTIFY_ROOM: + case PREF_NOTIFY_ROOM_MENTION: + case PREF_NOTIFY_ROOM_TRIGGER: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_ROOM_TEXT: case PREF_NOTIFY_INVITE: @@ -869,14 +1114,18 @@ _get_key(preference_t pref) return "typing"; case PREF_NOTIFY_TYPING_CURRENT: return "typing.current"; - case PREF_NOTIFY_MESSAGE: + case PREF_NOTIFY_CHAT: return "message"; - case PREF_NOTIFY_MESSAGE_CURRENT: + case PREF_NOTIFY_CHAT_CURRENT: return "message.current"; - case PREF_NOTIFY_MESSAGE_TEXT: + case PREF_NOTIFY_CHAT_TEXT: return "message.text"; case PREF_NOTIFY_ROOM: return "room"; + case PREF_NOTIFY_ROOM_TRIGGER: + return "room.trigger"; + case PREF_NOTIFY_ROOM_MENTION: + return "room.mention"; case PREF_NOTIFY_ROOM_CURRENT: return "room.current"; case PREF_NOTIFY_ROOM_TEXT: @@ -987,8 +1236,9 @@ _get_default_boolean(preference_t pref) case PREF_AUTOAWAY_CHECK: case PREF_LOG_ROTATE: case PREF_LOG_SHARED: - case PREF_NOTIFY_MESSAGE: - case PREF_NOTIFY_MESSAGE_CURRENT: + case PREF_NOTIFY_CHAT: + case PREF_NOTIFY_CHAT_CURRENT: + case PREF_NOTIFY_ROOM: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: @@ -1026,8 +1276,6 @@ _get_default_string(preference_t pref) { case PREF_AUTOAWAY_MODE: return "off"; - case PREF_NOTIFY_ROOM: - return "on"; case PREF_OTR_LOG: return "redact"; case PREF_OTR_POLICY: diff --git a/src/config/preferences.h b/src/config/preferences.h index 607a1abe..b2411906 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -93,10 +93,12 @@ typedef enum { PREF_OUTTYPE, PREF_NOTIFY_TYPING, PREF_NOTIFY_TYPING_CURRENT, - PREF_NOTIFY_MESSAGE, - PREF_NOTIFY_MESSAGE_CURRENT, - PREF_NOTIFY_MESSAGE_TEXT, + PREF_NOTIFY_CHAT, + PREF_NOTIFY_CHAT_CURRENT, + PREF_NOTIFY_CHAT_TEXT, PREF_NOTIFY_ROOM, + PREF_NOTIFY_ROOM_MENTION, + PREF_NOTIFY_ROOM_TRIGGER, PREF_NOTIFY_ROOM_CURRENT, PREF_NOTIFY_ROOM_TEXT, PREF_NOTIFY_INVITE, @@ -133,9 +135,13 @@ void prefs_close(void); char* prefs_find_login(char *prefix); void prefs_reset_login_search(void); + char* prefs_autocomplete_boolean_choice(const char *const prefix); void prefs_reset_boolean_choice(void); +char* prefs_autocomplete_room_trigger(const char *const prefix); +void prefs_reset_room_trigger_ac(void); + gint prefs_get_gone(void); void prefs_set_gone(gint value); @@ -192,10 +198,28 @@ char* prefs_get_alias(const char *const name); GList* prefs_get_aliases(void); void prefs_free_aliases(GList *aliases); +gboolean prefs_add_room_notify_trigger(const char * const text); +gboolean prefs_remove_room_notify_trigger(const char * const text); +GList* prefs_get_room_notify_triggers(void); + gboolean prefs_get_boolean(preference_t pref); void prefs_set_boolean(preference_t pref, gboolean value); char* prefs_get_string(preference_t pref); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); +gboolean prefs_do_chat_notify(gboolean current_win, const char *const message); +gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, const char *const message); + +void prefs_set_room_notify(const char *const roomjid, gboolean value); +void prefs_set_room_notify_mention(const char *const roomjid, gboolean value); +void prefs_set_room_notify_trigger(const char *const roomjid, gboolean value); +gboolean prefs_reset_room_notify(const char *const roomjid); +gboolean prefs_has_room_notify(const char *const roomjid); +gboolean prefs_has_room_notify_mention(const char *const roomjid); +gboolean prefs_has_room_notify_trigger(const char *const roomjid); +gboolean prefs_get_room_notify(const char *const roomjid); +gboolean prefs_get_room_notify_mention(const char *const roomjid); +gboolean prefs_get_room_notify_trigger(const char *const roomjid); + #endif diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index c34cc1fc..2875256d 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -239,6 +239,9 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha char *display_name = roster_get_msg_display_name(chatwin->barejid, resource); + gboolean is_current = wins_is_current(window); + gboolean notify = prefs_do_chat_notify(is_current, message); + // currently viewing chat window with sender if (wins_is_current(window)) { win_print_incoming_message(window, timestamp, display_name, message, enc_mode); @@ -255,6 +258,9 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha } chatwin->unread++; + if (notify) { + chatwin->notify = TRUE; + } if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { _chatwin_history(chatwin, chatwin->barejid); } @@ -274,8 +280,20 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha beep(); } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - notify_message(window, display_name, message); + if (!notify) { + free(display_name); + return; + } + + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + + if (prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) { + notify_message(display_name, ui_index, message); + } else { + notify_message(display_name, ui_index, NULL); } free(display_name); diff --git a/src/ui/console.c b/src/ui/console.c index 6aa706c5..775fa671 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1323,72 +1323,78 @@ cons_show_ui_prefs(void) void cons_notify_setting(void) { - if (is_notify_enabled()) { - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) - cons_show("Messages (/notify message) : ON"); - else - cons_show("Messages (/notify message) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) - cons_show("Messages current (/notify message) : ON"); - else - cons_show("Messages current (/notify message) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) - cons_show("Messages text (/notify message) : ON"); - else - cons_show("Messages text (/notify message) : OFF"); - - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - if (g_strcmp0(room_setting, "on") == 0) { - cons_show ("Room messages (/notify room) : ON"); - } else if (g_strcmp0(room_setting, "off") == 0) { - cons_show ("Room messages (/notify room) : OFF"); - } else { - cons_show ("Room messages (/notify room) : %s", room_setting); - } - prefs_free_string(room_setting); - - if (prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) - cons_show("Room current (/notify room) : ON"); - else - cons_show("Room current (/notify room) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) - cons_show("Room text (/notify room) : ON"); - else - cons_show("Room text (/notify room) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_TYPING)) - cons_show("Composing (/notify typing) : ON"); - else - cons_show("Composing (/notify typing) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) - cons_show("Composing current (/notify typing) : ON"); - else - cons_show("Composing current (/notify typing) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_INVITE)) - cons_show("Room invites (/notify invite) : ON"); - else - cons_show("Room invites (/notify invite) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_SUB)) - cons_show("Subscription requests (/notify sub) : ON"); - else - cons_show("Subscription requests (/notify sub) : OFF"); - - gint remind_period = prefs_get_notify_remind(); - if (remind_period == 0) { - cons_show("Reminder period (/notify remind) : OFF"); - } else if (remind_period == 1) { - cons_show("Reminder period (/notify remind) : 1 second"); - } else { - cons_show("Reminder period (/notify remind) : %d seconds", remind_period); - } - } else { + if (!is_notify_enabled()) { cons_show("Notification support was not included in this build."); + return; + } + + if (prefs_get_boolean(PREF_NOTIFY_CHAT)) + cons_show("Chat message (/notify chat) : ON"); + else + cons_show("Chat message (/notify chat) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_CHAT_CURRENT)) + cons_show("Chat current (/notify chat) : ON"); + else + cons_show("Chat current (/notify chat) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) + cons_show("Chat text (/notify chat) : ON"); + else + cons_show("Chat text (/notify chat) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM)) + cons_show("Room message (/notify room) : ON"); + else + cons_show("Room message (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION)) + cons_show("Room mention (/notify room) : ON"); + else + cons_show("Room mention (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) + cons_show("Room trigger (/notify room) : ON"); + else + cons_show("Room trigger (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) + cons_show("Room current (/notify room) : ON"); + else + cons_show("Room current (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) + cons_show("Room text (/notify room) : ON"); + else + cons_show("Room text (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_TYPING)) + cons_show("Composing (/notify typing) : ON"); + else + cons_show("Composing (/notify typing) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) + cons_show("Composing current (/notify typing) : ON"); + else + cons_show("Composing current (/notify typing) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_INVITE)) + cons_show("Room invites (/notify invite) : ON"); + else + cons_show("Room invites (/notify invite) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_SUB)) + cons_show("Subscription requests (/notify sub) : ON"); + else + cons_show("Subscription requests (/notify sub) : OFF"); + + gint remind_period = prefs_get_notify_remind(); + if (remind_period == 0) { + cons_show("Reminder period (/notify remind) : OFF"); + } else if (remind_period == 1) { + cons_show("Reminder period (/notify remind) : 1 second"); + } else { + cons_show("Reminder period (/notify remind) : %d seconds", remind_period); } } diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 58fef4d1..097e9589 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -374,6 +374,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes win_print(window, '-', 0, NULL, 0, THEME_TEXT_ME, nick, message); } + gboolean is_current = wins_is_current(window); + gboolean notify = prefs_do_room_notify(is_current, mucwin->roomjid, my_nick, message); + // currently in groupchat window if (wins_is_current(window)) { status_bar_active(num); @@ -388,11 +391,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes } mucwin->unread++; - } - - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; + if (notify) { + mucwin->notify = TRUE; + } } // don't notify self messages @@ -404,34 +405,22 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes beep(); } - gboolean notify = FALSE; - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - if (g_strcmp0(room_setting, "on") == 0) { - notify = TRUE; + if (!notify) { + return; } - if (g_strcmp0(room_setting, "mention") == 0) { - char *message_lower = g_utf8_strdown(message, -1); - char *nick_lower = g_utf8_strdown(nick, -1); - if (g_strrstr(message_lower, nick_lower)) { - notify = TRUE; - } - g_free(message_lower); - g_free(nick_lower); - } - prefs_free_string(room_setting); - if (notify) { - gboolean is_current = wins_is_current(window); - if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { - Jid *jidp = jid_create(mucwin->roomjid); - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { - notify_room_message(nick, jidp->localpart, ui_index, message); - } else { - notify_room_message(nick, jidp->localpart, ui_index, NULL); - } - jid_destroy(jidp); - } + Jid *jidp = jid_create(mucwin->roomjid); + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; } + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { + notify_room_message(nick, jidp->localpart, ui_index, message); + } else { + notify_room_message(nick, jidp->localpart, ui_index, NULL); + } + jid_destroy(jidp); } void diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 9127b1e7..9a185e38 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -73,17 +73,16 @@ notifier_uninit(void) } void -notify_typing(const char *const handle) +notify_typing(const char *const name) { - char message[strlen(handle) + 1 + 11]; - sprintf(message, "%s: typing...", handle); + char message[strlen(name) + 1 + 11]; + sprintf(message, "%s: typing...", name); _notify(message, 10000, "Incoming message"); } void -notify_invite(const char *const from, const char *const room, - const char *const reason) +notify_invite(const char *const from, const char *const room, const char *const reason) { GString *message = g_string_new("Room invite\nfrom: "); g_string_append(message, from); @@ -99,32 +98,24 @@ notify_invite(const char *const from, const char *const room, } void -notify_message(ProfWin *window, const char *const name, const char *const text) +notify_message(const char *const name, int win, const char *const text) { - int num = wins_get_num(window); - if (num == 10) { - num = 0; + GString *message = g_string_new(""); + g_string_append_printf(message, "%s (win %d)", name, win); + if (text) { + g_string_append_printf(message, "\n%s", text); } - gboolean is_current = wins_is_current(window); - if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { - GString *message = g_string_new(""); - g_string_append_printf(message, "%s (win %d)", name, num); + _notify(message->str, 10000, "incoming message"); - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT) && text) { - g_string_append_printf(message, "\n%s", text); - } - - _notify(message->str, 10000, "incoming message"); - g_string_free(message, TRUE); - } + g_string_free(message, TRUE); } void -notify_room_message(const char *const handle, const char *const room, int win, const char *const text) +notify_room_message(const char *const nick, const char *const room, int win, const char *const text) { GString *message = g_string_new(""); - g_string_append_printf(message, "%s in %s (win %d)", handle, room, win); + g_string_append_printf(message, "%s in %s (win %d)", nick, room, win); if (text) { g_string_append_printf(message, "\n%s", text); } @@ -149,13 +140,14 @@ notify_remind(void) gdouble elapsed = g_timer_elapsed(remind_timer, NULL); gint remind_period = prefs_get_notify_remind(); if (remind_period > 0 && elapsed >= remind_period) { + gboolean notify = wins_get_notify(); gint unread = wins_get_total_unread(); gint open = muc_invites_count(); gint subs = presence_sub_request_count(); GString *text = g_string_new(""); - if (unread > 0) { + if (notify && unread > 0) { if (unread == 1) { g_string_append(text, "1 unread message"); } else { @@ -184,7 +176,7 @@ notify_remind(void) } } - if ((unread > 0) || (open > 0) || (subs > 0)) { + if ((notify && unread > 0) || (open > 0) || (subs > 0)) { _notify(text->str, 5000, "Incoming message"); } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 6031a2c0..204335bd 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -53,6 +53,9 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat char *display_from = get_nick_from_full_jid(privatewin->fulljid); + gboolean is_current = wins_is_current(window); + gboolean notify = prefs_do_chat_notify(is_current, message); + // currently viewing chat window with sender if (wins_is_current(window)) { win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN); @@ -62,6 +65,9 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat // not currently viewing chat window with sender } else { privatewin->unread++; + if (notify) { + privatewin->notify = TRUE; + } status_bar_new(num); cons_show_incoming_message(display_from, num); win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN); @@ -75,8 +81,20 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat beep(); } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - notify_message(window, display_from, message); + if (!notify) { + free(display_from); + return; + } + + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + + if (prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) { + notify_message(display_from, ui_index, message); + } else { + notify_message(display_from, ui_index, NULL); } free(display_from); diff --git a/src/ui/ui.h b/src/ui/ui.h index 032a1161..458255f1 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -319,6 +319,7 @@ ProfWin* win_create_muc_config(const char *const title, DataForm *form); ProfWin* win_create_private(const char *const fulljid); void win_update_virtual(ProfWin *window); void win_free(ProfWin *window); +gboolean win_notify(ProfWin *window); int win_unread(ProfWin *window); void win_resize(ProfWin *window); void win_hide_subwin(ProfWin *window); @@ -339,9 +340,9 @@ void win_clear(ProfWin *window); // desktop notifications void notifier_initialise(void); void notifier_uninit(void); -void notify_typing(const char *const handle); -void notify_message(ProfWin *window, const char *const name, const char *const text); -void notify_room_message(const char *const handle, const char *const room, int win, const char *const text); +void notify_typing(const char *const name); +void notify_message(const char *const name, int win, const char *const text); +void notify_room_message(const char *const nick, const char *const room, int win, const char *const text); void notify_remind(void); void notify_invite(const char *const from, const char *const room, const char *const reason); void notify_subscription(const char *const from); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index bace4537..94901957 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -102,6 +102,7 @@ typedef struct prof_chat_win_t { ProfWin window; char *barejid; int unread; + gboolean notify; ChatState *state; gboolean is_otr; gboolean otr_is_trusted; @@ -116,6 +117,7 @@ typedef struct prof_muc_win_t { ProfWin window; char *roomjid; int unread; + gboolean notify; gboolean showjid; unsigned long memcheck; } ProfMucWin; @@ -131,6 +133,7 @@ typedef struct prof_private_win_t { ProfWin window; char *fulljid; int unread; + gboolean notify; unsigned long memcheck; } ProfPrivateWin; diff --git a/src/ui/window.c b/src/ui/window.c index 9317f3b8..d6500a67 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -141,6 +141,7 @@ win_create_chat(const char *const barejid) new_win->pgp_send = FALSE; new_win->history_shown = FALSE; new_win->unread = 0; + new_win->notify = FALSE; new_win->state = chat_state_new(); new_win->memcheck = PROFCHATWIN_MEMCHECK; @@ -180,6 +181,7 @@ win_create_muc(const char *const roomjid) new_win->roomjid = strdup(roomjid); new_win->unread = 0; + new_win->notify = FALSE; if (prefs_get_boolean(PREF_OCCUPANTS_JID)) { new_win->showjid = TRUE; } else { @@ -215,6 +217,7 @@ win_create_private(const char *const fulljid) new_win->fulljid = strdup(fulljid); new_win->unread = 0; + new_win->notify = FALSE; new_win->memcheck = PROFPRIVATEWIN_MEMCHECK; @@ -1245,6 +1248,26 @@ win_has_active_subwin(ProfWin *window) } } +gboolean +win_notify(ProfWin *window) +{ + if (window->type == WIN_CHAT) { + ProfChatWin *chatwin = (ProfChatWin*) window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + return chatwin->notify; + } else if (window->type == WIN_MUC) { + ProfMucWin *mucwin = (ProfMucWin*) window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + return mucwin->notify; + } else if (window->type == WIN_PRIVATE) { + ProfPrivateWin *privatewin = (ProfPrivateWin*) window; + assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK); + return privatewin->notify; + } else { + return FALSE; + } +} + int win_unread(ProfWin *window) { diff --git a/src/window_list.c b/src/window_list.c index 46da0e75..14bf6ea5 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -189,13 +189,16 @@ wins_set_current_by_num(int i) ProfChatWin *chatwin = (ProfChatWin*) window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); chatwin->unread = 0; + chatwin->notify = FALSE; } else if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin*) window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); mucwin->unread = 0; + mucwin->notify = FALSE; } else if (window->type == WIN_PRIVATE) { ProfPrivateWin *privatewin = (ProfPrivateWin*) window; privatewin->unread = 0; + privatewin->notify = FALSE; } } } @@ -382,6 +385,23 @@ wins_new_private(const char *const fulljid) return newwin; } +gboolean +wins_get_notify(void) +{ + GList *values = g_hash_table_get_values(windows); + GList *curr = values; + + while (curr) { + ProfWin *window = curr->data; + if (win_notify(window)) { + g_list_free(values); + return TRUE; + } + curr = g_list_next(curr); + } + return FALSE; +} + int wins_get_total_unread(void) { diff --git a/src/window_list.h b/src/window_list.h index 4b7dca8c..4cf4e5f8 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -67,6 +67,7 @@ int wins_get_current_num(void); void wins_close_current(void); void wins_close_by_num(int i); gboolean wins_is_current(ProfWin *window); +gboolean wins_get_notify(void); int wins_get_total_unread(void); void wins_resize_all(void); GSList* wins_get_chat_recipients(void); diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c index 5d81060d..11c056e1 100644 --- a/tests/functionaltests/proftest.c +++ b/tests/functionaltests/proftest.c @@ -179,8 +179,8 @@ init_prof_test(void **state) assert_true(prof_output_exact("Input blocking set to 5 milliseconds")); prof_input("/inpblock dynamic off"); assert_true(prof_output_exact("Dynamic input blocking disabled")); - prof_input("/notify message off"); - assert_true(prof_output_exact("Message notifications disabled")); + prof_input("/notify chat off"); + assert_true(prof_output_exact("Chat notifications disabled")); prof_input("/wrap off"); assert_true(prof_output_exact("Word wrap disabled")); prof_input("/roster hide"); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 084b36be..37d49d4d 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -486,6 +486,10 @@ ProfWin* win_create_private(const char * const fulljid) void win_update_virtual(ProfWin *window) {} void win_free(ProfWin *window) {} +gboolean win_notify(ProfWin *window) +{ + return TRUE; +} int win_unread(ProfWin *window) { return 0; @@ -514,7 +518,7 @@ void win_clear(ProfWin *window) {} void notifier_uninit(void) {} void notify_typing(const char * const handle) {} -void notify_message(ProfWin *window, const char * const name, const char * const text) {} +void notify_message(const char *const name, int win, const char *const text) {} void notify_room_message(const char * const handle, const char * const room, int win, const char * const text) {} void notify_remind(void) {}