summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Buquet <pep@bouah.net>2019-08-23 17:10:42 +0200
committerMaxime Buquet <pep@bouah.net>2019-08-23 17:10:42 +0200
commit9fe20a4056423cf3e457abb7c884781563d44561 (patch)
tree1ec0817e34856e7a102e4e7b973466b05b29c5c8
parent540ff894275023da343d8c7565ee46d6e41ccbfc (diff)
parent3253d34c0a3088c98e7d54bc5f38c118bcbfde2d (diff)
downloadslixmpp-9fe20a4056423cf3e457abb7c884781563d44561.tar.gz
slixmpp-9fe20a4056423cf3e457abb7c884781563d44561.tar.bz2
slixmpp-9fe20a4056423cf3e457abb7c884781563d44561.tar.xz
slixmpp-9fe20a4056423cf3e457abb7c884781563d44561.zip
Merge branch 'origin-id' into 'master'
Implement Origin-id (XEP-0359) See merge request poezio/slixmpp!21
-rw-r--r--slixmpp/basexmpp.py3
-rw-r--r--slixmpp/stanza/message.py44
2 files changed, 47 insertions, 0 deletions
diff --git a/slixmpp/basexmpp.py b/slixmpp/basexmpp.py
index 146b6086..02c0b21c 100644
--- a/slixmpp/basexmpp.py
+++ b/slixmpp/basexmpp.py
@@ -111,6 +111,9 @@ class BaseXMPP(XMLStream):
#: outgoing messages an ID.
self.use_presence_ids = True
+ #: XEP-0359 <origin-id/> tag that gets added to <message/> stanzas.
+ self.use_origin_id = True
+
#: The API registry is a way to process callbacks based on
#: JID+node combinations. Each callback in the registry is
#: marked with:
diff --git a/slixmpp/stanza/message.py b/slixmpp/stanza/message.py
index f5813eaf..716d48e0 100644
--- a/slixmpp/stanza/message.py
+++ b/slixmpp/stanza/message.py
@@ -10,6 +10,9 @@ from slixmpp.stanza.rootstanza import RootStanza
from slixmpp.xmlstream import StanzaBase, ET
+ORIGIN_NAME = '{urn:xmpp:sid:0}origin-id'
+
+
class Message(RootStanza):
"""
@@ -63,6 +66,8 @@ class Message(RootStanza):
if self['id'] == '':
if self.stream is not None and self.stream.use_message_ids:
self['id'] = self.stream.new_id()
+ else:
+ del self['origin_id']
def get_type(self):
"""
@@ -76,6 +81,43 @@ class Message(RootStanza):
"""
return self._get_attr('type', 'normal')
+ def get_id(self):
+ return self._get_attr('id') or ''
+
+ def get_origin_id(self):
+ sub = self.xml.find(ORIGIN_NAME)
+ if sub is not None:
+ return sub.attrib.get('id') or ''
+ return ''
+
+ def _set_ids(self, value) -> None:
+ if value is None or value == '':
+ return None
+
+ self.xml.attrib['id'] = value
+
+ if not self.stream.use_origin_id:
+ return None
+
+ sub = self.xml.find(ORIGIN_NAME)
+ if sub is not None:
+ sub.attrib['id'] = value
+ else:
+ sub = ET.Element(ORIGIN_NAME)
+ sub.attrib['id'] = value
+ self.xml.append(sub)
+
+ def set_id(self, value):
+ return self._set_ids(value)
+
+ def set_origin_id(self, value: str):
+ return self._set_ids(value)
+
+ def del_origin_id(self):
+ sub = self.xml.find(ORIGIN_NAME)
+ if sub is not None:
+ self.xml.remove(sub)
+
def get_parent_thread(self):
"""Return the message thread's parent thread.
@@ -140,6 +182,8 @@ class Message(RootStanza):
new_message['parent_thread'] = self['parent_thread']
del new_message['id']
+ if self.stream is not None and self.stream.use_message_ids:
+ new_message['id'] = self.stream.new_id()
if body is not None:
new_message['body'] = body