XEP-0424: Message Retraction
This commit is contained in:
parent
54d556280a
commit
c4ca15a040
4 changed files with 114 additions and 0 deletions
|
@ -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
|
||||
]
|
||||
|
|
13
slixmpp/plugins/xep_0424/__init__.py
Normal file
13
slixmpp/plugins/xep_0424/__init__.py
Normal file
|
@ -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)
|
62
slixmpp/plugins/xep_0424/retraction.py
Normal file
62
slixmpp/plugins/xep_0424/retraction.py
Normal file
|
@ -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()
|
38
slixmpp/plugins/xep_0424/stanza.py
Normal file
38
slixmpp/plugins/xep_0424/stanza.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue