about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jabber.c18
-rw-r--r--src/stanza.c32
-rw-r--r--src/stanza.h4
3 files changed, 41 insertions, 13 deletions
diff --git a/src/jabber.c b/src/jabber.c
index 4d2fcbbb..e0b7a67c 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -550,10 +550,11 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
     }
 
     // determine if the notifications happened whilst offline
-    xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
+    GTimeVal tv_stamp;
+    gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
 
     // deal with chat states if recipient supports them
-    if (recipient_supports && (delay == NULL)) {
+    if (recipient_supports && (!delayed)) {
         if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
             if (prefs_get_notify_typing() || prefs_get_intype()) {
                 prof_handle_typing(jid);
@@ -573,17 +574,8 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
     xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
     if (body != NULL) {
         char *message = xmpp_stanza_get_text(body);
-        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_delayed_message(jid, message, tv_stamp, priv);
-                }
-            } else {
-                log_error("Couldn't parse datetime string of historic message: %s", utc_stamp);
-            }
+        if (delayed) {
+            prof_handle_delayed_message(jid, message, tv_stamp, priv);
         } else {
             prof_handle_incoming_message(jid, message, priv);
         }
diff --git a/src/stanza.c b/src/stanza.c
index 788aea88..41d80d10 100644
--- a/src/stanza.c
+++ b/src/stanza.c
@@ -22,6 +22,7 @@
 
 #include <string.h>
 
+#include <glib.h>
 #include <strophe.h>
 
 #include "common.h"
@@ -193,3 +194,34 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx)
 
     return iq;
 }
+
+gboolean
+stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp)
+{
+    // first check for XEP-0203 delayed delivery
+    xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
+    if (delay != NULL) {
+        char *xmlns = xmpp_stanza_get_attribute(delay, STANZA_ATTR_XMLNS);
+        if ((xmlns != NULL) && (strcmp(xmlns, "urn:xmpp:delay") == 0)) {
+            char *stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP);
+            if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) {
+                return TRUE;
+            }
+        }
+    }
+
+    // otherwise check for XEP-0091 legacy delayed delivery
+    // stanp format : CCYYMMDDThh:mm:ss
+    xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X);
+    if (x != NULL) {
+        char *xmlns = xmpp_stanza_get_attribute(x, STANZA_ATTR_XMLNS);
+        if ((xmlns != NULL) && (strcmp(xmlns, "jabber:x:delay") == 0)) {
+            char *stamp = xmpp_stanza_get_attribute(x, STANZA_ATTR_STAMP);
+            if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) {
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
+}
diff --git a/src/stanza.h b/src/stanza.h
index 442741fd..7fbe3d4d 100644
--- a/src/stanza.h
+++ b/src/stanza.h
@@ -23,6 +23,7 @@
 #ifndef STANZA_H
 #define STANZA_H
 
+#include <glib.h>
 #include <strophe.h>
 
 #define STANZA_NAME_ACTIVE "active"
@@ -62,6 +63,7 @@
 #define STANZA_ATTR_JID "jid"
 #define STANZA_ATTR_NAME "name"
 #define STANZA_ATTR_SUBSCRIPTION "subscription"
+#define STANZA_ATTR_XMLNS "xmlns"
 
 #define STANZA_TEXT_AWAY "away"
 #define STANZA_TEXT_DND "dnd"
@@ -94,4 +96,6 @@ xmpp_stanza_t* stanza_create_ping_iq(xmpp_ctx_t *ctx);
 
 gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
 
+gboolean stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp);
+
 #endif