Philipp Hörist pushed to branch master at gajim / gajim

Commits:
7f0bcbb5 by Philipp Hörist at 2017-07-26T02:35:34+02:00
Correctly set stanza-id for received MAM messages

The gaol why we need to determine what ID should be used as stanza-id,
is so we can use the stanza-id in the future for deduplication.

Case we are the sender:

Either we look for a origin-id element, which we will include in the
Future in all messages we send, or until then the ID we set on the
message as attr.

Case we are the receiver:

If our server supports mam:2 we take the ID of the result element,
because mam:2 injects the archive ID live into every message we
receive. If we dont have mam:2 we fall back to the ID of the message
attr.

- - - - -


1 changed file:

- gajim/common/connection_handlers_events.py


Changes:

=====================================
gajim/common/connection_handlers_events.py
=====================================
--- a/gajim/common/connection_handlers_events.py
+++ b/gajim/common/connection_handlers_events.py
@@ -1069,10 +1069,34 @@ class MamMessageReceivedEvent(nec.NetworkIncomingEvent, 
HelperEvent):
             return False
 
         self.msgtxt = self.msg_.getTagData('body')
-        self.stanza_id = self.msg_.getID()
-        self.mam_id = self.result.getID()
         self.query_id = self.result.getAttr('queryid')
 
+        frm = self.msg_.getFrom()
+        to = self.msg_.getTo()
+
+        if frm.bareMatch(own_jid):
+            self.stanza_id = self.msg_.getTag('origin-id', 
+                                              namespace=nbxmpp.NS_SID)
+            if not self.stanza_id:
+                self.stanza_id = self.msg_.getID()
+
+            self.with_ = str(to)
+            self.direction = 'to'
+            self.resource = to.getResource()
+        else:
+            if self.result.getNamespace() == nbxmpp.NS_MAM_2:
+                self.stanza_id = self.result.getID()
+            else:
+                self.stanza_id = self.msg_.getID()
+
+            self.with_ = str(frm)
+            self.direction = 'from'
+            self.resource = frm.getResource()
+
+        if not self.stanza_id:
+            log.error('Could not retrieve stanza-id')
+            return False
+
         # Use timestamp provided by archive,
         # Fallback: Use timestamp provided by user and issue a warning
         delay = self.forwarded.getTag('delay', namespace=nbxmpp.NS_DELAY2)
@@ -1085,23 +1109,7 @@ class MamMessageReceivedEvent(nec.NetworkIncomingEvent, 
HelperEvent):
 
         self.timestamp = helpers.parse_delay(delay)
 
-        frm = self.msg_.getFrom()
-        to = self.msg_.getTo()
-
-        if not to or to.bareMatch(own_jid):
-            self.with_ = str(frm)
-            self.direction = 'from'
-            self.resource = frm.getResource()
-        else:
-            self.with_ = str(to)
-            self.direction = 'to'
-            self.resource = to.getResource()
-
-        log_message = \
-            'received: mam-message: ' \
-            'stanza id: {:15} - mam id: {:15} - query id: {}'.format(
-                self.stanza_id, self.mam_id, self.query_id)
-        log.debug(log_message)
+        log.debug('Received mam-message: stanza id: %s', self.stanza_id)
         return True
 
 class MamDecryptedMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/7f0bcbb5bf2e8faf4136767714d8d08912520683
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to