Coverage for slidge/slixfix/xep_0424/retraction.py: 64%
33 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-07 05:11 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-07 05:11 +0000
1# Slixmpp: The Slick XMPP Library
2# Copyright (C) 2020 Mathieu Pasquet <mathieui@mathieui.net>
3# This file is part of Slixmpp.
4# See the file LICENSE for copying permission.
5from typing import Optional
7from slixmpp import JID, Message
8from slixmpp.exceptions import IqError, IqTimeout
9from slixmpp.plugins import BasePlugin
10from slixmpp.xmlstream.handler import Callback
11from slixmpp.xmlstream.matcher import StanzaPath
13from . import stanza
15DEFAULT_FALLBACK = (
16 "This person attempted to retract a previous message, but your client "
17 "does not support it."
18)
21class XEP_0424(BasePlugin):
22 """XEP-0424: Message Retraction"""
24 name = "xep_0424"
25 description = "XEP-0424: Message Retraction (fix Slidge)"
26 dependencies = {"xep_0422", "xep_0030", "xep_0359", "xep_0428", "xep_0334"}
27 stanza = stanza
28 namespace = stanza.NS
30 def plugin_init(self) -> None:
31 stanza.register_plugins()
32 self.xmpp.register_handler(
33 Callback(
34 "Message Retracted",
35 StanzaPath("message/retract"),
36 self._handle_retract_message,
37 )
38 )
40 def session_bind(self, jid):
41 self.xmpp.plugin["xep_0030"].add_feature(feature=stanza.NS)
43 def plugin_end(self):
44 self.xmpp.plugin["xep_0030"].del_feature(feature=stanza.NS)
46 def _handle_retract_message(self, message: Message):
47 self.xmpp.event("message_retract", message)
49 def send_retraction(
50 self,
51 mto: JID,
52 id: str,
53 mtype: str = "chat",
54 include_fallback: bool = True,
55 fallback_text: Optional[str] = None,
56 *,
57 mfrom: Optional[JID] = None
58 ):
59 """
60 Send a message retraction
62 :param JID mto: The JID to retract the message from
63 :param str id: Message ID to retract
64 :param str mtype: Message type
65 :param bool include_fallback: Whether to include a fallback body
66 :param Optional[str] fallback_text: The content of the fallback
67 body. None will set the default value.
68 """
69 if fallback_text is None:
70 fallback_text = DEFAULT_FALLBACK
71 msg = self.xmpp.make_message(mto=mto, mtype=mtype, mfrom=mfrom)
72 if include_fallback:
73 msg["body"] = fallback_text
74 msg.enable("fallback")
75 msg["retract"]["id"] = id
76 msg.enable("store")
77 msg.send()