Merge branch 'retraction-event' into 'master'

XEP-0424: Add an event for message retraction

See merge request poezio/slixmpp!87
This commit is contained in:
Link Mauve 2020-12-12 14:45:49 +01:00
commit 71888b24a6
2 changed files with 12 additions and 1 deletions

View File

@ -22,7 +22,7 @@ class TestRetract(SlixIntegration):
id='toto', id='toto',
fallback_text='Twas a mistake', fallback_text='Twas a mistake',
) )
msg = await self.clients[1].wait_until('message') msg = await self.clients[1].wait_until('message_retract')
self.assertEqual(msg['apply_to']['id'], 'toto') self.assertEqual(msg['apply_to']['id'], 'toto')
self.assertTrue(msg['apply_to']['retract']) self.assertTrue(msg['apply_to']['retract'])

View File

@ -9,6 +9,8 @@ from typing import Optional
from slixmpp import JID, Message from slixmpp import JID, Message
from slixmpp.exceptions import IqError, IqTimeout from slixmpp.exceptions import IqError, IqTimeout
from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.xmlstream.handler import Callback
from slixmpp.plugins import BasePlugin from slixmpp.plugins import BasePlugin
from slixmpp.plugins.xep_0424 import stanza from slixmpp.plugins.xep_0424 import stanza
@ -30,6 +32,11 @@ class XEP_0424(BasePlugin):
def plugin_init(self) -> None: def plugin_init(self) -> None:
stanza.register_plugins() stanza.register_plugins()
self.xmpp.register_handler(Callback(
"Message Retracted",
StanzaPath("message/apply_to/retract"),
self._handle_retract_message,
))
def session_bind(self, jid): def session_bind(self, jid):
self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS) self.xmpp.plugin['xep_0030'].add_feature(feature=stanza.NS)
@ -37,6 +44,10 @@ class XEP_0424(BasePlugin):
def plugin_end(self): def plugin_end(self):
self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS) self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
def _handle_retract_message(self, message: Message):
if message['type'] != 'groupchat':
self.xmpp.event('message_retract', message)
def send_retraction(self, mto: JID, id: str, mtype: str = 'chat', def send_retraction(self, mto: JID, id: str, mtype: str = 'chat',
include_fallback: bool = True, include_fallback: bool = True,
fallback_text: Optional[str] = None, *, fallback_text: Optional[str] = None, *,