summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slixmpp/plugins/__init__.py1
-rw-r--r--slixmpp/plugins/xep_0424/__init__.py13
-rw-r--r--slixmpp/plugins/xep_0424/retraction.py62
-rw-r--r--slixmpp/plugins/xep_0424/stanza.py38
4 files changed, 114 insertions, 0 deletions
diff --git a/slixmpp/plugins/__init__.py b/slixmpp/plugins/__init__.py
index 0bc62676..61e7a995 100644
--- a/slixmpp/plugins/__init__.py
+++ b/slixmpp/plugins/__init__.py
@@ -95,6 +95,7 @@ __all__ = [
'xep_0405', # MIX-PAM
'xep_0421', # Anonymous unique occupant identifiers for MUCs
'xep_0422', # Message Fastening
+ 'xep_0424', # Message Retraction
'xep_0428', # Message Fallback
'xep_0444', # Message Reactions
]
diff --git a/slixmpp/plugins/xep_0424/__init__.py b/slixmpp/plugins/xep_0424/__init__.py
new file mode 100644
index 00000000..0e5dfce1
--- /dev/null
+++ b/slixmpp/plugins/xep_0424/__init__.py
@@ -0,0 +1,13 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp.plugins.base import register_plugin
+from slixmpp.plugins.xep_0424.stanza import *
+from slixmpp.plugins.xep_0424.retraction import XEP_0424
+
+register_plugin(XEP_0424)
diff --git a/slixmpp/plugins/xep_0424/retraction.py b/slixmpp/plugins/xep_0424/retraction.py
new file mode 100644
index 00000000..5425a61f
--- /dev/null
+++ b/slixmpp/plugins/xep_0424/retraction.py
@@ -0,0 +1,62 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+from typing import Optional
+
+from slixmpp import JID, Message
+from slixmpp.exceptions import IqError, IqTimeout
+from slixmpp.plugins import BasePlugin
+from slixmpp.plugins.xep_0424 import stanza
+
+
+DEFAULT_FALLBACK = (
+ 'This person attempted to retract a previous message, but your client '
+ 'does not support it.'
+)
+
+
+class XEP_0424(BasePlugin):
+ '''XEP-0424: Message Retraction'''
+
+ name = 'xep_0424'
+ description = 'Message Retraction'
+ dependencies = {'xep_0422', 'xep_0030', 'xep_0359', 'xep_0428', 'xep_0334'}
+ stanza = stanza
+ namespace = stanza.NS
+
+ def plugin_init(self) -> None:
+ stanza.register_plugins()
+
+ def session_bind(self, jid):
+ self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
+
+ def plugin_end(self):
+ self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
+
+ def send_retraction(self, mto: JID, id: str, mtype: str = 'chat',
+ include_fallback: bool = True,
+ fallback_text: Optional[str] = None, *,
+ mfrom: Optional[JID] = None):
+ """
+ Send a message retraction
+ :param JID mto: The JID to retract the message from
+ :param str id: Message ID to retract
+ :param str mtype: Message type
+ :param bool include_fallback: Whether to include a fallback body
+ :param Optional[str] fallback_text: The contet of the fallback
+ body. None will set the default value.
+ """
+ if fallback_text is None:
+ fallback_text = DEFAULT_FALLBACK
+ msg = self.xmpp.make_message(mto=mto, mtype=mtype, mfrom=mfrom)
+ if include_fallback:
+ msg['body'] = fallback_text
+ msg.enable('fallback')
+ msg['apply_to']['id'] = id
+ msg['apply_to'].enable('retract')
+ msg.enable('store')
+ msg.send()
diff --git a/slixmpp/plugins/xep_0424/stanza.py b/slixmpp/plugins/xep_0424/stanza.py
new file mode 100644
index 00000000..c55af08c
--- /dev/null
+++ b/slixmpp/plugins/xep_0424/stanza.py
@@ -0,0 +1,38 @@
+"""
+ Slixmpp: The Slick XMPP Library
+ Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
+ This file is part of Slixmpp.
+
+ See the file LICENSE for copying permissio
+"""
+
+from slixmpp.stanza import Message
+from slixmpp.xmlstream import (
+ ElementBase,
+ register_stanza_plugin,
+)
+from slixmpp.plugins.xep_0422.stanza import ApplyTo
+from slixmpp.plugins.xep_0359 import OriginID
+
+
+NS = 'urn:xmpp:message-retract:0'
+
+
+class Retract(ElementBase):
+ namespace = NS
+ name = 'retract'
+ plugin_attrib = 'retract'
+
+
+class Retracted(ElementBase):
+ namespace = NS
+ name = 'retracted'
+ plugin_attrib = 'retracted'
+ interfaces = {'stamp'}
+
+
+def register_plugins():
+ register_stanza_plugin(ApplyTo, Retract)
+ register_stanza_plugin(Message, Retracted)
+
+ register_stanza_plugin(Retracted, OriginID)