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.
This commit is contained in:
Philipp Hörist 2017-07-26 02:35:34 +02:00
parent 3a4a97dbf8
commit 7f0bcbb5bf
1 changed files with 27 additions and 19 deletions

View File

@ -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):