blob: 88067dc5061866484626c32f8ddd935469613a3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# 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)
|