about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server_events.c8
-rw-r--r--src/server_events.h2
-rw-r--r--src/ui/core.c27
-rw-r--r--src/ui/titlebar.c21
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/xmpp/message.c2
6 files changed, 38 insertions, 24 deletions
diff --git a/src/server_events.c b/src/server_events.c
index 34185ed5..a70a9a60 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -297,7 +297,7 @@ handle_incoming_private_message(char *fulljid, char *message)
 }
 
 void
-handle_incoming_message(char *barejid, char *message)
+handle_incoming_message(char *barejid, char *resource, char *message)
 {
 #ifdef HAVE_LIBOTR
     gboolean was_decrypted = FALSE;
@@ -336,7 +336,7 @@ handle_incoming_message(char *barejid, char *message)
         message_send_chat(barejid, otr_query_message);
     }
 
-    ui_incoming_msg(barejid, newmessage, NULL);
+    ui_incoming_msg(barejid, resource, newmessage, NULL);
 
     if (prefs_get_boolean(PREF_CHLOG)) {
         const char *jid = jabber_get_fulljid();
@@ -355,7 +355,7 @@ handle_incoming_message(char *barejid, char *message)
 
     otr_free_message(newmessage);
 #else
-    ui_incoming_msg(barejid, message, NULL);
+    ui_incoming_msg(barejid, resource, message, NULL);
 
     if (prefs_get_boolean(PREF_CHLOG)) {
         const char *jid = jabber_get_fulljid();
@@ -375,7 +375,7 @@ handle_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp)
 void
 handle_delayed_message(char *barejid, char *message, GTimeVal tv_stamp)
 {
-    ui_incoming_msg(barejid, message, &tv_stamp);
+    ui_incoming_msg(barejid, NULL, message, &tv_stamp);
 
     if (prefs_get_boolean(PREF_CHLOG)) {
         const char *jid = jabber_get_fulljid();
diff --git a/src/server_events.h b/src/server_events.h
index 32ac62f3..e803f945 100644
--- a/src/server_events.h
+++ b/src/server_events.h
@@ -69,7 +69,7 @@ void handle_room_role_list(const char * const from, const char * const role, GSL
 void handle_room_role_set_error(const char * const room, const char * const nick, const char * const role,
     const char * const error);
 void handle_room_kick_result_error(const char * const room, const char * const nick, const char * const error);
-void handle_incoming_message(char *barejid, char *message);
+void handle_incoming_message(char *barejid, char *resource, char *message);
 void handle_incoming_private_message(char *fulljid, char *message);
 void handle_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp);
 void handle_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp);
diff --git a/src/ui/core.c b/src/ui/core.c
index 84a157d7..08f45fb5 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -328,20 +328,25 @@ ui_get_current_chat(void)
 }
 
 void
-ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal *tv_stamp)
+ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp)
 {
     gboolean win_created = FALSE;
-    char *display_from = NULL;
+    GString *user = g_string_new("");
 
     PContact contact = roster_get_contact(barejid);
     if (contact != NULL) {
         if (p_contact_name(contact) != NULL) {
-            display_from = strdup(p_contact_name(contact));
+            g_string_append(user, p_contact_name(contact));
         } else {
-            display_from = strdup(barejid);
+            g_string_append(user, barejid);
         }
     } else {
-        display_from = strdup(barejid);
+        g_string_append(user,barejid);
+    }
+
+    if (resource) {
+        g_string_append(user, "/");
+        g_string_append(user, resource);
     }
 
     ProfChatWin *chatwin = wins_get_chat(barejid);
@@ -362,14 +367,14 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
 
     // currently viewing chat window with sender
     if (wins_is_current(window)) {
-        win_print_incoming_message(window, tv_stamp, display_from, message);
+        win_print_incoming_message(window, tv_stamp, user->str, 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(display_from, num);
+        cons_show_incoming_message(user->str, num);
 
         if (prefs_get_boolean(PREF_FLASH)) {
             flash();
@@ -388,7 +393,7 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
             }
         }
 
-        win_print_incoming_message(window, tv_stamp, display_from, message);
+        win_print_incoming_message(window, tv_stamp, user->str, message);
     }
 
     int ui_index = num;
@@ -404,14 +409,14 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
         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(display_from, ui_index, message);
+                notify_message(user->str, ui_index, message);
             } else {
-                notify_message(display_from, ui_index, NULL);
+                notify_message(user->str, ui_index, NULL);
             }
         }
     }
 
-    free(display_from);
+    g_string_free(user, TRUE);
 }
 
 void
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index 368309e9..21e904ac 100644
--- a/src/ui/titlebar.c
+++ b/src/ui/titlebar.c
@@ -47,6 +47,7 @@
 #include "ui/windows.h"
 #include "ui/window.h"
 #include "roster_list.h"
+#include "chat_session.h"
 
 static WINDOW *win;
 static contact_presence_t current_presence;
@@ -307,9 +308,17 @@ static void
 _show_contact_presence(ProfChatWin *chatwin)
 {
     int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
-    if (chatwin && chatwin->resource_override) {
+    char *resource = NULL;
+
+    ChatSession *session = chat_session_get(chatwin->barejid);
+    if (chatwin->resource_override) {
+        resource = chatwin->resource_override;
+    } else if (session && session->resource) {
+        resource = session->resource;
+    }
+    if (resource) {
         wprintw(win, "/");
-        wprintw(win, chatwin->resource_override);
+        wprintw(win, resource);
     }
 
     if (prefs_get_boolean(PREF_PRESENCE)) {
@@ -318,10 +327,10 @@ _show_contact_presence(ProfChatWin *chatwin)
 
         PContact contact = roster_get_contact(chatwin->barejid);
         if (contact) {
-            if (chatwin && chatwin->resource_override) {
-                Resource *resource = p_contact_get_resource(contact, chatwin->resource_override);
-                if (resource) {
-                    presence = string_from_resource_presence(resource->presence);
+            if (resource) {
+                Resource *resourcep = p_contact_get_resource(contact, resource);
+                if (resourcep) {
+                    presence = string_from_resource_presence(resourcep->presence);
                 }
             } else {
                 presence = p_contact_presence(contact);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index e7b46766..08d67ec6 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -116,7 +116,7 @@ void ui_handle_stanza(const char * const msg);
 
 // ui events
 void ui_contact_typing(const char * const from);
-void ui_incoming_msg(const char * const from, const char * const message, GTimeVal *tv_stamp);
+void ui_incoming_msg(const char * const from, const char * const resource,  const char * const message, GTimeVal *tv_stamp);
 void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp);
 
 void ui_disconnected(void);
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 4474c7ad..0d88603a 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -499,7 +499,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
                 if (delayed) {
                     handle_delayed_message(jid->barejid, message, tv_stamp);
                 } else {
-                    handle_incoming_message(jid->barejid, message);
+                    handle_incoming_message(jid->barejid, jid->resourcepart, message);
                 }
                 xmpp_free(ctx, message);
             }