about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-11-25 01:42:27 +0000
committerJames Booth <boothj5@gmail.com>2015-11-25 01:42:27 +0000
commitb9794361f7eb59052b8662284ca11b18bb3187dc (patch)
tree1151f7ca5bb2147061dca9d7cdf5da1ea121b4f1
parent01682a759480a057ed8223ccc9961831fa700208 (diff)
downloadprofani-tty-b9794361f7eb59052b8662284ca11b18bb3187dc.tar.gz
Implemented regular chat notify triggers
-rw-r--r--src/config/preferences.c40
-rw-r--r--src/config/preferences.h2
-rw-r--r--src/ui/chatwin.c12
3 files changed, 39 insertions, 15 deletions
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 205d47df..d8ddd159 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -202,17 +202,51 @@ prefs_reset_room_trigger_ac(void)
     autocomplete_reset(room_trigger_ac);
 }
 
+
+
 gboolean
-prefs_get_notify_chat(gboolean current_win)
+prefs_get_notify_chat(gboolean current_win, const char *const message)
 {
     gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE);
-    gboolean notify_window = FALSE;
 
+    gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER);
+    gboolean trigger_found = FALSE;
+    if (notify_trigger) {
+        char *message_lower = g_utf8_strdown(message, -1);
+        gsize len = 0;
+        gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.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);
+    }
+
+    gboolean notify_window = FALSE;
     if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) {
         notify_window = TRUE;
     }
 
-    return (notify_message && notify_window);
+    if (!notify_window) {
+        return FALSE;
+    }
+
+    if (notify_message) {
+        return TRUE;
+    }
+
+    if (notify_trigger && trigger_found) {
+        return TRUE;
+    }
+
+    return FALSE;
 }
 
 gboolean
diff --git a/src/config/preferences.h b/src/config/preferences.h
index face1811..603ba30c 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -213,7 +213,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_get_notify_chat(gboolean current_win);
+gboolean prefs_get_notify_chat(gboolean current_win, const char *const message);
 gboolean prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message);
 
 #endif
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index 2efe82e1..f9bbedde 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -274,18 +274,8 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha
         beep();
     }
 
-    if (!prefs_get_boolean(PREF_NOTIFY_MESSAGE)) {
-        free(display_name);
-        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;
-    }
-
+    gboolean notify = prefs_get_notify_chat(is_current, message);
     if (!notify) {
         free(display_name);
         return;