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/stanza.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/stanza.py')
-rw-r--r-- | slixmpp/plugins/xep_0437/stanza.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/slixmpp/plugins/xep_0437/stanza.py b/slixmpp/plugins/xep_0437/stanza.py new file mode 100644 index 00000000..cd3a2c84 --- /dev/null +++ b/slixmpp/plugins/xep_0437/stanza.py @@ -0,0 +1,47 @@ +""" + 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 +from slixmpp import JID, Presence +from slixmpp.xmlstream import ( + ElementBase, + register_stanza_plugin, +) + +NS = 'urn:xmpp:rai:0' + +class RAI(ElementBase): + name = 'rai' + plugin_attrib = 'rai' + namespace = NS + interfaces = {'activities'} + + def get_activities(self) -> Iterable[JID]: + return [JID(el.xml.text) for el in self if isinstance(el, Activity)] + + def del_activities(self): + for el in self.xml.findall('{%s}activity' % NS): + self.xml.remove(el) + + def set_activities(self, activities: Iterable[JID]): + self.del_activities() + for jid in activities: + act = Activity() + act.xml.text = str(jid) + self.append(act) + + +class Activity(ElementBase): + name = 'activity' + plugin_attrib = 'activity' + namespace = NS + + +def register_plugins(): + register_stanza_plugin(RAI, Activity, iterable=True) + register_stanza_plugin(Presence, RAI) |