about summary refs log tree commit diff stats
path: root/src/ui/window.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-04-06 15:21:45 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-04-06 15:33:01 +0200
commit067bc690f28f32b59714579608a5f1469b1f5212 (patch)
treed62b6ea7402372fde6b9e933fe807593439705d8 /src/ui/window.c
parent0942d98c6116dc4b9b608e7483f1d6a8f62c84d7 (diff)
downloadprofani-tty-067bc690f28f32b59714579608a5f1469b1f5212.tar.gz
Adapt win_print_history() to work with muc too
Diffstat (limited to 'src/ui/window.c')
-rw-r--r--src/ui/window.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index fdf5d3f9..21f0f724 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1218,15 +1218,33 @@ win_print_outgoing(ProfWin *window, const char *show_char, const char *const id,
 }
 
 void
-win_print_history(ProfWin *window, GDateTime *timestamp, const char *const message)
+win_print_history(ProfWin *window, const ProfMessage *const message, gboolean is_muc)
 {
-    g_date_time_ref(timestamp);
+    g_date_time_ref(message->timestamp);
 
-    buffer_append(window->layout->buffer, "-", 0, timestamp, 0, THEME_TEXT_HISTORY, "", NULL, message, NULL, NULL);
-    _win_print_internal(window, "-", 0, timestamp, 0, THEME_TEXT_HISTORY, "", message, NULL);
+    int flags = 0;
+
+    // TODO: ProfMessage needs a 'type' field like we have in sql db. then we can know whether each message is a chat, muc, mucpm
+    char *display_name;
+    if (is_muc) {
+        display_name = strdup(message->jid->resourcepart);
+
+        char *muc_history_color = prefs_get_string(PREF_HISTORY_COLOR_MUC);
+        if (g_strcmp0(muc_history_color, "unanimous") == 0) {
+            flags = NO_COLOUR_FROM;
+        }
+        g_free(muc_history_color);
+    } else {
+        display_name = roster_get_msg_display_name(message->jid->barejid, message->jid->resourcepart);
+    }
+
+    buffer_append(window->layout->buffer, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, NULL, message->plain, NULL, NULL);
+    _win_print_internal(window, "-", 0, message->timestamp, flags, THEME_TEXT_HISTORY, display_name, message->plain, NULL);
+
+    free(display_name);
 
     inp_nonblocking(TRUE);
-    g_date_time_unref(timestamp);
+    g_date_time_unref(message->timestamp);
 }
 
 void