From 834226560707358c47d85d16bd85a49e218ef2d8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 4 Feb 2016 00:21:38 +0000 Subject: [PATCH 1/5] Removed unused arg: prefs_do_chat_notify() --- src/config/preferences.c | 2 +- src/config/preferences.h | 2 +- src/ui/chatwin.c | 2 +- src/ui/notifier.c | 2 +- src/ui/privwin.c | 2 +- src/window_list.c | 2 +- src/window_list.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 36f3df38..d0506e06 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -192,7 +192,7 @@ prefs_reset_room_trigger_ac(void) } gboolean -prefs_do_chat_notify(gboolean current_win, const char *const message) +prefs_do_chat_notify(gboolean current_win) { gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_CHAT_CURRENT); gboolean notify_window = FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index 5bb219b1..baf43953 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -231,7 +231,7 @@ 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_chat_notify(gboolean current_win); gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, const char *const message, gboolean mention, gboolean trigger_found); GList* prefs_message_get_triggers(const char *const message); diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 05751f6c..718c6809 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -240,7 +240,7 @@ 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); + gboolean notify = prefs_do_chat_notify(is_current); // currently viewing chat window with sender if (wins_is_current(window)) { diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 9a185e38..30497fe3 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -140,7 +140,7 @@ 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(); + gboolean notify = wins_do_notify_remind(); gint unread = wins_get_total_unread(); gint open = muc_invites_count(); gint subs = presence_sub_request_count(); diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 00c50bb6..36cc29c7 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -57,7 +57,7 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat } gboolean is_current = wins_is_current(window); - gboolean notify = prefs_do_chat_notify(is_current, message); + gboolean notify = prefs_do_chat_notify(is_current); // currently viewing chat window with sender if (wins_is_current(window)) { diff --git a/src/window_list.c b/src/window_list.c index 62576b84..bfd1f422 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -589,7 +589,7 @@ wins_new_private(const char *const fulljid) } gboolean -wins_get_notify(void) +wins_do_notify_remind(void) { GList *values = g_hash_table_get_values(windows); GList *curr = values; diff --git a/src/window_list.h b/src/window_list.h index 7037e80e..46bac234 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -72,7 +72,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); +gboolean wins_do_notify_remind(void); int wins_get_total_unread(void); void wins_resize_all(void); GSList* wins_get_chat_recipients(void); From f8f9ad51979680e9aef316f637d8cf6d3bde1bc5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 4 Feb 2016 00:35:10 +0000 Subject: [PATCH 2/5] Tidy prefs_do_chat_notify() --- src/config/preferences.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index d0506e06..af89b0c6 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -194,21 +194,15 @@ prefs_reset_room_trigger_ac(void) gboolean prefs_do_chat_notify(gboolean current_win) { - 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) { + if (prefs_get_boolean(PREF_NOTIFY_CHAT) == FALSE) { return FALSE; + } else { + if ((current_win == FALSE) || ((current_win == TRUE) && prefs_get_boolean(PREF_NOTIFY_CHAT_CURRENT))) { + return TRUE; + } else { + return FALSE; + } } - - gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_CHAT); - if (notify_message) { - return TRUE; - } - - return FALSE; } GList* From c14ef3390690d732c64bf88a37b23dcdebb6e867 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 4 Feb 2016 00:41:53 +0000 Subject: [PATCH 3/5] Tidy notify_message() --- src/ui/chatwin.c | 16 ++-------------- src/ui/notifier.c | 11 ++++++++--- src/ui/privwin.c | 16 ++-------------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 718c6809..b086619e 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -280,20 +280,8 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha beep(); } - 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); + if (notify) { + notify_message(display_name, num, message); } free(display_name); diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 30497fe3..fda5aedd 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -98,11 +98,16 @@ notify_invite(const char *const from, const char *const room, const char *const } void -notify_message(const char *const name, int win, const char *const text) +notify_message(const char *const name, int num, const char *const text) { + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + GString *message = g_string_new(""); - g_string_append_printf(message, "%s (win %d)", name, win); - if (text) { + g_string_append_printf(message, "%s (win %d)", name, ui_index); + if (text && prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) { g_string_append_printf(message, "\n%s", text); } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 36cc29c7..c47a7565 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -85,20 +85,8 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat beep(); } - if (!notify) { - jid_destroy(jidp); - return; - } - - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; - } - - if (prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) { - notify_message(jidp->resourcepart, ui_index, message); - } else { - notify_message(jidp->resourcepart, ui_index, NULL); + if (notify) { + notify_message(jidp->resourcepart, num, message); } jid_destroy(jidp); From e1962261a90ceb12860ad64c564a610730c2cc6f Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 4 Feb 2016 00:45:37 +0000 Subject: [PATCH 4/5] Tidy notify_room_message() --- src/event/server_events.c | 19 ++++--------------- src/ui/notifier.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 35466be3..42d75cdb 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -305,22 +305,11 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha beep(); } - if (!notify) { - return; + if (notify) { + Jid *jidp = jid_create(mucwin->roomjid); + notify_room_message(nick, jidp->localpart, num, message); + 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 fda5aedd..23d942fb 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -117,11 +117,16 @@ notify_message(const char *const name, int num, const char *const text) } void -notify_room_message(const char *const nick, const char *const room, int win, const char *const text) +notify_room_message(const char *const nick, const char *const room, int num, const char *const text) { + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + GString *message = g_string_new(""); - g_string_append_printf(message, "%s in %s (win %d)", nick, room, win); - if (text) { + g_string_append_printf(message, "%s in %s (win %d)", nick, room, ui_index); + if (text && prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { g_string_append_printf(message, "\n%s", text); } From 6702bb9739ffae6f1b905e15fc9504773e0e64c4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 4 Feb 2016 01:24:37 +0000 Subject: [PATCH 5/5] Don't show notification reminders for messages the user does not want notifications for --- src/config/preferences.c | 8 ++++++-- src/config/preferences.h | 4 ++-- src/event/server_events.c | 38 ++++++++++++++-------------------- src/ui/chatwin.c | 4 +--- src/ui/privwin.c | 3 --- src/ui/win_types.h | 3 --- src/ui/window.c | 43 ++++++++++++++++++++++++++++++--------- src/window_list.c | 3 --- 8 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index af89b0c6..8642e20a 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -228,9 +228,13 @@ prefs_message_get_triggers(const char *const message) } gboolean -prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, const char *const message, - gboolean mention, gboolean trigger_found) +prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const mynick, + const char *const theirnick, const char *const message, gboolean mention, gboolean trigger_found) { + if (g_strcmp0(mynick, theirnick) == 0) { + return FALSE; + } + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT); gboolean notify_window = FALSE; if (!current_win || (current_win && notify_current) ) { diff --git a/src/config/preferences.h b/src/config/preferences.h index baf43953..8afb2707 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -232,8 +232,8 @@ void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); gboolean prefs_do_chat_notify(gboolean current_win); -gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, - const char *const message, gboolean mention, gboolean trigger_found); +gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const mynick, + const char *const theirnick, const char *const message, gboolean mention, gboolean trigger_found); GList* prefs_message_get_triggers(const char *const message); void prefs_set_room_notify(const char *const roomjid, gboolean value); diff --git a/src/event/server_events.c b/src/event/server_events.c index 42d75cdb..0b11fbfa 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -259,28 +259,29 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha mucwin_message(mucwin, nick, message, mention, triggers != NULL); ProfWin *window = (ProfWin*)mucwin; - gboolean is_current = wins_is_current(window); int num = wins_get_num(window); - gboolean notify = prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message, mention, triggers != NULL); + gboolean is_current = FALSE; // currently in groupchat window if (wins_is_current(window)) { + is_current = TRUE; status_bar_active(num); + if ((g_strcmp0(mynick, nick) != 0) && (prefs_get_boolean(PREF_BEEP))) { + beep(); + } + // not currently on groupchat window } else { status_bar_new(num); - cons_show_incoming_room_message(nick, mucwin->roomjid, num, mention, triggers, mucwin->unread); - - if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, mynick) != 0)) { + if ((g_strcmp0(mynick, nick) != 0) && (prefs_get_boolean(PREF_FLASH))) { flash(); } + cons_show_incoming_room_message(nick, mucwin->roomjid, num, mention, triggers, mucwin->unread); + mucwin->unread++; - if (notify) { - mucwin->notify = TRUE; - } if (mention) { mucwin->unread_mentions = TRUE; @@ -290,26 +291,17 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha } } + if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, nick, message, mention, triggers != NULL)) { + Jid *jidp = jid_create(mucwin->roomjid); + notify_room_message(nick, jidp->localpart, num, message); + jid_destroy(jidp); + } + if (triggers) { g_list_free_full(triggers, free); } rosterwin_roster(); - - // don't notify self messages - if (strcmp(nick, mynick) == 0) { - return; - } - - if (prefs_get_boolean(PREF_BEEP)) { - beep(); - } - - if (notify) { - Jid *jidp = jid_create(mucwin->roomjid); - notify_room_message(nick, jidp->localpart, num, message); - jid_destroy(jidp); - } } void diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index b086619e..1a87cbd8 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -258,9 +258,7 @@ 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); } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index c47a7565..d1f26cba 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -72,9 +72,6 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat win_print_incoming_message(window, timestamp, jidp->resourcepart, message, PROF_MSG_PLAIN); privatewin->unread++; - if (notify) { - privatewin->notify = TRUE; - } if (prefs_get_boolean(PREF_FLASH)) { flash(); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index 558359a2..54ded939 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -102,7 +102,6 @@ typedef struct prof_chat_win_t { ProfWin window; char *barejid; int unread; - gboolean notify; ChatState *state; gboolean is_otr; gboolean otr_is_trusted; @@ -119,7 +118,6 @@ typedef struct prof_muc_win_t { int unread; gboolean unread_mentions; gboolean unread_triggers; - gboolean notify; gboolean showjid; unsigned long memcheck; } ProfMucWin; @@ -135,7 +133,6 @@ typedef struct prof_private_win_t { ProfWin window; char *fulljid; int unread; - gboolean notify; unsigned long memcheck; gboolean occupant_offline; gboolean room_left; diff --git a/src/ui/window.c b/src/ui/window.c index d8499ad3..345470b2 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -141,7 +141,6 @@ 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; @@ -183,7 +182,6 @@ win_create_muc(const char *const roomjid) new_win->unread = 0; new_win->unread_mentions = FALSE; new_win->unread_triggers = FALSE; - new_win->notify = FALSE; if (prefs_get_boolean(PREF_OCCUPANTS_JID)) { new_win->showjid = TRUE; } else { @@ -219,7 +217,6 @@ win_create_private(const char *const fulljid) new_win->fulljid = strdup(fulljid); new_win->unread = 0; - new_win->notify = FALSE; new_win->occupant_offline = FALSE; new_win->room_left = FALSE; @@ -1313,19 +1310,45 @@ win_has_active_subwin(ProfWin *window) gboolean win_notify(ProfWin *window) { - if (window->type == WIN_CHAT) { + switch (window->type) { + case WIN_CHAT: + { ProfChatWin *chatwin = (ProfChatWin*) window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - return chatwin->notify; - } else if (window->type == WIN_MUC) { + + if (prefs_get_boolean(PREF_NOTIFY_CHAT) && chatwin->unread > 0) { + return TRUE; + } else { + return FALSE; + } + } + case WIN_MUC: + { ProfMucWin *mucwin = (ProfMucWin*) window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - return mucwin->notify; - } else if (window->type == WIN_PRIVATE) { + + if (prefs_get_room_notify(mucwin->roomjid) && mucwin->unread > 0) { + return TRUE; + } else if (prefs_get_room_notify_mention(mucwin->roomjid) && mucwin->unread_mentions) { + return TRUE; + } else if (prefs_get_room_notify_trigger(mucwin->roomjid) && mucwin->unread_triggers) { + return TRUE; + } else { + return FALSE; + } + } + case WIN_PRIVATE: + { ProfPrivateWin *privatewin = (ProfPrivateWin*) window; assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK); - return privatewin->notify; - } else { + + if (prefs_get_boolean(PREF_NOTIFY_CHAT) && privatewin->unread > 0) { + return TRUE; + } else { + return FALSE; + } + } + default: return FALSE; } } diff --git a/src/window_list.c b/src/window_list.c index bfd1f422..97155294 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -273,18 +273,15 @@ 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->unread_mentions = FALSE; mucwin->unread_triggers = FALSE; - mucwin->notify = FALSE; } else if (window->type == WIN_PRIVATE) { ProfPrivateWin *privatewin = (ProfPrivateWin*) window; privatewin->unread = 0; - privatewin->notify = FALSE; } } }