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/7f0bcbb5bf2e8faf4136767714d8d08912…
Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
0264a744 by Philipp Hörist at 2017-07-25T02:25:24+02:00
Make better use of Protocol classes
Return always a xmpp aware Protocol instance on getTag().
Otherwise we would fall back to a xmpp unaware Node instance.
Return a Message instance in case the tag name is 'message'
- - - - -
0f51792d by Philipp Hörist at 2017-07-25T02:25:42+02:00
add getJid() attribute method
- - - - -
1 changed file:
- nbxmpp/protocol.py
Changes:
=====================================
nbxmpp/protocol.py
=====================================
--- a/nbxmpp/protocol.py
+++ b/nbxmpp/protocol.py
@@ -834,6 +834,15 @@ class Protocol(Node):
return self.timestamp
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
+ def getJid(self):
+ """
+ Return the value of the 'jid' attribute
+ """
+ attr = self.getAttr('jid')
+ if attr:
+ return JID(attr)
+ return attr
+
def getID(self):
"""
Return the value of the 'id' attribute
@@ -946,6 +955,16 @@ class Protocol(Node):
props.append(prop)
return props
+ def getTag(self, name, attrs=None, namespace=None):
+ """
+ Return at least a Protocol instance, so we dont fall back to simplexml level
+ """
+ tag = super().getTag(name, attrs, namespace)
+ if not tag:
+ return None
+
+ return Protocol(node=tag)
+
def __setitem__(self, item, val):
"""
Set the item 'item' to the value 'val'
@@ -1073,6 +1092,18 @@ class Message(Protocol):
attrs.append(child.getAttr('code'))
return attrs
+ def getTag(self, name, attrs=None, namespace=None):
+ """
+ Return Message instance, fallback to Protocol
+ """
+ tag = super().getTag(name, attrs, namespace)
+ if not tag:
+ return tag
+
+ if name == 'message':
+ return Message(node=tag)
+ return tag
+
class Presence(Protocol):
def __init__(self, to=None, typ=None, priority=None, show=None, status=None,
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/4ce3016001112f7cc2c579bc2…