Mercurial > libervia-backend
annotate sat/plugins/plugin_exp_events.py @ 2913:672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 14 Apr 2019 08:21:51 +0200 |
parents | a3faf1c86596 |
children | b256e90612d0 |
rev | line source |
---|---|
2231 | 1 #!/usr/bin/env python2 |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT plugin to detect language (experimental) | |
2771 | 5 # Copyright (C) 2009-2019 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 | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
20 import shortuuid |
2231 | 21 from sat.core.i18n import _ |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
22 from sat.core import exceptions |
2231 | 23 from sat.core.constants import Const as C |
24 from sat.core.log import getLogger | |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
25 from sat.tools import utils |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
26 from sat.tools.common import uri as xmpp_uri |
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
|
27 from sat.tools.common import date_utils |
2231 | 28 from twisted.internet import defer |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
29 from twisted.words.protocols.jabber import jid, error |
2231 | 30 from twisted.words.xish import domish |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
31 from wokkel import disco, iwokkel |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
32 from zope.interface import implements |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
33 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
34 from wokkel import pubsub |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
35 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
36 log = getLogger(__name__) |
2231 | 37 |
38 | |
39 PLUGIN_INFO = { | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
40 C.PI_NAME: "Events", |
2303
37887b5acb25
plugin events: changed import names to EVENTS uppercase for consistency with other plugins
Goffi <goffi@goffi.org>
parents:
2294
diff
changeset
|
41 C.PI_IMPORT_NAME: "EVENTS", |
2231 | 42 C.PI_TYPE: "EXP", |
43 C.PI_PROTOCOLS: [], | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
44 C.PI_DEPENDENCIES: [u"XEP-0060", u"INVITATION", u"LIST_INTEREST"], |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
45 C.PI_RECOMMENDATIONS: ["XEP-0277", "EMAIL_INVITATION"], |
2231 | 46 C.PI_MAIN: "Events", |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
47 C.PI_HANDLER: "yes", |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
48 C.PI_DESCRIPTION: _(u"""Experimental implementation of XMPP events management"""), |
2231 | 49 } |
50 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
51 NS_EVENT = "org.salut-a-toi.event:0" |
2231 | 52 |
53 | |
54 class Events(object): | |
55 """Q&D module to handle event attendance answer, experimentation only""" | |
56 | |
57 def __init__(self, host): | |
58 log.info(_(u"Event plugin initialization")) | |
59 self.host = host | |
60 self._p = self.host.plugins["XEP-0060"] | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
61 self._i = self.host.plugins.get("EMAIL_INVITATION") |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
62 self._b = self.host.plugins.get("XEP-0277") |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
63 self.host.plugins[u"INVITATION"].registerNamespace(NS_EVENT, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
64 self.register) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
65 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
66 "eventGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
67 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
68 in_sign="ssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
69 out_sign="(ia{ss})", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
70 method=self._eventGet, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
71 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
72 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
73 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
74 "eventCreate", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
75 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
76 in_sign="ia{ss}ssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
77 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
78 method=self._eventCreate, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
79 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
80 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
81 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
82 "eventModify", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
83 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
84 in_sign="sssia{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
85 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
86 method=self._eventModify, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
87 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
88 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
89 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
90 "eventsList", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
91 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
92 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
93 out_sign="aa{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
94 method=self._eventsList, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
95 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
96 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
97 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
98 "eventInviteeGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
99 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
100 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
101 out_sign="a{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
102 method=self._eventInviteeGet, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
103 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
104 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
105 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
106 "eventInviteeSet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
107 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
108 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
109 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
110 method=self._eventInviteeSet, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
111 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
112 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
113 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
114 "eventInviteesList", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
115 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
116 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
117 out_sign="a{sa{ss}}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
118 method=self._eventInviteesList, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
119 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
120 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
121 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
122 "eventInvite", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
123 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
124 in_sign="sssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
125 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
126 method=self._invite, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
127 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
128 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
129 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
130 "eventInviteByEmail", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
131 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
132 in_sign="ssssassssssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
133 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
134 method=self._inviteByEmail, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
135 async=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
136 ) |
2231 | 137 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
138 def getHandler(self, client): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
139 return EventsHandler(self) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
140 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
141 def _parseEventElt(self, event_elt): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
142 """Helper method to parse event element |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
143 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
144 @param (domish.Element): event_elt |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
145 @return (tupple[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
|
146 """ |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
147 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
|
148 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
|
149 except StopIteration: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
150 timestamp = -1 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
151 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
152 data = {} |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
153 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
154 for key in (u"name",): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
155 try: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
156 data[key] = event_elt[key] |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
157 except KeyError: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
158 continue |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
159 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
160 for elt_name in (u"description",): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
161 try: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
162 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
|
163 except StopIteration: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
164 continue |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
165 else: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
166 data[elt_name] = unicode(elt) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
167 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
168 for elt_name in (u"image", "background-image"): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
169 try: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
170 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
|
171 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
|
172 except StopIteration: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
173 continue |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
174 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
175 log.warning(_(u"no src found for image")) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
176 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
177 for uri_type in (u"invitees", u"blog"): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
178 try: |
2246
e8641b7718dc
plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
179 elt = next(event_elt.elements(NS_EVENT, uri_type)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
180 uri = data[uri_type + u"_uri"] = elt["uri"] |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
181 uri_data = xmpp_uri.parseXMPPUri(uri) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
182 if uri_data[u"type"] != u"pubsub": |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
183 raise ValueError |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
184 except StopIteration: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
185 log.warning(_(u"no {uri_type} element found!").format(uri_type=uri_type)) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
186 except KeyError: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
187 log.warning(_(u"incomplete {uri_type} element").format(uri_type=uri_type)) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
188 except ValueError: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
189 log.warning(_(u"bad {uri_type} element").format(uri_type=uri_type)) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
190 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
191 data[uri_type + u"_service"] = uri_data[u"path"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
192 data[uri_type + u"_node"] = uri_data[u"node"] |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
193 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
194 for meta_elt in event_elt.elements(NS_EVENT, "meta"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
195 key = meta_elt[u"name"] |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
196 if key in data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
197 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
198 u"Ignoring conflicting meta element: {xml}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
199 xml=meta_elt.toXml() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
200 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
201 ) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
202 continue |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
203 data[key] = unicode(meta_elt) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
204 if event_elt.link: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
205 link_elt = event_elt.link |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
206 data["service"] = link_elt["service"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
207 data["node"] = link_elt["node"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
208 data["item"] = link_elt["item"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
209 if event_elt.getAttribute("creator") == "true": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
210 data["creator"] = True |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
211 return timestamp, data |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
212 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
213 @defer.inlineCallbacks |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
214 def getEventElement(self, client, service, node, id_): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
215 """Retrieve event element |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
216 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
217 @param service(jid.JID): pubsub service |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
218 @param node(unicode): pubsub node |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
219 @param id_(unicode, None): event id |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
220 @return (domish.Element): event element |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
221 @raise exceptions.NotFound: no event element found |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
222 """ |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
223 if not id_: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
224 id_ = NS_EVENT |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
225 items, metadata = yield self._p.getItems(client, service, node, item_ids=[id_]) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
226 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
227 event_elt = next(items[0].elements(NS_EVENT, u"event")) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
228 except StopIteration: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
229 raise exceptions.NotFound(_(u"No event element has been found")) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
230 except IndexError: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
231 raise exceptions.NotFound(_(u"No event with this id has been found")) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
232 defer.returnValue(event_elt) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
233 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
234 def register(self, client, service, node, event_id, event_elt, creator=False): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
235 """register evenement in personal events list |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
236 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
237 @param service(jid.JID): pubsub service of the event |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
238 @param node(unicode): event node |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
239 @param event_id(unicode): event id |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
240 @param event_elt(domish.Element): event element |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
241 note that this element will be modified in place |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
242 @param creator(bool): True if client's profile is the creator of the node |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
243 """ |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
244 link_elt = event_elt.addElement("link") |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
245 link_elt["service"] = service.full() |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
246 link_elt["node"] = node |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
247 link_elt["item"] = event_id |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
248 return self.host.plugins[u'LIST_INTEREST'].registerPubsub( |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
249 client, NS_EVENT, service, node, event_id, creator, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
250 element=event_elt) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
251 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
252 def _eventGet(self, service, node, id_=u"", profile_key=C.PROF_KEY_NONE): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
253 service = jid.JID(service) if service else None |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
254 node = node if node else NS_EVENT |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
255 client = self.host.getClient(profile_key) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
256 return self.eventGet(client, service, node, id_) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
257 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
258 @defer.inlineCallbacks |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
259 def eventGet(self, client, service, node, id_=NS_EVENT): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
260 """Retrieve event data |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
261 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
262 @param service(unicode, None): PubSub service |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
263 @param node(unicode): PubSub node of the event |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
264 @param id_(unicode): id_ with even data |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
265 @return (tuple[int, dict[unicode, unicode]): event data: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
266 - timestamp of the event |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
267 - event metadata where key can be: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
268 location: location of the event |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
269 image: URL of a picture to use to represent event |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
270 background-image: URL of a picture to use in background |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
271 """ |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
272 event_elt = yield self.getEventElement(client, service, node, id_) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
273 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
274 defer.returnValue(self._parseEventElt(event_elt)) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
275 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
276 def _eventCreate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
277 self, timestamp, data, service, node, id_=u"", profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
278 ): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
279 service = jid.JID(service) if service else None |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
280 node = node or None |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
281 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
282 data[u"register"] = C.bool(data.get(u"register", C.BOOL_FALSE)) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
283 return self.eventCreate(client, timestamp, data, service, node, id_ or NS_EVENT) |
2231 | 284 |
285 @defer.inlineCallbacks | |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
286 def eventCreate(self, client, timestamp, data, service, node=None, event_id=NS_EVENT): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
287 """Create or replace an event |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
288 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
289 @param service(jid.JID, None): PubSub service |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
290 @param node(unicode, None): PubSub node of the event |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
291 None will create instant node. |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
292 @param event_id(unicode): 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
|
293 @param timestamp(timestamp, None) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
294 @param data(dict[unicode, unicode]): data to update |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
295 dict will be cleared, do a copy if data are still needed |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
296 key can be: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
297 - name: name of the event |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
298 - description: details |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
299 - image: main picture of the event |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
300 - background-image: image to use as background |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
301 - register: bool, True if we want to register the event in our local list |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
302 @return (unicode): created node |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
303 """ |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
304 if not event_id: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
305 raise ValueError(_(u"event_id must be set")) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
306 if not service: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
307 service = client.jid.userhostJID() |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
308 if not node: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
309 node = NS_EVENT + u"__" + shortuuid.uuid() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
310 event_elt = domish.Element((NS_EVENT, "event")) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
311 if timestamp is not None and timestamp != -1: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
312 formatted_date = utils.xmpp_date(timestamp) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
313 event_elt.addElement((NS_EVENT, "date"), content=formatted_date) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
314 register = data.pop("register", False) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
315 for key in (u"name",): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
316 if key in data: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
317 event_elt[key] = data.pop(key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
318 for key in (u"description",): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
319 if key in data: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
320 event_elt.addElement((NS_EVENT, key), content=data.pop(key)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
321 for key in (u"image", u"background-image"): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
322 if key in data: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
323 elt = event_elt.addElement((NS_EVENT, key)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
324 elt["src"] = data.pop(key) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
325 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
326 # we first create the invitees and blog nodes (if not specified in data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
327 for uri_type in (u"invitees", u"blog"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
328 key = uri_type + u"_uri" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
329 for to_delete in (u"service", u"node"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
330 k = uri_type + u"_" + to_delete |
2246
e8641b7718dc
plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
331 if k in data: |
e8641b7718dc
plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
332 del data[k] |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
333 if key not in data: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
334 # FIXME: affiliate invitees |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
335 uri_node = yield self._p.createNode(client, service) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
336 yield self._p.setConfiguration( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
337 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
338 service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
339 uri_node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
340 {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
341 ) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
342 uri_service = service |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
343 else: |
2246
e8641b7718dc
plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents:
2243
diff
changeset
|
344 uri = data.pop(key) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
345 uri_data = xmpp_uri.parseXMPPUri(uri) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
346 if uri_data[u"type"] != u"pubsub": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
347 raise ValueError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
348 _(u"The given URI is not valid: {uri}").format(uri=uri) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
349 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
350 uri_service = jid.JID(uri_data[u"path"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
351 uri_node = uri_data[u"node"] |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
352 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
353 elt = event_elt.addElement((NS_EVENT, uri_type)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
354 elt["uri"] = xmpp_uri.buildXMPPUri( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
355 "pubsub", path=uri_service.full(), node=uri_node |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
356 ) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
357 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
358 # remaining data are put in <meta> elements |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
359 for key in data.keys(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
360 elt = event_elt.addElement((NS_EVENT, "meta"), content=data.pop(key)) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
361 elt["name"] = key |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
362 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
363 item_elt = pubsub.Item(id=event_id, payload=event_elt) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
364 try: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
365 # TODO: check auto-create, no need to create node first if available |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
366 node = yield self._p.createNode(client, service, nodeIdentifier=node) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
367 except error.StanzaError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
368 if e.condition == u"conflict": |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
369 log.debug(_(u"requested node already exists")) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
370 |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2246
diff
changeset
|
371 yield self._p.publish(client, service, node, items=[item_elt]) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
372 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
373 if register: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
374 yield self.register(client, service, node, event_id, event_elt, creator=True) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
375 defer.returnValue(node) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
376 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
377 def _eventModify(self, service, node, id_, timestamp_update, data_update, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
378 profile_key=C.PROF_KEY_NONE): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
379 service = jid.JID(service) if service else None |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
380 if not node: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
381 raise ValueError(_(u"missing node")) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
382 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
383 return self.eventModify( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
384 client, service, node, id_ or NS_EVENT, timestamp_update or None, data_update |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
385 ) |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
386 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
387 @defer.inlineCallbacks |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
388 def eventModify( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
389 self, client, service, node, id_=NS_EVENT, timestamp_update=None, data_update=None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
390 ): |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
391 """Update an event |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
392 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
393 Similar as create instead that it update existing item instead of |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
394 creating or replacing it. Params are the same as for [eventCreate]. |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
395 """ |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
396 event_timestamp, event_metadata = yield self.eventGet(client, service, node, id_) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
397 new_timestamp = event_timestamp if timestamp_update is None else timestamp_update |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
398 new_data = event_metadata |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
399 if data_update: |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
400 for k, v in data_update.iteritems(): |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
401 new_data[k] = v |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
402 yield self.eventCreate(client, new_timestamp, new_data, service, node, id_) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
403 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
404 def _eventsListSerialise(self, events): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
405 for timestamp, data in events: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
406 data["date"] = unicode(timestamp) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
407 data["creator"] = C.boolConst(data.get("creator", False)) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
408 return [e[1] for e in events] |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
409 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
410 def _eventsList(self, service, node, profile): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
411 service = jid.JID(service) if service else None |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
412 node = node or None |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
413 client = self.host.getClient(profile) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
414 d = self.eventsList(client, service, node) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
415 d.addCallback(self._eventsListSerialise) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
416 return d |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
417 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
418 @defer.inlineCallbacks |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
419 def eventsList(self, client, service, node=None): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
420 """Retrieve list of registered events |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
421 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
422 @return list(tuple(int, dict)): list of events (timestamp + metadata) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
423 """ |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
424 items, metadata = yield self.host.plugins[u'LIST_INTEREST'].listInterests( |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
425 client, service, node, namespace=NS_EVENT) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
426 events = [] |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
427 for item in items: |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
428 try: |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
429 event_elt = next(item.interest.pubsub.elements(NS_EVENT, u"event")) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
430 except IndexError: |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
431 log.warning( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
432 _(u"No event found in item {item_id}").format(item_id=item["id"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
433 ) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
434 else: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
435 timestamp, data = self._parseEventElt(event_elt) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
436 events.append((timestamp, data)) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
437 defer.returnValue(events) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
438 |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
439 def _eventInviteeGet(self, service, node, profile_key): |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
440 service = jid.JID(service) if service else None |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
441 node = node if node else NS_EVENT |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
442 client = self.host.getClient(profile_key) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
443 return self.eventInviteeGet(client, service, node) |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
444 |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
445 @defer.inlineCallbacks |
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
446 def eventInviteeGet(self, client, service, node): |
2231 | 447 """Retrieve attendance from event node |
448 | |
449 @param service(unicode, None): PubSub service | |
450 @param node(unicode): PubSub node of the event | |
451 @return (dict): a dict with current attendance status, | |
452 an empty dict is returned if nothing has been answered yed | |
453 """ | |
454 try: | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
455 items, metadata = yield self._p.getItems( |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
456 client, service, node, item_ids=[client.jid.userhost()] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
457 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
458 event_elt = next(items[0].elements(NS_EVENT, u"invitee")) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
459 except (exceptions.NotFound, IndexError): |
2231 | 460 # no item found, event data are not set yet |
461 defer.returnValue({}) | |
462 data = {} | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
463 for key in (u"attend", u"guests"): |
2231 | 464 try: |
465 data[key] = event_elt[key] | |
466 except KeyError: | |
467 continue | |
468 defer.returnValue(data) | |
469 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
470 def _eventInviteeSet(self, service, node, event_data, profile_key): |
2231 | 471 service = jid.JID(service) if service else None |
472 node = node if node else NS_EVENT | |
473 client = self.host.getClient(profile_key) | |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
474 return self.eventInviteeSet(client, service, node, event_data) |
2231 | 475 |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
476 def eventInviteeSet(self, client, service, node, data): |
2231 | 477 """Set or update attendance data in event node |
478 | |
479 @param service(unicode, None): PubSub service | |
480 @param node(unicode): PubSub node of the event | |
481 @param data(dict[unicode, unicode]): data to update | |
482 key can be: | |
483 attend: one of "yes", "no", "maybe" | |
484 guests: an int | |
485 """ | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
486 event_elt = domish.Element((NS_EVENT, "invitee")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
487 for key in (u"attend", u"guests"): |
2231 | 488 try: |
489 event_elt[key] = data.pop(key) | |
490 except KeyError: | |
491 pass | |
492 item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt) | |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2246
diff
changeset
|
493 return self._p.publish(client, service, node, items=[item_elt]) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
494 |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
495 def _eventInviteesList(self, service, node, profile_key): |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
496 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
|
497 node = node if node else NS_EVENT |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
498 client = self.host.getClient(profile_key) |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
499 return self.eventInviteesList(client, service, node) |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
500 |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
501 @defer.inlineCallbacks |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
502 def eventInviteesList(self, client, service, node): |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
503 """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
|
504 |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
505 @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
|
506 @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
|
507 @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
|
508 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
|
509 """ |
2360
72cbb6478f97
plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents:
2303
diff
changeset
|
510 items, metadata = yield self._p.getItems(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
|
511 invitees = {} |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
512 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
|
513 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
514 event_elt = next(item.elements(NS_EVENT, u"invitee")) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
515 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
|
516 # no item found, event data are not set yet |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
517 log.warning(_( |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
518 u"no data found for {item_id} (service: {service}, node: {node})" |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
519 .format(item_id=item["id"], service=service, node=node))) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
520 else: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
521 data = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
522 for key in (u"attend", u"guests"): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
523 try: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
524 data[key] = event_elt[key] |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
525 except KeyError: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
526 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
527 invitees[item["id"]] = data |
2294
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
528 defer.returnValue(invitees) |
78048f002a3c
plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents:
2291
diff
changeset
|
529 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
530 def _invite(self, invitee_jid, service, node, item_id, profile): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
531 client = self.host.getClient(profile) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
532 service = jid.JID(service) if service else None |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
533 node = node or None |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
534 item_id = item_id or None |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
535 invitee_jid = jid.JID(invitee_jid) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
536 return self.invite(client, invitee_jid, service, node, item_id) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
537 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
538 @defer.inlineCallbacks |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
539 def invite(self, client, invitee_jid, service, node, item_id=NS_EVENT): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
540 """Invite an entity to the event |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
541 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
542 This will set permission to let the entity access everything needed |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
543 @pararm invitee_jid(jid.JID): entity to invite |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
544 @param service(jid.JID, None): pubsub service |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
545 None to use client's PEP |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
546 @param node(unicode): event node |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
547 @param item_id(unicode): event id |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
548 """ |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
549 if self._b is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
550 raise exceptions.FeatureNotFound( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
551 _(u'"XEP-0277" (blog) plugin is needed for this feature') |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
552 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
553 if item_id is None: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
554 item_id = NS_EVENT |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
555 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
556 # first we authorize our invitee to see the nodes of interest |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
557 yield self._p.setNodeAffiliations(client, service, node, {invitee_jid: u"member"}) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
558 log.debug(_(u"affiliation set on event node")) |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
559 __, event_data = yield self.eventGet(client, service, node, item_id) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
560 log.debug(_(u"got event data")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
561 invitees_service = jid.JID(event_data["invitees_service"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
562 invitees_node = event_data["invitees_node"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
563 blog_service = jid.JID(event_data["blog_service"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
564 blog_node = event_data["blog_node"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
565 yield self._p.setNodeAffiliations( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
566 client, invitees_service, invitees_node, {invitee_jid: u"publisher"} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
567 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
568 log.debug(_(u"affiliation set on invitee node")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
569 yield self._p.setNodeAffiliations( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
570 client, blog_service, blog_node, {invitee_jid: u"member"} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
571 ) |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
572 blog_items, __ = yield self._b.mbGet(client, blog_service, blog_node, None) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
573 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
574 for item in blog_items: |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
575 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
576 comments_service = jid.JID(item["comments_service"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
577 comments_node = item["comments_node"] |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
578 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
579 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
580 u"no comment service set for item {item_id}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
581 item_id=item["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
582 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
583 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
584 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
585 yield self._p.setNodeAffiliations( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
586 client, comments_service, comments_node, {invitee_jid: u"publisher"} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
587 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
588 log.debug(_(u"affiliation set on blog and comments nodes")) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
589 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
590 # now we send the invitation |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
591 pubsub_invitation = self.host.plugins[u'PUBSUB_INVITATION'] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
592 pubsub_invitation.sendPubsubInvitation(client, invitee_jid, service, node, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
593 item_id) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
594 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
595 def _inviteByEmail(self, service, node, id_=NS_EVENT, email=u"", emails_extra=None, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
596 name=u"", host_name=u"", language=u"", url_template=u"", |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
597 message_subject=u"", message_body=u"", |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
598 profile_key=C.PROF_KEY_NONE): |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
599 client = self.host.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
600 kwargs = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
601 u"profile": client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
602 u"emails_extra": [unicode(e) for e in emails_extra], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
603 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
604 for key in ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
605 "email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
606 "name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
607 "host_name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
608 "language", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
609 "url_template", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
610 "message_subject", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
611 "message_body", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
612 ): |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
613 value = locals()[key] |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
614 kwargs[key] = unicode(value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
615 return self.inviteByEmail( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
616 client, jid.JID(service) if service else None, node, id_ or NS_EVENT, **kwargs |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
617 ) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
618 |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
619 @defer.inlineCallbacks |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
620 def inviteByEmail(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
|
621 """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
|
622 |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
623 @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
|
624 @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
|
625 @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
|
626 """ |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
627 if self._i is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
628 raise exceptions.FeatureNotFound( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
629 _(u'"Invitations" plugin is needed for this feature') |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
630 ) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
631 if self._b is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
632 raise exceptions.FeatureNotFound( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
633 _(u'"XEP-0277" (blog) plugin is needed for this feature') |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
634 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
635 service = service or client.jid.userhostJID() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
636 event_uri = xmpp_uri.buildXMPPUri( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
637 "pubsub", path=service.full(), node=node, item=id_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
638 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
639 kwargs["extra"] = {u"event_uri": event_uri} |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
640 invitation_data = yield self._i.create(**kwargs) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
641 invitee_jid = invitation_data[u"jid"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
642 log.debug(_(u"invitation created")) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
643 # now that we have a jid, we can send normal invitation |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
644 yield self.invite(client, invitee_jid, service, node, id_) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
645 |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
646 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
647 class EventsHandler(XMPPHandler): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
648 implements(iwokkel.IDisco) |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
649 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
650 def __init__(self, plugin_parent): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
651 self.plugin_parent = plugin_parent |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
652 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
653 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
654 return [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
655 disco.DiscoFeature(NS_EVENT), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
656 ] |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
657 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
658 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
659 return [] |