about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/roster_list.c28
-rw-r--r--src/roster_list.h1
-rw-r--r--src/ui/core.c32
3 files changed, 37 insertions, 24 deletions
diff --git a/src/roster_list.c b/src/roster_list.c
index ad1864f1..a320ab2b 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -42,6 +42,7 @@
 #include "contact.h"
 #include "jid.h"
 #include "tools/autocomplete.h"
+#include "config/preferences.h"
 
 // nicknames
 static Autocomplete name_ac;
@@ -116,6 +117,33 @@ roster_get_contact(const char * const barejid)
     return contact;
 }
 
+char *
+roster_get_msg_display_name(const char * const barejid, const char * const resource)
+{
+    GString *result = g_string_new("");
+
+    PContact contact = roster_get_contact(barejid);
+    if (contact != NULL) {
+        if (p_contact_name(contact) != NULL) {
+            g_string_append(result, p_contact_name(contact));
+        } else {
+            g_string_append(result, barejid);
+        }
+    } else {
+        g_string_append(result, barejid);
+    }
+
+    if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
+        g_string_append(result, "/");
+        g_string_append(result, resource);
+    }
+
+    char *result_str = result->str;
+    g_string_free(result, FALSE);
+
+    return result_str;
+}
+
 gboolean
 roster_contact_offline(const char * const barejid,
     const char * const resource, const char * const status)
diff --git a/src/roster_list.h b/src/roster_list.h
index 6c66d142..4417c763 100644
--- a/src/roster_list.h
+++ b/src/roster_list.h
@@ -67,5 +67,6 @@ char * roster_group_autocomplete(const char * const search_str);
 char * roster_barejid_autocomplete(const char * const search_str);
 GSList * roster_get_contacts_by_presence(const char * const presence);
 GSList * roster_get_nogroup(void);
+char * roster_get_msg_display_name(const char * const barejid, const char * const resource);
 
 #endif
diff --git a/src/ui/core.c b/src/ui/core.c
index 9deca664..fb1a4219 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -389,23 +389,6 @@ void
 ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp)
 {
     gboolean win_created = FALSE;
-    GString *user = g_string_new("");
-
-    PContact contact = roster_get_contact(barejid);
-    if (contact != NULL) {
-        if (p_contact_name(contact) != NULL) {
-            g_string_append(user, p_contact_name(contact));
-        } else {
-            g_string_append(user, barejid);
-        }
-    } else {
-        g_string_append(user, barejid);
-    }
-
-    if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
-        g_string_append(user, "/");
-        g_string_append(user, resource);
-    }
 
     ProfChatWin *chatwin = wins_get_chat(barejid);
     if (chatwin == NULL) {
@@ -415,19 +398,20 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
     }
 
     ProfWin *window = (ProfWin*) chatwin;
-
     int num = wins_get_num(window);
 
+    char *display_name = roster_get_msg_display_name(barejid, resource);
+
     // currently viewing chat window with sender
     if (wins_is_current(window)) {
-        win_print_incoming_message(window, tv_stamp, user->str, message);
+        win_print_incoming_message(window, tv_stamp, display_name, message);
         title_bar_set_typing(FALSE);
         status_bar_active(num);
 
     // not currently viewing chat window with sender
     } else {
         status_bar_new(num);
-        cons_show_incoming_message(user->str, num);
+        cons_show_incoming_message(display_name, num);
 
         if (prefs_get_boolean(PREF_FLASH)) {
             flash();
@@ -446,7 +430,7 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
             }
         }
 
-        win_print_incoming_message(window, tv_stamp, user->str, message);
+        win_print_incoming_message(window, tv_stamp, display_name, message);
     }
 
     int ui_index = num;
@@ -462,14 +446,14 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c
         gboolean is_current = wins_is_current(window);
         if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) {
             if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) {
-                notify_message(user->str, ui_index, message);
+                notify_message(display_name, ui_index, message);
             } else {
-                notify_message(user->str, ui_index, NULL);
+                notify_message(display_name, ui_index, NULL);
             }
         }
     }
 
-    g_string_free(user, TRUE);
+    free(display_name);
 }
 
 void