about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-01-21 10:20:34 +0100
committerMichael Vetter <jubalh@iodoru.org>2021-01-21 10:20:34 +0100
commita01c963b4604a24b1556e137b92aa1230abcac63 (patch)
tree46dc79543a84b97803cff4c1e0b2d84b07070ea7 /src
parent9e679a03a5180f0c6a7b8d466ec7b544647459f4 (diff)
downloadprofani-tty-a01c963b4604a24b1556e137b92aa1230abcac63.tar.gz
Simplify console notification code
Functions had some duplicate code:
* cons_show_incoming_room_message()
* cons_show_incoming_message()
* cons_show_incoming_private_message()
Diffstat (limited to 'src')
-rw-r--r--src/ui/console.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 1bfd1cc1..f701dc88 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -321,38 +321,30 @@ cons_show_incoming_room_message(const char* const nick, const char* const room,
 
     char* muc_show = prefs_get_string(PREF_CONSOLE_MUC);
 
-    if (g_strcmp0(muc_show, "all") == 0) {
+    // 'mention'
+    if (g_strcmp0(muc_show, "mention") == 0) {
         if (mention) {
             win_println(console, THEME_MENTION, "-", "<< room mention: %s in %s (win %d)", nick, room, ui_index);
-        } else if (triggers) {
-            char* triggers_str = _room_triggers_to_string(triggers);
-            win_println(console, THEME_TRIGGER, "-", "<< room trigger %s: %s in %s (win %d)", triggers_str, nick, room, ui_index);
-            free(triggers_str);
-        } else {
-            win_println(console, THEME_INCOMING, "-", "<< room message: %s in %s (win %d)", nick, room, ui_index);
+            cons_alert(window);
         }
-        cons_alert(window);
-
-    } else if (g_strcmp0(muc_show, "first") == 0) {
+        // 'all' or 'first'
+    } else {
         if (mention) {
             win_println(console, THEME_MENTION, "-", "<< room mention: %s in %s (win %d)", nick, room, ui_index);
-            cons_alert(window);
         } else if (triggers) {
             char* triggers_str = _room_triggers_to_string(triggers);
             win_println(console, THEME_TRIGGER, "-", "<< room trigger %s: %s in %s (win %d)", triggers_str, nick, room, ui_index);
             free(triggers_str);
-            cons_alert(window);
-        } else if (unread == 0) {
-            win_println(console, THEME_INCOMING, "-", "<< room message: %s (win %d)", room, ui_index);
-            cons_alert(window);
-        }
-    } else if (g_strcmp0(muc_show, "mention") == 0) {
-        if (mention) {
-            win_println(console, THEME_MENTION, "-", "<< room mention: %s in %s (win %d)", nick, room, ui_index);
+        } else {
+            // 'all' or 'first' if its the first message
+            if ((g_strcmp0(muc_show, "all") == 0) || ((g_strcmp0(muc_show, "first") == 0) && (unread == 0))) {
+                win_println(console, THEME_INCOMING, "-", "<< room message: %s in %s (win %d)", nick, room, ui_index);
+            }
             cons_alert(window);
         }
     }
-    g_free(muc_show);
+
+    free(muc_show);
 }
 
 void
@@ -366,10 +358,7 @@ cons_show_incoming_message(const char* const short_from, const int win_index, in
     }
 
     char* chat_show = prefs_get_string(PREF_CONSOLE_CHAT);
-    if (g_strcmp0(chat_show, "all") == 0) {
-        win_println(console, THEME_INCOMING, "-", "<< chat message: %s (win %d)", short_from, ui_index);
-        cons_alert(window);
-    } else if ((g_strcmp0(chat_show, "first") == 0) && unread == 0) {
+    if (g_strcmp0(chat_show, "all") == 0 || ((g_strcmp0(chat_show, "first") == 0) && unread == 0)) {
         win_println(console, THEME_INCOMING, "-", "<< chat message: %s (win %d)", short_from, ui_index);
         cons_alert(window);
     }
@@ -388,15 +377,12 @@ cons_show_incoming_private_message(const char* const nick, const char* const roo
     }
 
     char* priv_show = prefs_get_string(PREF_CONSOLE_PRIVATE);
-    if (g_strcmp0(priv_show, "all") == 0) {
-        win_println(console, THEME_INCOMING, "-", "<< private message: %s in %s (win %d)", nick, room, ui_index);
-        cons_alert(window);
-    } else if ((g_strcmp0(priv_show, "first") == 0) && unread == 0) {
+    if (g_strcmp0(priv_show, "all") == 0 || ((g_strcmp0(priv_show, "first") == 0) && (unread == 0))) {
         win_println(console, THEME_INCOMING, "-", "<< private message: %s in %s (win %d)", nick, room, ui_index);
         cons_alert(window);
     }
 
-    g_free(priv_show);
+    free(priv_show);
 }
 
 void