about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-02-07 01:15:40 +0000
committerJames Booth <boothj5@gmail.com>2016-02-07 01:15:40 +0000
commit62b0cdd8fd3e811033f58d39a744d7f7eb973e3c (patch)
tree43f9acb0313f61980290fbf59f4dada7b9128ee9
parentabc2f0de39e39638fc519ad38de55d5ce0d93f28 (diff)
downloadprofani-tty-62b0cdd8fd3e811033f58d39a744d7f7eb973e3c.tar.gz
Fix room notification reminders
-rw-r--r--src/config/preferences.c36
-rw-r--r--src/config/preferences.h1
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/window.c12
-rw-r--r--src/window_list.c2
-rw-r--r--tests/unittests/ui/stub_ui.c2
6 files changed, 42 insertions, 13 deletions
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 12870bb1..96d97f39 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -277,6 +277,42 @@ prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char
     return FALSE;
 }
 
+gboolean
+prefs_do_room_notify_mention(const char *const roomjid, int unread, gboolean mention, gboolean trigger)
+{
+    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 && unread > 0) {
+        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 && mention) {
+        return TRUE;
+    }
+
+    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 && trigger) {
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
 void
 prefs_set_room_notify(const char *const roomjid, gboolean value)
 {
diff --git a/src/config/preferences.h b/src/config/preferences.h
index a89ee65b..d97cd015 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -235,6 +235,7 @@ 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 mynick,
     const char *const theirnick, const char *const message, gboolean mention, gboolean trigger_found);
+gboolean prefs_do_room_notify_mention(const char *const roomjid, int unread, gboolean mention, gboolean trigger);
 GList* prefs_message_get_triggers(const char *const message);
 
 void prefs_set_room_notify(const char *const roomjid, gboolean value);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 62454e72..70b01df3 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -345,7 +345,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);
+gboolean win_notify_remind(ProfWin *window);
 int win_unread(ProfWin *window);
 void win_resize(ProfWin *window);
 void win_hide_subwin(ProfWin *window);
diff --git a/src/ui/window.c b/src/ui/window.c
index 345470b2..66fcc334 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1308,7 +1308,7 @@ win_has_active_subwin(ProfWin *window)
 }
 
 gboolean
-win_notify(ProfWin *window)
+win_notify_remind(ProfWin *window)
 {
     switch (window->type) {
     case WIN_CHAT:
@@ -1327,15 +1327,7 @@ win_notify(ProfWin *window)
         ProfMucWin *mucwin = (ProfMucWin*) window;
         assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
 
-        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;
-        }
+        return prefs_do_room_notify_mention(mucwin->roomjid, mucwin->unread, mucwin->unread_mentions, mucwin->unread_triggers);
     }
     case WIN_PRIVATE:
     {
diff --git a/src/window_list.c b/src/window_list.c
index b275fe63..7ba62e47 100644
--- a/src/window_list.c
+++ b/src/window_list.c
@@ -622,7 +622,7 @@ wins_do_notify_remind(void)
 
     while (curr) {
         ProfWin *window = curr->data;
-        if (win_notify(window)) {
+        if (win_notify_remind(window)) {
             g_list_free(values);
             return TRUE;
         }
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index 521431b8..40467c6e 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -497,7 +497,7 @@ ProfWin* win_create_private(const char * const fulljid)
 
 void win_update_virtual(ProfWin *window) {}
 void win_free(ProfWin *window) {}
-gboolean win_notify(ProfWin *window)
+gboolean win_notify_remind(ProfWin *window)
 {
     return TRUE;
 }