summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0461/stanza.py
diff options
context:
space:
mode:
authorLink Mauve <linkmauve@linkmauve.fr>2022-08-21 12:24:08 +0000
committerLink Mauve <linkmauve@linkmauve.fr>2022-08-21 12:24:08 +0000
commitc955cf1c66328e21d36ba1f3b8663efcf28d7ae9 (patch)
treecbf7b02c1b4de9c0b507e28b1f7ecdd7915e51a0 /slixmpp/plugins/xep_0461/stanza.py
parent6904ae63f5c7cab138558aa55bf126ffee7255c3 (diff)
parent450aaa7f86ddad0256bca4f772ccfff194afc123 (diff)
downloadslixmpp-c955cf1c66328e21d36ba1f3b8663efcf28d7ae9.tar.gz
slixmpp-c955cf1c66328e21d36ba1f3b8663efcf28d7ae9.tar.bz2
slixmpp-c955cf1c66328e21d36ba1f3b8663efcf28d7ae9.tar.xz
slixmpp-c955cf1c66328e21d36ba1f3b8663efcf28d7ae9.zip
Merge branch 'xep-0461' into 'master'
XEP-0461: Message Replies See merge request poezio/slixmpp!213
Diffstat (limited to 'slixmpp/plugins/xep_0461/stanza.py')
-rw-r--r--slixmpp/plugins/xep_0461/stanza.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/slixmpp/plugins/xep_0461/stanza.py b/slixmpp/plugins/xep_0461/stanza.py
new file mode 100644
index 00000000..b99b2745
--- /dev/null
+++ b/slixmpp/plugins/xep_0461/stanza.py
@@ -0,0 +1,47 @@
+from slixmpp.stanza import Message
+from slixmpp.xmlstream import ElementBase, register_stanza_plugin
+
+NS = "urn:xmpp:reply:0"
+
+
+class Reply(ElementBase):
+ namespace = NS
+ name = "reply"
+ plugin_attrib = "reply"
+ interfaces = {"id", "to"}
+
+
+class FeatureFallBack(ElementBase):
+ # should also be a multi attrib
+ namespace = "urn:xmpp:feature-fallback:0"
+ name = "fallback"
+ plugin_attrib = "feature_fallback"
+ interfaces = {"for"}
+
+ def get_stripped_body(self):
+ # only works for a single fallback_body attrib
+ start = self["fallback_body"]["start"]
+ end = self["fallback_body"]["end"]
+ body = self.parent()["body"]
+ try:
+ start = int(start)
+ end = int(end)
+ except ValueError:
+ return body
+ else:
+ return body[:start] + body[end:]
+
+
+class FallBackBody(ElementBase):
+ # According to https://xmpp.org/extensions/inbox/compatibility-fallback.html
+ # this should be a multi_attrib *but* since it's a protoXEP, we'll see...
+ namespace = FeatureFallBack.namespace
+ name = "body"
+ plugin_attrib = "fallback_body"
+ interfaces = {"start", "end"}
+
+
+def register_plugins():
+ register_stanza_plugin(Message, Reply)
+ register_stanza_plugin(Message, FeatureFallBack)
+ register_stanza_plugin(FeatureFallBack, FallBackBody)