Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0471.py @ 4177:0f1a4ffcd419
doc (cli/blog): Document new `--alt-link` option
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Dec 2023 13:14:55 +0100 |
parents | 4b842c1fb686 |
children | bc898879af34 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2231 | 3 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
4 # Libervia plugin to handle events |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
5 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org) |
2231 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
20 from random import seed |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
21 from typing import Optional, Final, Dict, List, Union, Any, Optional |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
22 from attr import attr |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
23 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
24 import shortuuid |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
25 from sqlalchemy.orm.events import event |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.core.xmpp import SatXMPPClient |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
27 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
28 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
29 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
30 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
31 from libervia.backend.core.xmpp import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
32 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
33 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
34 from libervia.backend.tools import xml_tools |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
35 from libervia.backend.tools.common import uri as xmpp_uri |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
36 from libervia.backend.tools.common import date_utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
37 from libervia.backend.tools.common import data_format |
2231 | 38 from twisted.internet import defer |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
39 from twisted.words.protocols.jabber import jid, error |
2231 | 40 from twisted.words.xish import domish |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
41 from wokkel import disco, iwokkel |
3028 | 42 from zope.interface import implementer |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
43 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
44 from wokkel import pubsub, data_form |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
45 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
46 log = getLogger(__name__) |
2231 | 47 |
48 | |
49 PLUGIN_INFO = { | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
50 C.PI_NAME: "Events", |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
51 C.PI_IMPORT_NAME: "XEP-0471", |
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
52 C.PI_TYPE: "XEP", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
53 C.PI_MODES: C.PLUG_MODE_BOTH, |
2231 | 54 C.PI_PROTOCOLS: [], |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
55 C.PI_DEPENDENCIES: [ |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
56 "XEP-0060", "XEP-0080", "XEP-0447", "XEP-0470", # "INVITATION", "PUBSUB_INVITATION", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
57 # "LIST_INTEREST" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
58 ], |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
59 C.PI_RECOMMENDATIONS: ["XEP-0277", "EMAIL_INVITATION"], |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
60 C.PI_MAIN: "XEP_0471", |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
61 C.PI_HANDLER: "yes", |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
62 C.PI_DESCRIPTION: _("""Calendar Events"""), |
2231 | 63 } |
64 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
65 NS_EVENT = "org.salut-a-toi.event:0" |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
66 NS_EVENTS: Final = "urn:xmpp:events:0" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
67 NS_RSVP: Final = "urn:xmpp:events:rsvp:0" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
68 NS_EXTRA: Final = "urn:xmpp:events:extra:0" |
2231 | 69 |
70 | |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
71 class XEP_0471: |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
72 namespace = NS_EVENTS |
2231 | 73 |
74 def __init__(self, host): | |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
75 log.info(_("Events plugin initialization")) |
2231 | 76 self.host = host |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
77 self._p = host.plugins["XEP-0060"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
78 self._g = host.plugins["XEP-0080"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
79 self._b = host.plugins.get("XEP-0277") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
80 self._sfs = host.plugins["XEP-0447"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
81 self._a = host.plugins["XEP-0470"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
82 # self._i = host.plugins.get("EMAIL_INVITATION") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
83 host.register_namespace("events", NS_EVENTS) |
3956
3cb9ade2ab84
plugin pubsub signing: pubsub items signature implementation:
Goffi <goffi@goffi.org>
parents:
3915
diff
changeset
|
84 self._a.register_attachment_handler("rsvp", NS_EVENTS, self.rsvp_get, self.rsvp_set) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
85 # host.plugins["PUBSUB_INVITATION"].register(NS_EVENTS, self) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
86 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
87 "events_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
88 ".plugin", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
89 in_sign="ssasss", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
90 out_sign="s", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
91 method=self._events_get, |
3028 | 92 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
93 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
94 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
95 "event_create", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
96 ".plugin", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
97 in_sign="sssss", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
98 out_sign="", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
99 method=self._event_create, |
3028 | 100 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
101 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
102 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
103 "event_modify", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
104 ".plugin", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
105 in_sign="sssss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
106 out_sign="", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
107 method=self._event_modify, |
3028 | 108 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
109 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
110 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
111 "event_invitee_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
112 ".plugin", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
113 in_sign="sssasss", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
114 out_sign="s", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
115 method=self._event_invitee_get, |
3028 | 116 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
117 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
118 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
119 "event_invitee_set", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
120 ".plugin", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
121 in_sign="sssss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
122 out_sign="", |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
123 method=self._event_invitee_set, |
3028 | 124 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
125 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
126 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
127 "event_invitees_list", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
128 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
129 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
130 out_sign="a{sa{ss}}", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
131 method=self._event_invitees_list, |
3028 | 132 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
133 ), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
134 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
135 "event_invite", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
136 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
137 in_sign="sssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
138 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
139 method=self._invite, |
3028 | 140 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
141 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
142 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
143 "event_invite_by_email", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
144 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
145 in_sign="ssssassssssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
146 out_sign="", |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
147 method=self._invite_by_email, |
3028 | 148 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
149 ) |
2231 | 150 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
151 def get_handler(self, client): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
152 return EventsHandler(self) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
153 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
154 def _parse_event_elt(self, event_elt): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
155 """Helper method to parse event element |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
156 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
157 @param (domish.Element): event_elt |
2941
83cbd4545274
plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents:
2935
diff
changeset
|
158 @return (tuple[int, dict[unicode, unicode]): timestamp, event_data |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
159 """ |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
160 try: |
2612
3e4e78de9cca
tools (date_utils): moved date_parse to common.date_utils, because it can be used in frontends
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 timestamp = date_utils.date_parse(next(event_elt.elements(NS_EVENT, "date"))) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
162 except StopIteration: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
163 timestamp = -1 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
164 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
165 data = {} |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
166 |
3028 | 167 for key in ("name",): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
168 try: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
169 data[key] = event_elt[key] |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
170 except KeyError: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
171 continue |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
172 |
3028 | 173 for elt_name in ("description",): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
174 try: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
175 elt = next(event_elt.elements(NS_EVENT, elt_name)) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
176 except StopIteration: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
177 continue |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
178 else: |
3028 | 179 data[elt_name] = str(elt) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
180 |
3028 | 181 for elt_name in ("image", "background-image"): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
182 try: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
183 image_elt = next(event_elt.elements(NS_EVENT, elt_name)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
184 data[elt_name] = image_elt["src"] |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
185 except StopIteration: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
186 continue |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
187 except KeyError: |
3028 | 188 log.warning(_("no src found for image")) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
189 |
3028 | 190 for uri_type in ("invitees", "blog"): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
191 try: |
2246
e8641b7718dc
plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
192 elt = next(event_elt.elements(NS_EVENT, uri_type)) |
3028 | 193 uri = data[uri_type + "_uri"] = elt["uri"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
194 uri_data = xmpp_uri.parse_xmpp_uri(uri) |
3028 | 195 if uri_data["type"] != "pubsub": |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
196 raise ValueError |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
197 except StopIteration: |
3028 | 198 log.warning(_("no {uri_type} element found!").format(uri_type=uri_type)) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
199 except KeyError: |
3028 | 200 log.warning(_("incomplete {uri_type} element").format(uri_type=uri_type)) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
201 except ValueError: |
3028 | 202 log.warning(_("bad {uri_type} element").format(uri_type=uri_type)) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
203 else: |
3028 | 204 data[uri_type + "_service"] = uri_data["path"] |
205 data[uri_type + "_node"] = uri_data["node"] | |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
206 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
207 for meta_elt in event_elt.elements(NS_EVENT, "meta"): |
3028 | 208 key = meta_elt["name"] |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
209 if key in data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
210 log.warning( |
3028 | 211 "Ignoring conflicting meta element: {xml}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
212 xml=meta_elt.toXml() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
213 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
214 ) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
215 continue |
3028 | 216 data[key] = str(meta_elt) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
217 if event_elt.link: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
218 link_elt = event_elt.link |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
219 data["service"] = link_elt["service"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
220 data["node"] = link_elt["node"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
221 data["item"] = link_elt["item"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
222 if event_elt.getAttribute("creator") == "true": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
223 data["creator"] = True |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
224 return timestamp, data |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
225 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
226 def event_elt_2_event_data(self, event_elt: domish.Element) -> Dict[str, Any]: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
227 """Convert <event/> element to event data |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
228 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
229 @param event_elt: <event/> element |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
230 parent <item/> element can also be used |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
231 @raise exceptions.NotFound: can't find event payload |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
232 @raise ValueError: something is missing or badly formed |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
233 """ |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
234 if event_elt.name == "item": |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
235 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
236 event_elt = next(event_elt.elements(NS_EVENTS, "event")) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
237 except StopIteration: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
238 raise exceptions.NotFound("<event/> payload is missing") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
239 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
240 event_data: Dict[str, Any] = {} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
241 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
242 # id |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
243 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
244 parent_elt = event_elt.parent |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
245 if parent_elt is not None and parent_elt.hasAttribute("id"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
246 event_data["id"] = parent_elt["id"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
247 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
248 # name |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
249 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
250 name_data: Dict[str, str] = {} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
251 event_data["name"] = name_data |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
252 for name_elt in event_elt.elements(NS_EVENTS, "name"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
253 lang = name_elt.getAttribute("xml:lang", "") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
254 if lang in name_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
255 raise ValueError("<name/> elements don't have distinct xml:lang") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
256 name_data[lang] = str(name_elt) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
257 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
258 if not name_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
259 raise exceptions.NotFound("<name/> element is missing") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
260 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
261 # start |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
262 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
263 try: |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
264 start_elt = next(event_elt.elements(NS_EVENTS, "start")) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
265 except StopIteration: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
266 raise exceptions.NotFound("<start/> element is missing") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
267 event_data["start"] = utils.parse_xmpp_date(str(start_elt)) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
268 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
269 # end |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
270 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
271 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
272 end_elt = next(event_elt.elements(NS_EVENTS, "end")) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
273 except StopIteration: |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
274 raise exceptions.NotFound("<end/> element is missing") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
275 event_data["end"] = utils.parse_xmpp_date(str(end_elt)) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
276 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
277 # head-picture |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
278 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
279 head_pic_elt = next(event_elt.elements(NS_EVENTS, "head-picture"), None) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
280 if head_pic_elt is not None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
281 event_data["head-picture"] = self._sfs.parse_file_sharing_elt(head_pic_elt) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
282 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
283 # description |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
284 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
285 seen_desc = set() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
286 for description_elt in event_elt.elements(NS_EVENTS, "description"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
287 lang = description_elt.getAttribute("xml:lang", "") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
288 desc_type = description_elt.getAttribute("type", "text") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
289 lang_type = (lang, desc_type) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
290 if lang_type in seen_desc: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
291 raise ValueError( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
292 "<description/> elements don't have distinct xml:lang/type" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
293 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
294 seen_desc.add(lang_type) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
295 descriptions = event_data.setdefault("descriptions", []) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
296 description_data = {"description": str(description_elt)} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
297 if lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
298 description_data["language"] = lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
299 if desc_type: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
300 description_data["type"] = desc_type |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
301 descriptions.append(description_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
302 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
303 # categories |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
304 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
305 for category_elt in event_elt.elements(NS_EVENTS, "category"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
306 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
307 category_data = { |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
308 "term": category_elt["term"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
309 } |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
310 except KeyError: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
311 log.warning( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
312 "<category/> element is missing mandatory term: " |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
313 f"{category_elt.toXml()}" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
314 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
315 continue |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
316 wd = category_elt.getAttribute("wd") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
317 if wd: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
318 category_data["wikidata_id"] = wd |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
319 lang = category_elt.getAttribute("xml:lang") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
320 if lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
321 category_data["language"] = lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
322 event_data.setdefault("categories", []).append(category_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
323 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
324 # locations |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
325 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
326 seen_location_ids = set() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
327 for location_elt in event_elt.elements(NS_EVENTS, "location"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
328 location_id = location_elt.getAttribute("id", "") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
329 if location_id in seen_location_ids: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
330 raise ValueError("<location/> elements don't have distinct IDs") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
331 seen_location_ids.add(location_id) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
332 location_data = self._g.parse_geoloc_elt(location_elt) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
333 if location_id: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
334 location_data["id"] = location_id |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
335 lang = location_elt.getAttribute("xml:lang", "") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
336 if lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
337 location_data["language"] = lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
338 event_data.setdefault("locations", []).append(location_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
339 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
340 # RSVPs |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
341 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
342 seen_rsvp_lang = set() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
343 for rsvp_elt in event_elt.elements(NS_EVENTS, "rsvp"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
344 rsvp_lang = rsvp_elt.getAttribute("xml:lang", "") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
345 if rsvp_lang in seen_rsvp_lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
346 raise ValueError("<rsvp/> elements don't have distinct xml:lang") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
347 seen_rsvp_lang.add(rsvp_lang) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
348 rsvp_form = data_form.findForm(rsvp_elt, NS_RSVP) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
349 if rsvp_form is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
350 log.warning(f"RSVP form is missing: {rsvp_elt.toXml()}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
351 continue |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
352 rsvp_data = xml_tools.data_form_2_data_dict(rsvp_form) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
353 if rsvp_lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
354 rsvp_data["language"] = rsvp_lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
355 event_data.setdefault("rsvp", []).append(rsvp_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
356 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
357 # linked pubsub nodes |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
358 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
359 for name in ("invitees", "comments", "blog", "schedule"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
360 elt = next(event_elt.elements(NS_EVENTS, name), None) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
361 if elt is not None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
362 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
363 event_data[name] = { |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
364 "service": elt["jid"], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
365 "node": elt["node"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
366 } |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
367 except KeyError: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
368 log.warning(f"invalid {name} element: {elt.toXml()}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
369 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
370 # attachments |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
371 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
372 attachments_elt = next(event_elt.elements(NS_EVENTS, "attachments"), None) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
373 if attachments_elt: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
374 attachments = event_data["attachments"] = [] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
375 for file_sharing_elt in attachments_elt.elements( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
376 self._sfs.namespace, "file-sharing"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
377 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
378 file_sharing_data = self._sfs.parse_file_sharing_elt(file_sharing_elt) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
379 except Exception as e: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
380 log.warning(f"invalid attachment: {e}\n{file_sharing_elt.toXml()}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
381 continue |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
382 attachments.append(file_sharing_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
383 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
384 # extra |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
385 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
386 extra_elt = next(event_elt.elements(NS_EVENTS, "extra"), None) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
387 if extra_elt is not None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
388 extra_form = data_form.findForm(extra_elt, NS_EXTRA) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
389 if extra_form is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
390 log.warning(f"extra form is missing: {extra_elt.toXml()}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
391 else: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
392 extra_data = event_data["extra"] = {} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
393 for name, value in extra_form.items(): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
394 if name.startswith("accessibility:"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
395 extra_data.setdefault("accessibility", {})[name[14:]] = value |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
396 elif name == "accessibility": |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
397 log.warning( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
398 'ignoring "accessibility" key which is not standard: ' |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
399 f"{extra_form.toElement().toXml()}" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
400 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
401 else: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
402 extra_data[name] = value |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
403 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
404 # external |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
405 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
406 external_elt = next(event_elt.elements(NS_EVENTS, "external"), None) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
407 if external_elt: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
408 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
409 event_data["external"] = { |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
410 "jid": external_elt["jid"], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
411 "node": external_elt["node"], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
412 "item": external_elt["item"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
413 } |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
414 except KeyError: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
415 log.warning(f"invalid <external/> element: {external_elt.toXml()}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
416 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
417 return event_data |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
418 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
419 def _events_get( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
420 self, service: str, node: str, event_ids: List[str], extra: str, profile_key: str |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
421 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
422 client = self.host.get_client(profile_key) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
423 d = defer.ensureDeferred( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
424 self.events_get( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
425 client, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
426 jid.JID(service) if service else None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
427 node if node else NS_EVENTS, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
428 event_ids, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
429 data_format.deserialise(extra) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
430 ) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
431 ) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
432 d.addCallback(data_format.serialise) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
433 return d |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
434 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
435 async def events_get( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
436 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
437 client: SatXMPPEntity, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
438 service: Optional[jid.JID], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
439 node: str = NS_EVENTS, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
440 events_ids: Optional[List[str]] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
441 extra: Optional[dict] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
442 ) -> List[Dict[str, Any]]: |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
443 """Retrieve event data |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
444 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
445 @param service: pubsub service |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
446 @param node: pubsub node |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
447 @param event_id: pubsub item ID |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
448 @return: event data: |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
449 """ |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
450 if service is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
451 service = client.jid.userhostJID() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
452 items, __ = await self._p.get_items( |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
453 client, service, node, item_ids=events_ids, extra=extra |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
454 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
455 events = [] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
456 for item in items: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
457 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
458 events.append(self.event_elt_2_event_data((item))) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
459 except (ValueError, exceptions.NotFound): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
460 log.warning( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
461 f"Can't parse event for item {item['id']}: {item.toXml()}" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
462 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
463 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
464 return events |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
465 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
466 def _event_create( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
467 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
468 data_s: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
469 service: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
470 node: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
471 event_id: str = "", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
472 profile_key: str = C.PROF_KEY_NONE |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
473 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
474 client = self.host.get_client(profile_key) |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
475 return defer.ensureDeferred( |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
476 self.event_create( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
477 client, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
478 data_format.deserialise(data_s), |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
479 jid.JID(service) if service else None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
480 node or None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
481 event_id or None |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
482 ) |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
483 ) |
2231 | 484 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
485 def event_data_2_event_elt(self, event_data: Dict[str, Any]) -> domish.Element: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
486 """Convert Event Data to corresponding Element |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
487 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
488 @param event_data: data of the event with keys as follow: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
489 name (dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
490 map of language to name |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
491 empty string can be used as key if no language is specified |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
492 this key is mandatory |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
493 start (int|float) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
494 starting time of the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
495 this key is mandatory |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
496 end (int|float) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
497 ending time of the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
498 this key is mandatory |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
499 head-picture(dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
500 file sharing data for the main picture to use to represent the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
501 description(list[dict]) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
502 list of descriptions. If there are several descriptions, they must have |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
503 distinct (language, type). |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
504 Description data is dict which following keys: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
505 description(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
506 the description itself, either in plain text or xhtml |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
507 this key is mandatory |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
508 language(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
509 ISO-639 language code |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
510 type(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
511 type of the description, either "text" (default) or "xhtml" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
512 categories(list[dict]) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
513 each category is a dict with following keys: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
514 term(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
515 human readable short text of the category |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
516 this key is mandatory |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
517 wikidata_id(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
518 Entity ID from WikiData |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
519 language(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
520 ISO-639 language code |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
521 locations(list[dict]) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
522 list of location dict as used in plugin XEP-0080 [get_geoloc_elt]. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
523 If several locations are used, they must have distinct IDs |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
524 rsvp(list[dict]) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
525 RSVP data. The dict is a data dict as used in |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
526 sat.tools.xml_tools.data_dict_2_data_form with some extra keys. |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
527 The "attending" key is automatically added if it's not already present, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
528 except if the "no_default" key is present. Thus, an empty dict can be used |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
529 to use default RSVP. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
530 If several dict are present in the list, they must have different "lang" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
531 keys. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
532 Following extra key can be used: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
533 language(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
534 ISO-639 code for language used in the form |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
535 no_default(bool) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
536 if True, the "attending" field won't be automatically added |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
537 invitees(dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
538 link to pubsub node holding invitees list. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
539 Following keys are mandatory: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
540 service(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
541 pubsub service where the node is |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
542 node (str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
543 pubsub node to use |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
544 comments(dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
545 link to pubsub node holding XEP-0277 comments on the event itself. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
546 Following keys are mandatory: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
547 service(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
548 pubsub service where the node is |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
549 node (str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
550 pubsub node to use |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
551 blog(dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
552 link to pubsub node holding a blog about the event. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
553 Following keys are mandatory: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
554 service(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
555 pubsub service where the node is |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
556 node (str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
557 pubsub node to use |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
558 schedule(dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
559 link to pubsub node holding an events node describing the schedule of this |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
560 event. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
561 Following keys are mandatory: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
562 service(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
563 pubsub service where the node is |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
564 node (str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
565 pubsub node to use |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
566 attachments[list[dict]] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
567 list of file sharing data about all kind of attachments of interest for |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
568 the event. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
569 extra(dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
570 extra information about the event. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
571 Keys can be: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
572 website(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
573 main website about the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
574 status(str) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
575 status of the event. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
576 Can be one of "confirmed", "tentative" or "cancelled" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
577 languages(list[str]) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
578 ISO-639 codes for languages which will be mainly spoken at the |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
579 event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
580 accessibility(dict) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
581 accessibility informations. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
582 Keys can be: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
583 wheelchair |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
584 tell if the event is accessible to wheelchair. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
585 Value can be "full", "partial" or "no" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
586 external(dict): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
587 if present, this event is a link to an external one. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
588 Keys (all mandatory) are: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
589 jid: pubsub service |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
590 node: pubsub node |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
591 item: event id |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
592 @return: Event element |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
593 @raise ValueError: some expected data were missing or incorrect |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
594 """ |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
595 event_elt = domish.Element((NS_EVENTS, "event")) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
596 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
597 for lang, name in event_data["name"].items(): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
598 name_elt = event_elt.addElement("name", content=name) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
599 if lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
600 name_elt["xml:lang"] = lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
601 except (KeyError, TypeError): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
602 raise ValueError('"name" field is not a dict mapping language to event name') |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
603 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
604 event_elt.addElement("start", content=utils.xmpp_date(event_data["start"])) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
605 event_elt.addElement("end", content=utils.xmpp_date(event_data["end"])) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
606 except (KeyError, TypeError, ValueError): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
607 raise ValueError('"start" and "end" fields are mandatory') |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
608 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
609 if "head-picture" in event_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
610 head_pic_data = event_data["head-picture"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
611 head_picture_elt = event_elt.addElement("head-picture") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
612 head_picture_elt.addChild(self._sfs.get_file_sharing_elt(**head_pic_data)) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
613 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
614 seen_desc = set() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
615 if "descriptions" in event_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
616 for desc_data in event_data["descriptions"]: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
617 desc_type = desc_data.get("type", "text") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
618 lang = desc_data.get("language") or "" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
619 lang_type = (lang, desc_type) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
620 if lang_type in seen_desc: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
621 raise ValueError( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
622 '"xml:lang" and "type" is not unique among descriptions: ' |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
623 f"{desc_data}" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
624 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
625 seen_desc.add(lang_type) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
626 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
627 description = desc_data["description"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
628 except KeyError: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
629 log.warning(f"description is missing in {desc_data!r}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
630 continue |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
631 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
632 if desc_type == "text": |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
633 description_elt = event_elt.addElement( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
634 "description", content=description |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
635 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
636 elif desc_type == "xhtml": |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
637 description_elt = event_elt.addElement("description") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
638 div_elt = xml_tools.parse(description, namespace=C.NS_XHTML) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
639 description_elt.addChild(div_elt) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
640 else: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
641 log.warning(f"unknown description type {desc_type!r}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
642 continue |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
643 if lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
644 description_elt["xml:lang"] = lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
645 for category_data in event_data.get("categories", []): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
646 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
647 category_term = category_data["term"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
648 except KeyError: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
649 log.warning(f'"term" is missing categories data: {category_data}') |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
650 continue |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
651 category_elt = event_elt.addElement("category") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
652 category_elt["term"] = category_term |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
653 category_wd = category_data.get("wikidata_id") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
654 if category_wd: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
655 category_elt["wd"] = category_wd |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
656 category_lang = category_data.get("language") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
657 if category_lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
658 category_elt["xml:lang"] = category_lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
659 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
660 seen_location_ids = set() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
661 for location_data in event_data.get("locations", []): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
662 location_id = location_data.get("id", "") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
663 if location_id in seen_location_ids: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
664 raise ValueError("locations must have distinct IDs") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
665 seen_location_ids.add(location_id) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
666 location_elt = event_elt.addElement("location") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
667 location_elt.addChild(self._g.get_geoloc_elt(location_data)) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
668 if location_id: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
669 location_elt["id"] = location_id |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
670 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
671 rsvp_data_list: Optional[List[dict]] = event_data.get("rsvp") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
672 if rsvp_data_list is not None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
673 seen_lang = set() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
674 for rsvp_data in rsvp_data_list: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
675 if not rsvp_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
676 # we use a minimum data if an empty dict is received. It will be later |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
677 # filled with defaut "attending" field. |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
678 rsvp_data = {"fields": []} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
679 rsvp_elt = event_elt.addElement("rsvp") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
680 lang = rsvp_data.get("language", "") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
681 if lang in seen_lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
682 raise ValueError( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
683 "If several RSVP are specified, they must have distinct " |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
684 f"languages. {lang!r} language has been used several times." |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
685 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
686 seen_lang.add(lang) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
687 if lang: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
688 rsvp_elt["xml:lang"] = lang |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
689 if not rsvp_data.get("no_default", False): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
690 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
691 next(f for f in rsvp_data["fields"] if f["name"] == "attending") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
692 except StopIteration: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
693 rsvp_data["fields"].append({ |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
694 "type": "list-single", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
695 "name": "attending", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
696 "label": "Attending", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
697 "options": [ |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
698 {"label": "maybe", "value": "maybe"}, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
699 {"label": "yes", "value": "yes"}, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
700 {"label": "no", "value": "no"} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
701 ], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
702 "required": True |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
703 }) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
704 rsvp_data["namespace"] = NS_RSVP |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
705 rsvp_form = xml_tools.data_dict_2_data_form(rsvp_data) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
706 rsvp_elt.addChild(rsvp_form.toElement()) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
707 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
708 for node_type in ("invitees", "comments", "blog", "schedule"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
709 node_data = event_data.get(node_type) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
710 if not node_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
711 continue |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
712 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
713 service, node = node_data["service"], node_data["node"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
714 except KeyError: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
715 log.warning(f"invalid node data for {node_type}: {node_data}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
716 else: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
717 pub_node_elt = event_elt.addElement(node_type) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
718 pub_node_elt["jid"] = service |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
719 pub_node_elt["node"] = node |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
720 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
721 attachments = event_data.get("attachments") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
722 if attachments: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
723 attachments_elt = event_elt.addElement("attachments") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
724 for attachment_data in attachments: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
725 attachments_elt.addChild( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
726 self._sfs.get_file_sharing_elt(**attachment_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
727 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
728 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
729 extra = event_data.get("extra") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
730 if extra: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
731 extra_form = data_form.Form( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
732 "result", |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
733 formNamespace=NS_EXTRA |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
734 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
735 for node_type in ("website", "status"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
736 if node_type in extra: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
737 extra_form.addField( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
738 data_form.Field(var=node_type, value=extra[node_type]) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
739 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
740 if "languages" in extra: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
741 extra_form.addField( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
742 data_form.Field( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
743 "list-multi", var="languages", values=extra["languages"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
744 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
745 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
746 for node_type, value in extra.get("accessibility", {}).items(): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
747 extra_form.addField( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
748 data_form.Field(var=f"accessibility:{node_type}", value=value) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
749 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
750 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
751 extra_elt = event_elt.addElement("extra") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
752 extra_elt.addChild(extra_form.toElement()) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
753 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
754 if "external" in event_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
755 external_data = event_data["external"] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
756 external_elt = event_elt.addElement("external") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
757 for node_type in ("jid", "node", "item"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
758 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
759 value = external_data[node_type] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
760 except KeyError: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
761 raise ValueError(f"Invalid external data: {external_data}") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
762 external_elt[node_type] = value |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
763 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
764 return event_elt |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
765 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
766 async def event_create( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
767 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
768 client: SatXMPPEntity, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
769 event_data: Dict[str, Any], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
770 service: Optional[jid.JID] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
771 node: Optional[str] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
772 event_id: Optional[str] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
773 ) -> None: |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
774 """Create or replace an event |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
775 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
776 @param event_data: data of the event (cf. [event_data_2_event_elt]) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
777 @param node: PubSub node of the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
778 None to use default node (default namespace for personal agenda) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
779 @param service: PubSub service |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
780 None to use profile's PEP |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
781 @param event_id: ID of the item to create. |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
782 """ |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
783 if not service: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
784 service = client.jid.userhostJID() |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
785 if not node: |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
786 node = NS_EVENTS |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
787 if event_id is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
788 event_id = shortuuid.uuid() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
789 event_elt = self.event_data_2_event_elt(event_data) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
790 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
791 item_elt = pubsub.Item(id=event_id, payload=event_elt) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
792 options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
793 await self._p.create_if_new_node( |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
794 client, service, nodeIdentifier=node, options=options |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
795 ) |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
796 await self._p.publish(client, service, node, items=[item_elt]) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
797 if event_data.get("rsvp"): |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
798 await self._a.create_attachments_node(client, service, node, event_id) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
799 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
800 def _event_modify( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
801 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
802 data_s: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
803 event_id: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
804 service: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
805 node: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
806 profile_key: str = C.PROF_KEY_NONE |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
807 ) -> None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
808 client = self.host.get_client(profile_key) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
809 defer.ensureDeferred( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
810 self.event_modify( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
811 client, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
812 data_format.deserialise(data_s), |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
813 event_id, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
814 jid.JID(service) if service else None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
815 node or None, |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
816 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
817 ) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
818 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
819 async def event_modify( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
820 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
821 client: SatXMPPEntity, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
822 event_data: Dict[str, Any], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
823 event_id: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
824 service: Optional[jid.JID] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
825 node: Optional[str] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
826 ) -> None: |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
827 """Update an event |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
828 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
829 Similar as create instead that it update existing item instead of |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
830 creating or replacing it. Params are the same as for [event_create]. |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
831 """ |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
832 if not service: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
833 service = client.jid.userhostJID() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
834 if not node: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
835 node = NS_EVENTS |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
836 old_event = (await self.events_get(client, service, node, [event_id]))[0] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
837 old_event.update(event_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
838 event_data = old_event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
839 await self.event_create(client, event_data, service, node, event_id) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
840 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
841 def rsvp_get( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
842 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
843 client: SatXMPPEntity, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
844 attachments_elt: domish.Element, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
845 data: Dict[str, Any], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
846 ) -> None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
847 """Get RSVP answers from attachments""" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
848 try: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
849 rsvp_elt = next( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
850 attachments_elt.elements(NS_EVENTS, "rsvp") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
851 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
852 except StopIteration: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
853 pass |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
854 else: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
855 rsvp_form = data_form.findForm(rsvp_elt, NS_RSVP) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
856 if rsvp_form is not None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
857 data["rsvp"] = rsvp_data = dict(rsvp_form) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
858 self._a.set_timestamp(rsvp_elt, rsvp_data) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
859 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
860 def rsvp_set( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
861 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
862 client: SatXMPPEntity, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
863 data: Dict[str, Any], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
864 former_elt: Optional[domish.Element] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
865 ) -> Optional[domish.Element]: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
866 """update the <reaction> attachment""" |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
867 rsvp_data = data["extra"].get("rsvp") |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
868 if rsvp_data is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
869 return former_elt |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
870 elif rsvp_data: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
871 rsvp_elt = domish.Element( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
872 (NS_EVENTS, "rsvp"), |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
873 attribs = { |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
874 "timestamp": utils.xmpp_date() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
875 } |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
876 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
877 rsvp_form = data_form.Form("submit", formNamespace=NS_RSVP) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
878 rsvp_form.makeFields(rsvp_data) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
879 rsvp_elt.addChild(rsvp_form.toElement()) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
880 return rsvp_elt |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
881 else: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
882 return None |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
883 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
884 def _event_invitee_get( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
885 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
886 service: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
887 node: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
888 item: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
889 invitees_s: List[str], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
890 extra: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
891 profile_key: str |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
892 ) -> defer.Deferred: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
893 client = self.host.get_client(profile_key) |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
894 if invitees_s: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
895 invitees = [jid.JID(i) for i in invitees_s] |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
896 else: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
897 invitees = None |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
898 d = defer.ensureDeferred( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
899 self.event_invitee_get( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
900 client, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
901 jid.JID(service) if service else None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
902 node or None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
903 item, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
904 invitees, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
905 data_format.deserialise(extra) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
906 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
907 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
908 d.addCallback(lambda ret: data_format.serialise(ret)) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
909 return d |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
910 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
911 async def event_invitee_get( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
912 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
913 client: SatXMPPEntity, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
914 service: Optional[jid.JID], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
915 node: Optional[str], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
916 item: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
917 invitees: Optional[List[jid.JID]] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
918 extra: Optional[Dict[str, Any]] = None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
919 ) -> Dict[str, Dict[str, Any]]: |
2231 | 920 """Retrieve attendance from event node |
921 | |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
922 @param service: PubSub service |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
923 @param node: PubSub node of the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
924 @param item: PubSub item of the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
925 @param invitees: if set, only retrieve RSVPs from those guests |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
926 @param extra: extra data used to retrieve items as for [get_attachments] |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
927 @return: mapping of invitee bare JID to their RSVP |
2231 | 928 an empty dict is returned if nothing has been answered yed |
929 """ | |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
930 if service is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
931 service = client.jid.userhostJID() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
932 if node is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
933 node = NS_EVENTS |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
934 attachments, metadata = await self._a.get_attachments( |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
935 client, service, node, item, invitees, extra |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
936 ) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
937 ret = {} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
938 for attachment in attachments: |
2231 | 939 try: |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
940 rsvp = attachment["rsvp"] |
2231 | 941 except KeyError: |
942 continue | |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
943 ret[attachment["from"]] = rsvp |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
944 |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
945 return ret |
2231 | 946 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
947 def _event_invitee_set( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
948 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
949 service: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
950 node: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
951 item: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
952 rsvp_s: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
953 profile_key: str |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
954 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
955 client = self.host.get_client(profile_key) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
956 return defer.ensureDeferred( |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
957 self.event_invitee_set( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
958 client, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
959 jid.JID(service) if service else None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
960 node or None, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
961 item, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
962 data_format.deserialise(rsvp_s) |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
963 ) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
964 ) |
2231 | 965 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
966 async def event_invitee_set( |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
967 self, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
968 client: SatXMPPEntity, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
969 service: Optional[jid.JID], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
970 node: Optional[str], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
971 item: str, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
972 rsvp: Dict[str, Any], |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
973 ) -> None: |
2231 | 974 """Set or update attendance data in event node |
975 | |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
976 @param service: PubSub service |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
977 @param node: PubSub node of the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
978 @param item: PubSub item of the event |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
979 @param rsvp: RSVP data (values to submit to the form) |
2231 | 980 """ |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
981 if service is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
982 service = client.jid.userhostJID() |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
983 if node is None: |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
984 node = NS_EVENTS |
3956
3cb9ade2ab84
plugin pubsub signing: pubsub items signature implementation:
Goffi <goffi@goffi.org>
parents:
3915
diff
changeset
|
985 await self._a.set_attachements(client, { |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
986 "service": service.full(), |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
987 "node": node, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
988 "id": item, |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
989 "extra": {"rsvp": rsvp} |
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
990 }) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
991 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
992 def _event_invitees_list(self, service, node, profile_key): |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
993 service = jid.JID(service) if service else None |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
994 node = node if node else NS_EVENT |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
995 client = self.host.get_client(profile_key) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
996 return defer.ensureDeferred( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
997 self.event_invitees_list(client, service, node) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
998 ) |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
999 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1000 async def event_invitees_list(self, client, service, node): |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1001 """Retrieve attendance from event node |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1002 |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1003 @param service(unicode, None): PubSub service |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1004 @param node(unicode): PubSub node of the event |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1005 @return (dict): a dict with current attendance status, |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1006 an empty dict is returned if nothing has been answered yed |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1007 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1008 items, metadata = await self._p.get_items(client, service, node) |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1009 invitees = {} |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1010 for item in items: |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1011 try: |
3028 | 1012 event_elt = next(item.elements(NS_EVENT, "invitee")) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1013 except StopIteration: |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1014 # no item found, event data are not set yet |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1015 log.warning(_( |
3028 | 1016 "no data found for {item_id} (service: {service}, node: {node})" |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1017 .format(item_id=item["id"], service=service, node=node))) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1018 else: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1019 data = {} |
3028 | 1020 for key in ("attend", "guests"): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1021 try: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1022 data[key] = event_elt[key] |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1023 except KeyError: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1024 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1025 invitees[item["id"]] = data |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1026 return invitees |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
1027 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1028 async def invite_preflight( |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1029 self, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1030 client: SatXMPPEntity, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1031 invitee_jid: jid.JID, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1032 service: jid.JID, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1033 node: str, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1034 item_id: Optional[str] = None, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1035 name: str = '', |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1036 extra: Optional[dict] = None, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1037 ) -> None: |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1038 if self._b is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1039 raise exceptions.FeatureNotFound( |
3028 | 1040 _('"XEP-0277" (blog) plugin is needed for this feature') |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1041 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1042 if item_id is None: |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1043 item_id = extra["default_item_id"] = NS_EVENT |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1044 |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
1045 __, event_data = await self.events_get(client, service, node, item_id) |
3028 | 1046 log.debug(_("got event data")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1047 invitees_service = jid.JID(event_data["invitees_service"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1048 invitees_node = event_data["invitees_node"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1049 blog_service = jid.JID(event_data["blog_service"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1050 blog_node = event_data["blog_node"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1051 await self._p.set_node_affiliations( |
3028 | 1052 client, invitees_service, invitees_node, {invitee_jid: "publisher"} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1053 ) |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1054 log.debug( |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1055 f"affiliation set on invitee node (jid: {invitees_service}, " |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1056 f"node: {invitees_node!r})" |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1057 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1058 await self._p.set_node_affiliations( |
3028 | 1059 client, blog_service, blog_node, {invitee_jid: "member"} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1060 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1061 blog_items, __ = await self._b.mb_get(client, blog_service, blog_node, None) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1062 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1063 for item in blog_items: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1064 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1065 comments_service = jid.JID(item["comments_service"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1066 comments_node = item["comments_node"] |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1067 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1068 log.debug( |
3028 | 1069 "no comment service set for item {item_id}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1070 item_id=item["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1071 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1072 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1073 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1074 await self._p.set_node_affiliations( |
3028 | 1075 client, comments_service, comments_node, {invitee_jid: "publisher"} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1076 ) |
3028 | 1077 log.debug(_("affiliation set on blog and comments nodes")) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1078 |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1079 def _invite(self, invitee_jid, service, node, item_id, profile): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1080 return self.host.plugins["PUBSUB_INVITATION"]._send_pubsub_invitation( |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1081 invitee_jid, service, node, item_id or NS_EVENT, profile_key=profile |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1082 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1083 |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
1084 def _invite_by_email(self, service, node, id_=NS_EVENT, email="", emails_extra=None, |
3028 | 1085 name="", host_name="", language="", url_template="", |
1086 message_subject="", message_body="", | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1087 profile_key=C.PROF_KEY_NONE): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1088 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1089 kwargs = { |
3028 | 1090 "profile": client.profile, |
1091 "emails_extra": [str(e) for e in emails_extra], | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1092 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1093 for key in ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1094 "email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1095 "name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1096 "host_name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1097 "language", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1098 "url_template", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1099 "message_subject", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1100 "message_body", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1101 ): |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1102 value = locals()[key] |
3028 | 1103 kwargs[key] = str(value) |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
1104 return defer.ensureDeferred(self.invite_by_email( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1105 client, jid.JID(service) if service else None, node, id_ or NS_EVENT, **kwargs |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1106 )) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1107 |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
1108 async def invite_by_email(self, client, service, node, id_=NS_EVENT, **kwargs): |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1109 """High level method to create an email invitation to an event |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1110 |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1111 @param service(unicode, None): PubSub service |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1112 @param node(unicode): PubSub node of the event |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1113 @param id_(unicode): id_ with even data |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1114 """ |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1115 if self._i is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1116 raise exceptions.FeatureNotFound( |
3028 | 1117 _('"Invitations" plugin is needed for this feature') |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1118 ) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1119 if self._b is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1120 raise exceptions.FeatureNotFound( |
3028 | 1121 _('"XEP-0277" (blog) plugin is needed for this feature') |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1122 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1123 service = service or client.jid.userhostJID() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1124 event_uri = xmpp_uri.build_xmpp_uri( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1125 "pubsub", path=service.full(), node=node, item=id_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1126 ) |
3028 | 1127 kwargs["extra"] = {"event_uri": event_uri} |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1128 invitation_data = await self._i.create(**kwargs) |
3028 | 1129 invitee_jid = invitation_data["jid"] |
1130 log.debug(_("invitation created")) | |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1131 # now that we have a jid, we can send normal invitation |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1132 await self.invite(client, invitee_jid, service, node, id_) |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1133 |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3956
diff
changeset
|
1134 def on_invitation_preflight( |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1135 self, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1136 client: SatXMPPEntity, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1137 name: str, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1138 extra: dict, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1139 service: jid.JID, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1140 node: str, |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1141 item_id: Optional[str], |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1142 item_elt: domish.Element |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1143 ) -> None: |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1144 event_elt = item_elt.event |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1145 link_elt = event_elt.addElement("link") |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1146 link_elt["service"] = service.full() |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1147 link_elt["node"] = node |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1148 link_elt["item"] = item_id |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
1149 __, event_data = self._parse_event_elt(event_elt) |
3462
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1150 try: |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1151 name = event_data["name"] |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1152 except KeyError: |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1153 pass |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1154 else: |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1155 extra["name"] = name |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1156 if 'image' in event_data: |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1157 extra["thumb_url"] = event_data['image'] |
12dc234f698c
plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
1158 extra["element"] = event_elt |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1159 |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
1160 |
3028 | 1161 @implementer(iwokkel.IDisco) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1162 class EventsHandler(XMPPHandler): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1163 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1164 def __init__(self, plugin_parent): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1165 self.plugin_parent = plugin_parent |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1166 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1167 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1168 return [ |
3902
32b38dd3ac18
plugin events: update following `Events` protoXEP submission:
Goffi <goffi@goffi.org>
parents:
3709
diff
changeset
|
1169 disco.DiscoFeature(NS_EVENTS), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1170 ] |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1171 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
1172 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
1173 return [] |