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