about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-11-12 23:26:09 +0000
committerJames Booth <boothj5@gmail.com>2012-11-12 23:26:09 +0000
commit13689a1f8453c3ffed93ac2fd9378129686ef4a1 (patch)
tree7d97462ed8315b0bbcad5903ed3d52a513e78da0 /src
parentdf094a7d2c2dbbee7b3ab13fd0bd82c0ebbe33cd (diff)
downloadprofani-tty-13689a1f8453c3ffed93ac2fd9378129686ef4a1.tar.gz
Allow incoming private messages from chat rooms
Diffstat (limited to 'src')
-rw-r--r--src/jabber.c25
-rw-r--r--src/windows.c22
2 files changed, 27 insertions, 20 deletions
diff --git a/src/jabber.c b/src/jabber.c
index bb691a42..44e92da4 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -466,6 +466,15 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
     char from_cpy[strlen(from) + 1];
     strcpy(from_cpy, from);
     char *short_from = strtok(from_cpy, "/");
+    char *jid = NULL;
+
+    // private message from chat room use full jid (room/nick)
+    if (room_is_active(short_from)) {
+        jid = strdup(from);
+    // standard chat message, use jid without resource
+    } else {
+        jid = strdup(short_from);
+    }
 
     // determine chatstate support of recipient
     gboolean recipient_supports = FALSE;
@@ -474,10 +483,10 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
     }
 
     // create or update chat session
-    if (!chat_session_exists(short_from)) {
-        chat_session_start(short_from, recipient_supports);
+    if (!chat_session_exists(jid)) {
+        chat_session_start(jid, recipient_supports);
     } else {
-        chat_session_set_recipient_supports(short_from, recipient_supports);
+        chat_session_set_recipient_supports(jid, recipient_supports);
     }
 
     // determine if the notifications happened whilst offline
@@ -487,10 +496,10 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
     if (recipient_supports && (delay == NULL)) {
         if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
             if (prefs_get_notify_typing() || prefs_get_intype()) {
-                prof_handle_typing(short_from);
+                prof_handle_typing(jid);
             }
         } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) {
-            prof_handle_gone(short_from);
+            prof_handle_gone(jid);
         } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) {
             // do something
         } else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL) {
@@ -510,16 +519,18 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
 
             if (g_time_val_from_iso8601(utc_stamp, &tv_stamp)) {
                 if (message != NULL) {
-                    prof_handle_delayed_message(short_from, message, tv_stamp);
+                    prof_handle_delayed_message(jid, message, tv_stamp);
                 }
             } else {
                 log_error("Couldn't parse datetime string of historic message: %s", utc_stamp);
             }
         } else {
-            prof_handle_incoming_message(short_from, message);
+            prof_handle_incoming_message(jid, message);
         }
     }
 
+    g_free(jid);
+
     return 1;
 }
 
diff --git a/src/windows.c b/src/windows.c
index f47304e1..2f11c04c 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -303,13 +303,9 @@ void
 win_show_incomming_msg(const char * const from, const char * const message,
     GTimeVal *tv_stamp)
 {
-    char from_cpy[strlen(from) + 1];
-    strcpy(from_cpy, from);
-    char *short_from = strtok(from_cpy, "/");
-
-    int win_index = _find_prof_win_index(short_from);
+    int win_index = _find_prof_win_index(from);
     if (win_index == NUM_WINS)
-        win_index = _new_prof_win(short_from, WIN_CHAT);
+        win_index = _new_prof_win(from, WIN_CHAT);
 
     WINDOW *win = _wins[win_index].win;
 
@@ -327,12 +323,12 @@ win_show_incomming_msg(const char * const from, const char * const message,
 
         if (strncmp(message, "/me ", 4) == 0) {
             wattron(win, COLOUR_ONLINE);
-            wprintw(win, "*%s ", short_from);
+            wprintw(win, "*%s ", from);
             wprintw(win, message + 4);
             wprintw(win, "\n");
             wattroff(win, COLOUR_ONLINE);
         } else {
-            _win_show_user(win, short_from, 1);
+            _win_show_user(win, from, 1);
             _win_show_message(win, message);
         }
         title_bar_set_typing(FALSE);
@@ -343,13 +339,13 @@ win_show_incomming_msg(const char * const from, const char * const message,
     // not currently viewing chat window with sender
     } else {
         status_bar_new(win_index);
-        _cons_show_incoming_message(short_from, win_index);
+        _cons_show_incoming_message(from, win_index);
         if (prefs_get_flash())
             flash();
 
         _wins[win_index].unread++;
         if (prefs_get_chlog() && prefs_get_history()) {
-            _win_show_history(win, win_index, short_from);
+            _win_show_history(win, win_index, from);
         }
 
         if (tv_stamp == NULL) {
@@ -364,12 +360,12 @@ win_show_incomming_msg(const char * const from, const char * const message,
 
         if (strncmp(message, "/me ", 4) == 0) {
             wattron(win, COLOUR_ONLINE);
-            wprintw(win, "*%s ", short_from);
+            wprintw(win, "*%s ", from);
             wprintw(win, message + 4);
             wprintw(win, "\n");
             wattroff(win, COLOUR_ONLINE);
         } else {
-            _win_show_user(win, short_from, 1);
+            _win_show_user(win, from, 1);
             _win_show_message(win, message);
         }
     }
@@ -378,7 +374,7 @@ win_show_incomming_msg(const char * const from, const char * const message,
         beep();
 #ifdef HAVE_LIBNOTIFY
     if (prefs_get_notify_message())
-        _win_notify_message(short_from);
+        _win_notify_message(from);
 #endif
 }