about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/jabber.c28
-rw-r--r--src/stanza.c16
-rw-r--r--src/stanza.h3
3 files changed, 25 insertions, 22 deletions
diff --git a/src/jabber.c b/src/jabber.c
index b55a4019..42051ffb 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -458,29 +458,17 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
         return 1;
     }
 
-    xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
+    // determine if the notifications happened whilst offline
+    GTimeVal tv_stamp;
+    gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
     xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
 
+    // check for and deal with message
     if (body != NULL) {
-        message = xmpp_stanza_get_text(body);
-    }
-
-    // handle chat room history
-    if (delay != NULL) {
-        char *utc_stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP);
-        GTimeVal tv_stamp;
-
-        if (g_time_val_from_iso8601(utc_stamp, &tv_stamp)) {
-            if (message != NULL) {
-                prof_handle_room_history(room, nick, tv_stamp, message);
-            }
+        char *message = xmpp_stanza_get_text(body);
+        if (delayed) {
+            prof_handle_room_history(room, nick, tv_stamp, message);
         } else {
-            log_error("Couldn't parse datetime string receiving room history: %s", utc_stamp);
-        }
-
-    // handle regular chat room message
-    } else {
-        if (message != NULL) {
             prof_handle_room_message(room, nick, message);
         }
     }
@@ -707,7 +695,7 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza)
     }
 
     // handle self presence
-    if (stanza_is_muc_self_presence(stanza)) {
+    if (stanza_is_muc_self_presence(stanza, jabber_get_jid())) {
         char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
         gboolean nick_change = stanza_is_room_nick_change(stanza);
 
diff --git a/src/stanza.c b/src/stanza.c
index 282adc99..cbd1ae0d 100644
--- a/src/stanza.c
+++ b/src/stanza.c
@@ -238,7 +238,8 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp)
 }
 
 gboolean
-stanza_is_muc_self_presence(xmpp_stanza_t * const stanza)
+stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
+    const char * const self_jid)
 {
     if (stanza == NULL) {
         return FALSE;
@@ -276,6 +277,19 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza)
         x_children = xmpp_stanza_get_next(x_children);
     }
 
+    // for older server that don't send status 110
+    while (x_children != NULL) {
+        if (strcmp(xmpp_stanza_get_name(x_children), STANZA_NAME_ITEM) == 0) {
+            char *jid = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_JID);
+            if (jid != NULL) {
+                if (g_str_has_prefix(jid, self_jid)) {
+                    return TRUE;
+                }
+            }
+        }
+        x_children = xmpp_stanza_get_next(x_children);
+    }
+
     return FALSE;
 }
 
diff --git a/src/stanza.h b/src/stanza.h
index faea0fdd..9992c659 100644
--- a/src/stanza.h
+++ b/src/stanza.h
@@ -105,7 +105,8 @@ gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
 
 gboolean stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp);
 
-gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza);
+gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
+    const char * const self_jid);
 gboolean stanza_is_room_nick_change(xmpp_stanza_t * const stanza);
 
 char* stanza_get_new_nick(xmpp_stanza_t * const stanza);