XEP-047: Room Activity Indicators
Implement the XEP
This commit is contained in:
parent
8258202681
commit
b63dc3bc8c
6 changed files with 162 additions and 0 deletions
8
doap.xml
8
doap.xml
|
@ -863,6 +863,14 @@
|
||||||
<xmpp:since>NEXT</xmpp:since>
|
<xmpp:since>NEXT</xmpp:since>
|
||||||
</xmpp:SupportedXep>
|
</xmpp:SupportedXep>
|
||||||
</implements>
|
</implements>
|
||||||
|
<implements>
|
||||||
|
<xmpp:SupportedXep>
|
||||||
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0437.html"/>
|
||||||
|
<xmpp:status>complete</xmpp:status>
|
||||||
|
<xmpp:version>0.2.0</xmpp:version>
|
||||||
|
<xmpp:since>NEXT</xmpp:since>
|
||||||
|
</xmpp:SupportedXep>
|
||||||
|
</implements>
|
||||||
<implements>
|
<implements>
|
||||||
<xmpp:SupportedXep>
|
<xmpp:SupportedXep>
|
||||||
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0439.html"/>
|
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0439.html"/>
|
||||||
|
|
|
@ -109,6 +109,7 @@ __all__ = [
|
||||||
'xep_0424', # Message Retraction
|
'xep_0424', # Message Retraction
|
||||||
'xep_0425', # Message Moderation
|
'xep_0425', # Message Moderation
|
||||||
'xep_0428', # Message Fallback
|
'xep_0428', # Message Fallback
|
||||||
|
'xep_0437', # Room Activity Indicators
|
||||||
'xep_0439', # Quick Response
|
'xep_0439', # Quick Response
|
||||||
'xep_0444', # Message Reactions
|
'xep_0444', # Message Reactions
|
||||||
]
|
]
|
||||||
|
|
11
slixmpp/plugins/xep_0437/__init__.py
Normal file
11
slixmpp/plugins/xep_0437/__init__.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
"""
|
||||||
|
Slixmpp: The Slick XMPP Library
|
||||||
|
Copyright (C) 2020 Mathieu Pasquet
|
||||||
|
This file is part of Slixmpp.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
from slixmpp.plugins.xep_0437.rai import XEP_0437
|
||||||
|
|
||||||
|
register_plugin(XEP_0437)
|
67
slixmpp/plugins/xep_0437/rai.py
Normal file
67
slixmpp/plugins/xep_0437/rai.py
Normal file
|
@ -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()
|
47
slixmpp/plugins/xep_0437/stanza.py
Normal file
47
slixmpp/plugins/xep_0437/stanza.py
Normal file
|
@ -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)
|
28
tests/test_stanza_xep_0437.py
Normal file
28
tests/test_stanza_xep_0437.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import unittest
|
||||||
|
from slixmpp import Presence, JID
|
||||||
|
from slixmpp.test import SlixTest
|
||||||
|
from slixmpp.plugins.xep_0437 import stanza
|
||||||
|
|
||||||
|
|
||||||
|
class TestRAI(SlixTest):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
stanza.register_plugins()
|
||||||
|
|
||||||
|
def testResponse(self):
|
||||||
|
presence = Presence()
|
||||||
|
presence['rai']['activities'] = [
|
||||||
|
JID('toto@titi'),
|
||||||
|
JID('coucou@coucou'),
|
||||||
|
]
|
||||||
|
self.check(presence, """
|
||||||
|
<presence>
|
||||||
|
<rai xmlns="urn:xmpp:rai:0">
|
||||||
|
<activity>toto@titi</activity>
|
||||||
|
<activity>coucou@coucou</activity>
|
||||||
|
</rai>
|
||||||
|
</presence>
|
||||||
|
""", use_values=False)
|
||||||
|
|
||||||
|
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestRAI)
|
Loading…
Reference in a new issue