XEP-0405: Manage MIX Roster items
This commit is contained in:
parent
119f59ecbe
commit
04a3f609e2
@ -6,13 +6,16 @@
|
|||||||
See the file LICENSE for copying permission.
|
See the file LICENSE for copying permission.
|
||||||
"""
|
"""
|
||||||
from typing import (
|
from typing import (
|
||||||
|
List,
|
||||||
Optional,
|
Optional,
|
||||||
Set,
|
Set,
|
||||||
|
Tuple,
|
||||||
)
|
)
|
||||||
|
|
||||||
from slixmpp import JID, Iq
|
from slixmpp import JID, Iq
|
||||||
from slixmpp.exceptions import IqError, IqTimeout
|
from slixmpp.exceptions import IqError, IqTimeout
|
||||||
from slixmpp.plugins import BasePlugin
|
from slixmpp.plugins import BasePlugin
|
||||||
|
from slixmpp.stanza.roster import RosterItem
|
||||||
from slixmpp.plugins.xep_0405 import stanza
|
from slixmpp.plugins.xep_0405 import stanza
|
||||||
from slixmpp.plugins.xep_0369 import stanza as mix_stanza
|
from slixmpp.plugins.xep_0369 import stanza as mix_stanza
|
||||||
|
|
||||||
@ -86,3 +89,26 @@ class XEP_0405(BasePlugin):
|
|||||||
iq['client_leave']['channel'] = room
|
iq['client_leave']['channel'] = room
|
||||||
iq['client_leave'].enable('mix_leave')
|
iq['client_leave'].enable('mix_leave')
|
||||||
return await iq.send(**iqkwargs)
|
return await iq.send(**iqkwargs)
|
||||||
|
|
||||||
|
async def get_mix_roster(self, *,
|
||||||
|
ito: Optional[JID] = None,
|
||||||
|
ifrom: Optional[JID] = None,
|
||||||
|
**iqkwargs) -> Tuple[List[RosterItem], List[RosterItem]]:
|
||||||
|
"""
|
||||||
|
Get the annotated roster, with MIX channels.
|
||||||
|
|
||||||
|
:return: A tuple of (contacts, mix channels) as RosterItem elements
|
||||||
|
"""
|
||||||
|
iq = self.xmpp.make_iq_get(ito=ito, ifrom=ifrom)
|
||||||
|
iq['roster'].enable('annotate')
|
||||||
|
result = await iq.send(**iqkwargs)
|
||||||
|
self.xmpp.event("roster_update", result)
|
||||||
|
contacts = []
|
||||||
|
mix = []
|
||||||
|
for item in result['roster']:
|
||||||
|
channel = item._get_plugin('channel', check=True)
|
||||||
|
if channel:
|
||||||
|
mix.append(item)
|
||||||
|
else:
|
||||||
|
contacts.append(item)
|
||||||
|
return (contacts, mix)
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
from slixmpp import JID
|
from slixmpp import JID
|
||||||
from slixmpp.stanza import Iq
|
from slixmpp.stanza import Iq
|
||||||
|
from slixmpp.stanza.roster import Roster, RosterItem
|
||||||
from slixmpp.xmlstream import (
|
from slixmpp.xmlstream import (
|
||||||
ElementBase,
|
ElementBase,
|
||||||
register_stanza_plugin,
|
register_stanza_plugin,
|
||||||
@ -19,6 +20,7 @@ from slixmpp.plugins.xep_0369.stanza import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
NS = 'urn:xmpp:mix:pam:2'
|
NS = 'urn:xmpp:mix:pam:2'
|
||||||
|
NS_ROSTER = 'urn:xmpp:mix:roster:0'
|
||||||
|
|
||||||
|
|
||||||
class ClientJoin(ElementBase):
|
class ClientJoin(ElementBase):
|
||||||
@ -35,9 +37,25 @@ class ClientLeave(ElementBase):
|
|||||||
interfaces = {'channel'}
|
interfaces = {'channel'}
|
||||||
|
|
||||||
|
|
||||||
|
class Annotate(ElementBase):
|
||||||
|
namespace = NS_ROSTER
|
||||||
|
name = 'annotate'
|
||||||
|
plugin_attrib = 'annotate'
|
||||||
|
|
||||||
|
|
||||||
|
class Channel(ElementBase):
|
||||||
|
namespace = NS_ROSTER
|
||||||
|
name = 'channel'
|
||||||
|
plugin_attrib = 'channel'
|
||||||
|
interfaces = {'participant-id'}
|
||||||
|
|
||||||
|
|
||||||
def register_plugins():
|
def register_plugins():
|
||||||
register_stanza_plugin(Iq, ClientJoin)
|
register_stanza_plugin(Iq, ClientJoin)
|
||||||
register_stanza_plugin(ClientJoin, Join)
|
register_stanza_plugin(ClientJoin, Join)
|
||||||
|
|
||||||
register_stanza_plugin(Iq, ClientLeave)
|
register_stanza_plugin(Iq, ClientLeave)
|
||||||
register_stanza_plugin(ClientLeave, Leave)
|
register_stanza_plugin(ClientLeave, Leave)
|
||||||
|
|
||||||
|
register_stanza_plugin(Roster, Annotate)
|
||||||
|
register_stanza_plugin(RosterItem, Channel)
|
||||||
|
Loading…
Reference in New Issue
Block a user