From d3389db2336544b6f611ef03d7eb390ab4f7d295 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 25 Nov 2015 22:08:33 +0000 Subject: Only show reminder notifications when notifications are enabled --- src/ui/chatwin.c | 8 ++++++-- src/ui/mucwin.c | 8 ++++++-- src/ui/notifier.c | 5 +++-- src/ui/privwin.c | 18 ++++++------------ src/ui/ui.h | 1 + src/ui/win_types.h | 3 +++ src/ui/window.c | 23 +++++++++++++++++++++++ src/window_list.c | 20 ++++++++++++++++++++ src/window_list.h | 1 + tests/unittests/ui/stub_ui.c | 4 ++++ 10 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index f9bbedde..c8cee66b 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_get_notify_chat(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,6 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha beep(); } - gboolean is_current = wins_is_current(window); - gboolean notify = prefs_get_notify_chat(is_current, message); if (!notify) { free(display_name); return; diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index aa825d16..82b74e1b 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_get_notify_room(is_current, my_nick, message); + // currently in groupchat window if (wins_is_current(window)) { status_bar_active(num); @@ -388,6 +391,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes } mucwin->unread++; + if (notify) { + mucwin->notify = TRUE; + } } // don't notify self messages @@ -399,8 +405,6 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes beep(); } - gboolean is_current = wins_is_current(window); - gboolean notify = prefs_get_notify_room(is_current, my_nick, message); if (!notify) { return; } diff --git a/src/ui/notifier.c b/src/ui/notifier.c index c0861009..9a185e38 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -140,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 { @@ -175,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 10ce1dbe..67bad379 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_get_notify_chat(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,18 +81,6 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat beep(); } - if (!prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - free(display_from); - return; - } - - gboolean notify = FALSE; - - gboolean is_current = wins_is_current(window); - if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { - notify = TRUE; - } - if (!notify) { free(display_from); return; diff --git a/src/ui/ui.h b/src/ui/ui.h index 3cc40001..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); 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/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 4cab2ea9..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; -- cgit 1.4.1-2-gfad0