about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorHolger Weiß <holger@zedat.fu-berlin.de>2019-08-20 17:51:26 +0200
committerHolger Weiß <holger@zedat.fu-berlin.de>2019-08-20 17:51:26 +0200
commit3228ab47d341f477aad7a03093807d4324ec9f68 (patch)
treefc448c61f5e51c40fc218ba30ee5343ae77644ad
parentd8d6aa4b888a6a19133e5a48a32387451afdca44 (diff)
downloadprofani-tty-3228ab47d341f477aad7a03093807d4324ec9f68.tar.gz
Don't render (all) delayed messages as MUC history
Double-check that a <delay/> tag on a groupchat message was actually
added by the MUC service (rather than the sending client) before
assuming it was received from the MUC history.

Fixes #1173.
-rw-r--r--src/xmpp/message.c6
-rw-r--r--src/xmpp/stanza.c15
-rw-r--r--src/xmpp/stanza.h1
3 files changed, 20 insertions, 2 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index fd2b8e51..033a7a11 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -821,12 +821,14 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
     }
 
     // determine if the notifications happened whilst offline
-    message->timestamp = stanza_get_delay(stanza);
-    if (message->timestamp) {
+    gchar *from;
+    message->timestamp = stanza_get_delay_from(stanza, &from);
+    if (message->timestamp && g_strcmp0(jid->barejid, from) == 0) {
         sv_ev_room_history(message);
     } else {
         sv_ev_room_message(message);
     }
+    g_free(from);
 
 out:
     message_free(message);
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 2801ab53..a63cfef3 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -1174,6 +1174,12 @@ stanza_create_caps_sha1_from_query(xmpp_stanza_t *const query)
 GDateTime*
 stanza_get_delay(xmpp_stanza_t *const stanza)
 {
+    return stanza_get_delay_from(stanza, NULL);
+}
+
+GDateTime*
+stanza_get_delay_from(xmpp_stanza_t *const stanza, gchar **from)
+{
     GTimeVal utc_stamp;
     // first check for XEP-0203 delayed delivery
     xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
@@ -1185,6 +1191,9 @@ stanza_get_delay(xmpp_stanza_t *const stanza)
                 GDateTime *utc_datetime = g_date_time_new_from_timeval_utc(&utc_stamp);
                 GDateTime *local_datetime = g_date_time_to_local(utc_datetime);
                 g_date_time_unref(utc_datetime);
+                if (from) {
+                    *from = g_strdup(xmpp_stanza_get_attribute(delay, STANZA_ATTR_FROM));
+                }
                 return local_datetime;
             }
         }
@@ -1201,11 +1210,17 @@ stanza_get_delay(xmpp_stanza_t *const stanza)
                 GDateTime *utc_datetime = g_date_time_new_from_timeval_utc(&utc_stamp);
                 GDateTime *local_datetime = g_date_time_to_local(utc_datetime);
                 g_date_time_unref(utc_datetime);
+                if (from) {
+                    *from = g_strdup(xmpp_stanza_get_attribute(x, STANZA_ATTR_FROM));
+                }
                 return local_datetime;
             }
         }
     }
 
+    if (from) {
+        *from = NULL;
+    }
     return NULL;
 }
 
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index e5e17ba4..ad83d694 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -267,6 +267,7 @@ xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char *const
 gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
 
 GDateTime* stanza_get_delay(xmpp_stanza_t *const stanza);
+GDateTime* stanza_get_delay_from(xmpp_stanza_t *const stanza, gchar **from);
 
 gboolean stanza_is_muc_presence(xmpp_stanza_t *const stanza);
 gboolean stanza_is_muc_self_presence(xmpp_stanza_t *const stanza,