about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-01-24 23:47:17 +0000
committerJames Booth <boothj5@gmail.com>2016-01-24 23:47:17 +0000
commitb6e9a09c64ca4438aa066759caf9a4008edadd46 (patch)
tree4e0df1861978eabecf69b8a9a6346777c46f9088 /src
parent628119680955dfe693dc4109551385f454999771 (diff)
downloadprofani-tty-b6e9a09c64ca4438aa066759caf9a4008edadd46.tar.gz
Show console messages for room mention and triggers
closes #719
Diffstat (limited to 'src')
-rw-r--r--src/config/preferences.c1
-rw-r--r--src/event/server_events.c13
-rw-r--r--src/ui/console.c55
-rw-r--r--src/ui/ui.h3
4 files changed, 56 insertions, 16 deletions
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 7e798dc8..bb85c682 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -223,7 +223,6 @@ prefs_message_get_triggers(const char *const message)
     for (i = 0; i < len; i++) {
         char *trigger_lower = g_utf8_strdown(triggers[i], -1);
         if (g_strrstr(message_lower, trigger_lower)) {
-            g_free(trigger_lower);
             result = g_list_append(result, strdup(triggers[i]));
         }
         g_free(trigger_lower);
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 9f343e50..64f82dc0 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -270,13 +270,8 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
     // not currently on groupchat window
     } else {
         status_bar_new(num);
-        char *muc_show = prefs_get_string(PREF_CONSOLE_MUC);
-        if (g_strcmp0(muc_show, "all") == 0) {
-            cons_show_incoming_room_message(nick, mucwin->roomjid, num);
-        } else if (g_strcmp0(muc_show, "first") == 0 && mucwin->unread == 0) {
-            cons_show_incoming_room_message(NULL, mucwin->roomjid, num);
-        }
-        prefs_free_string(muc_show);
+
+        cons_show_incoming_room_message(nick, mucwin->roomjid, num, mention, triggers, mucwin->unread);
 
         if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, mynick) != 0)) {
             flash();
@@ -288,6 +283,10 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
         }
     }
 
+    if (triggers) {
+        g_list_free_full(triggers, free);
+    }
+
     rosterwin_roster();
 
     // don't notify self messages
diff --git a/src/ui/console.c b/src/ui/console.c
index 6fd6fc38..2be41b14 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -301,8 +301,27 @@ cons_show_typing(const char *const barejid)
     cons_alert();
 }
 
+char*
+_room_triggers_to_string(GList *triggers)
+{
+    GString *triggers_str = g_string_new("");
+    GList *curr = triggers;
+    while (curr) {
+        g_string_append_printf(triggers_str, "\"%s\"", (char*)curr->data);
+        curr = g_list_next(curr);
+        if (curr) {
+            g_string_append(triggers_str, ", ");
+        }
+    }
+
+    char *result = triggers_str->str;
+    g_string_free(triggers_str, FALSE);
+    return result;
+}
+
 void
-cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index)
+cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index, gboolean mention,
+    GList *triggers, int unread)
 {
     ProfWin *const console = wins_get_console();
 
@@ -311,13 +330,35 @@ cons_show_incoming_room_message(const char *const nick, const char *const room,
         ui_index = 0;
     }
 
-    if (nick) {
-        win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room message: %s in %s (win %d)", nick, room, ui_index);
-    } else {
-        win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room message: %s (win %d)", room, ui_index);
-    }
+    char *muc_show = prefs_get_string(PREF_CONSOLE_MUC);
 
-    cons_alert();
+    if (g_strcmp0(muc_show, "all") == 0) {
+        if (mention) {
+            win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room mention: %s in %s (win %d)", nick, room, ui_index);
+        } else if (triggers) {
+            char *triggers_str = _room_triggers_to_string(triggers);
+            win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room trigger %s: %s in %s (win %d)", triggers_str, nick, room, ui_index);
+            free(triggers_str);
+        } else {
+            win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room message: %s in %s (win %d)", nick, room, ui_index);
+        }
+        cons_alert();
+
+    } else if (g_strcmp0(muc_show, "first") == 0) {
+        if (mention) {
+            win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room mention: %s in %s (win %d)", nick, room, ui_index);
+            cons_alert();
+        } else if (triggers) {
+            char *triggers_str = _room_triggers_to_string(triggers);
+            win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room trigger %s: %s in %s (win %d)", triggers_str, nick, room, ui_index);
+            free(triggers_str);
+            cons_alert();
+        } else if (unread == 0) {
+            win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< room message: %s (win %d)", room, ui_index);
+            cons_alert();
+        }
+    }
+    prefs_free_string(muc_show);
 }
 
 void
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 86f68d3c..835fd890 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -257,7 +257,8 @@ void cons_show_disco_info(const char *from, GSList *identities, GSList *features
 void cons_show_room_invite(const char *const invitor, const char *const room, const char *const reason);
 void cons_check_version(gboolean not_available_msg);
 void cons_show_typing(const char *const barejid);
-void cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index);
+void cons_show_incoming_room_message(const char *const nick, const char *const room, const int win_index,
+    gboolean mention, GList *triggers, int unread);
 void cons_show_incoming_message(const char *const short_from, const int win_index);
 void cons_show_incoming_private_message(const char *const nick, const char *const room, const int win_index);
 void cons_show_room_invites(GSList *invites);