about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-01-30 11:46:19 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-01-30 11:46:19 +0100
commit8a9488245ba17e8040e85bdfbfd54463abeb99b3 (patch)
treede89a03321b4b8cf1d1978198e8576e4de6f30e4
parentbf2e09feee1697c570fcfb9e1e44a8ec991bd196 (diff)
downloadprofani-tty-8a9488245ba17e8040e85bdfbfd54463abeb99b3.tar.gz
muc: save oldest timestamp
So far we saved the timestamp which also had the `from`.
But we need this only to find out whether it's MUC history.

For displaying we should use the oldest delay timestamp.

Also in
https://github.com/profanity-im/profanity/commit/61f66966ddfe8ebd8bae26dd7ff92d777004edda#diff-4926fd4577a336bd3eb240f8104a5c5bL837
a error was introduced.

Before we saved the timestamp in all cases. And only if timestamp AND
from was given we went into MUC history case.
Normal timestamp saving was not done anymore only if it also had a from
attribute.

Regards https://github.com/profanity-im/profanity/issues/1254
-rw-r--r--src/xmpp/message.c9
-rw-r--r--src/xmpp/stanza.c31
-rw-r--r--src/xmpp/stanza.h1
3 files changed, 38 insertions, 3 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 18182e0c..1a97d9f1 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -831,14 +831,19 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
         message->plain = strdup(message->body);
     }
 
-    // determine if the notifications happened whilst offline
+    // determine if the notifications happened whilst offline (MUC history)
     message->timestamp = stanza_get_delay_from(stanza, jid->barejid);
     if (message->timestamp == NULL) {
         // checking the domainpart is a workaround for some prosody versions (gh#1190)
         message->timestamp = stanza_get_delay_from(stanza, jid->domainpart);
     }
 
-    if (message->timestamp) {
+    bool is_muc_history = message->timestamp != NULL;
+
+    // we want to display the oldest delay
+    message->timestamp = stanza_get_oldest_delay(stanza);
+
+    if (is_muc_history) {
         sv_ev_room_history(message);
     } else {
         sv_ev_room_message(message);
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index f793d035..e75bbd6e 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -1244,7 +1244,7 @@ _stanza_get_delay_timestamp_xep0091(xmpp_stanza_t *const x_stanza)
 GDateTime*
 stanza_get_delay_from(xmpp_stanza_t *const stanza, gchar *from)
 {
-    xmpp_stanza_t *delay;
+    xmpp_stanza_t *delay = NULL;
 
     // first check for XEP-0203 delayed delivery
     if (from) {
@@ -1272,6 +1272,35 @@ stanza_get_delay_from(xmpp_stanza_t *const stanza, gchar *from)
     return NULL;
 }
 
+GDateTime*
+stanza_get_oldest_delay(xmpp_stanza_t *const stanza)
+{
+    xmpp_stanza_t *child;
+    const char *child_name;
+    GDateTime* oldest;
+
+    for (child = xmpp_stanza_get_children(stanza); child; child = xmpp_stanza_get_next(child)) {
+
+        child_name = xmpp_stanza_get_name(child);
+
+        if (child_name && strcmp(child_name, STANZA_NAME_DELAY) == 0) {
+            GDateTime *tmp = _stanza_get_delay_timestamp_xep0203(stanza);
+
+            if (!oldest || g_date_time_compare(oldest, tmp) == 1)
+                oldest = tmp;
+        }
+
+        if (child_name && strcmp(child_name, STANZA_NAME_X) == 0) {
+            GDateTime *tmp = _stanza_get_delay_timestamp_xep0091(stanza);
+
+            if (!oldest || g_date_time_compare(oldest, tmp) == 1)
+                oldest = tmp;
+        }
+    }
+
+    return oldest;
+}
+
 char*
 stanza_get_status(xmpp_stanza_t *stanza, char *def)
 {
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 4b241fe2..04749fd2 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -271,6 +271,7 @@ 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);
+GDateTime* stanza_get_oldest_delay(xmpp_stanza_t *const stanza);
 
 gboolean stanza_is_muc_presence(xmpp_stanza_t *const stanza);
 gboolean stanza_is_muc_self_presence(xmpp_stanza_t *const stanza,