diff options
author | mathieui <mathieui@mathieui.net> | 2020-12-07 22:27:28 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2020-12-08 18:56:26 +0100 |
commit | b63dc3bc8cf16177a6e50a804681958a47497550 (patch) | |
tree | e8bf12aebda1f723ca7c2c072e70466760c481f0 /slixmpp/plugins/xep_0437/rai.py | |
parent | 8258202681b32fb7267562a9fe3a5af03eb17f50 (diff) | |
download | slixmpp-b63dc3bc8cf16177a6e50a804681958a47497550.tar.gz slixmpp-b63dc3bc8cf16177a6e50a804681958a47497550.tar.bz2 slixmpp-b63dc3bc8cf16177a6e50a804681958a47497550.tar.xz slixmpp-b63dc3bc8cf16177a6e50a804681958a47497550.zip |
XEP-047: Room Activity Indicators
Implement the XEP
Diffstat (limited to 'slixmpp/plugins/xep_0437/rai.py')
-rw-r--r-- | slixmpp/plugins/xep_0437/rai.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/slixmpp/plugins/xep_0437/rai.py b/slixmpp/plugins/xep_0437/rai.py new file mode 100644 index 00000000..c3c4d325 --- /dev/null +++ b/slixmpp/plugins/xep_0437/rai.py @@ -0,0 +1,67 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2020 Mathieu Pasquet + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" +from typing import Iterable, Optional + +from slixmpp import JID +from slixmpp.plugins import BasePlugin +from slixmpp.stanza import Presence +from slixmpp.xmlstream.matcher import StanzaPath +from slixmpp.xmlstream.handler import Callback + +from slixmpp.plugins.xep_0437 import stanza + + +class XEP_0437(BasePlugin): + name = 'xep_0437' + description = 'XEP-0437: Room Activity Indicators' + stanza = stanza + namespace = stanza.NS + + def plugin_init(self): + stanza.register_plugins() + self.xmpp.register_handler(Callback( + 'RAI Received', + StanzaPath("presence/rai"), + self._handle_rai, + )) + self.xmpp.register_handler(Callback( + 'RAI Activity Received', + StanzaPath("presence/rai/activity"), + self._handle_rai_activity, + )) + + def plugin_end(self): + self.xmpp.remove_handler('RAI received') + self.xmpp.remove_handler('RAI Activity received') + + def _handle_rai(self, presence: Presence): + self.xmpp.event('room_activity_bare', presence) + + def _handle_rai_activity(self, presence: Presence): + self.xmpp.event('room_activity', presence) + + def subscribe(self, service: JID, *, + pfrom: Optional[JID] = None): + """ + Subscribe to room activty on a MUC service. + :param JID service: MUC service + """ + pres = self.xmpp.make_presence(pto=service, pfrom=pfrom) + pres.enable('rai') + pres.send() + + def unsubscribe(self, service: JID, *, + pfrom: Optional[JID] = None): + """ + Unsubscribe from room activty on a MUC service. + :param JID service: MUC service + """ + pres = self.xmpp.make_presence( + pto=service, pfrom=pfrom, ptype='unavailable', + ) + pres.send() |