From a18a6c4eb8f8a59de07467abe02135abd2afe32f Mon Sep 17 00:00:00 2001 From: nicoco Date: Sun, 17 Mar 2024 12:44:13 +0100 Subject: [PATCH] xep-0425: update to version 0.3.0 --- doap.xml | 2 +- slixmpp/plugins/__init__.py | 2 +- slixmpp/plugins/xep_0425/moderation.py | 12 +++++----- slixmpp/plugins/xep_0425/stanza.py | 19 +++++++-------- tests/test_stanza_xep_0425.py | 33 ++++++++++++++------------ 5 files changed, 35 insertions(+), 33 deletions(-) diff --git a/doap.xml b/doap.xml index 80d812aa..c22e64e9 100644 --- a/doap.xml +++ b/doap.xml @@ -864,7 +864,7 @@ complete - 0.2.1 + 0.3.0 1.6.0 diff --git a/slixmpp/plugins/__init__.py b/slixmpp/plugins/__init__.py index 6db22ed2..e0c8f38d 100644 --- a/slixmpp/plugins/__init__.py +++ b/slixmpp/plugins/__init__.py @@ -112,7 +112,7 @@ PLUGINS = [ 'xep_0421', # Anonymous unique occupant identifiers for MUCs 'xep_0422', # Message Fastening 'xep_0424', # Message Retraction - 'xep_0425', # Message Moderation + 'xep_0425', # Moderated Message Retraction 'xep_0428', # Message Fallback 'xep_0437', # Room Activity Indicators 'xep_0439', # Quick Response diff --git a/slixmpp/plugins/xep_0425/moderation.py b/slixmpp/plugins/xep_0425/moderation.py index 3c1308fc..863b4c34 100644 --- a/slixmpp/plugins/xep_0425/moderation.py +++ b/slixmpp/plugins/xep_0425/moderation.py @@ -13,10 +13,10 @@ from slixmpp.plugins.xep_0425 import stanza class XEP_0425(BasePlugin): - '''XEP-0425: Message Moderation''' + '''XEP-0425: Moderated Message Retraction''' name = 'xep_0425' - description = 'XEP-0425: Message Moderation' + description = 'XEP-0425: Moderated Message Retraction' dependencies = {'xep_0424', 'xep_0421'} stanza = stanza namespace = stanza.NS @@ -25,7 +25,7 @@ class XEP_0425(BasePlugin): stanza.register_plugins() self.xmpp.register_handler(Callback( 'Moderated Message', - StanzaPath('message/apply_to/moderated/retract'), + StanzaPath('message/retract/moderated'), self._handle_moderated, )) @@ -42,7 +42,7 @@ class XEP_0425(BasePlugin): async def moderate(self, room: JID, id: str, reason: str = '', *, ifrom: Optional[JID] = None, **iqkwargs): iq = self.xmpp.make_iq_set(ito=room.bare, ifrom=ifrom) - iq['apply_to']['id'] = id - iq['apply_to']['moderate']['reason'] = reason - iq['apply_to']['moderate'].enable('retract') + iq['moderate']['id'] = id + iq['moderate']['reason'] = reason + iq['moderate'].enable('retract') await iq.send(**iqkwargs) diff --git a/slixmpp/plugins/xep_0425/stanza.py b/slixmpp/plugins/xep_0425/stanza.py index f195c99b..9fabda20 100644 --- a/slixmpp/plugins/xep_0425/stanza.py +++ b/slixmpp/plugins/xep_0425/stanza.py @@ -8,12 +8,11 @@ from slixmpp.xmlstream import ( ElementBase, register_stanza_plugin, ) -from slixmpp.plugins.xep_0422.stanza import ApplyTo from slixmpp.plugins.xep_0421.stanza import OccupantId from slixmpp.plugins.xep_0424.stanza import Retract, Retracted -NS = 'urn:xmpp:message-moderate:0' +NS = 'urn:xmpp:message-moderate:1' class Moderate(ElementBase): @@ -28,17 +27,17 @@ class Moderated(ElementBase): namespace = NS name = 'moderated' plugin_attrib = 'moderated' - interfaces = {'reason', 'by'} - sub_interfaces = {'reason'} + interfaces = {'by'} def register_plugins(): - register_stanza_plugin(Iq, ApplyTo) - register_stanza_plugin(ApplyTo, Moderate) + # for moderation requests + register_stanza_plugin(Iq, Moderate) register_stanza_plugin(Moderate, Retract) - register_stanza_plugin(Message, Moderated) - register_stanza_plugin(ApplyTo, Moderated) - register_stanza_plugin(Moderated, Retract) - register_stanza_plugin(Moderated, Retracted) + # for moderation events + register_stanza_plugin(Retract, Moderated) register_stanza_plugin(Moderated, OccupantId) + + # for tombstones + register_stanza_plugin(Retracted, Moderated) diff --git a/tests/test_stanza_xep_0425.py b/tests/test_stanza_xep_0425.py index 96d979e8..46192492 100644 --- a/tests/test_stanza_xep_0425.py +++ b/tests/test_stanza_xep_0425.py @@ -1,45 +1,48 @@ import unittest from slixmpp import Message, Iq, JID from slixmpp.test import SlixTest +from slixmpp.plugins.xep_0424 import stanza as stanza424 from slixmpp.plugins.xep_0425 import stanza class TestModeration(SlixTest): def setUp(self): + stanza424.register_plugins() stanza.register_plugins() def testModerate(self): iq = Iq() iq['type'] = 'set' iq['id'] = 'a' - iq['apply_to']['id'] = 'some-id' - iq['apply_to']['moderate'].enable('retract') - iq['apply_to']['moderate']['reason'] = 'R' + iq['moderate']['id'] = 'some-id' + iq['moderate'].enable('retract') + iq['moderate']['reason'] = 'R' self.check(iq, """ - - - - R - - + + + R + """, use_values=False) def testModerated(self): message = Message() - message['moderated']['by'] = JID('toto@titi') - message['moderated']['retracted']['stamp'] = '2019-09-20T23:09:32Z' - message['moderated']['reason'] = 'R' + message['retract']['id'] = 'some-id' + message['retract']['moderated']['by'] = JID('toto@titi') + message['retract']['moderated']['occupant-id']['id'] = 'oc-id' + message['retract']['reason'] = 'R' self.check(message, """ - - + + + + R - + """)