annotate sat/plugins/plugin_exp_events.py @ 3405:ecdb3728749e

plugin XEP-0353: Jingle Message Initiation implementation: This plugin uses the new `XEP-0166_initiate` trigger to initiate a Jingle session with messages if the peer jid has no resource specified. On reception, if the sender is not in our roster, a confirmation is requested to user to avoid leaking presence and IP. If user refuses the session for somebody not in roster, nothing is sent at all (the request is just ignored).
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:15 +0100
parents 559a625a236b
children 12dc234f698c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin to detect language (experimental)
3136
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3083
diff changeset
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
20 import shortuuid
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.constants import Const as C
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
32 from zope.interface import implementer
2616
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
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_TYPE: "EXP",
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_PROTOCOLS: [],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
44 C.PI_DEPENDENCIES: ["XEP-0060", "INVITATION", "LIST_INTEREST"],
2912
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
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
48 C.PI_DESCRIPTION: _("""Experimental implementation of XMPP events management"""),
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 }
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 class Events(object):
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 """Q&D module to handle event attendance answer, experimentation only"""
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
58 log.info(_("Event plugin initialization"))
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.host = host
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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")
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
63 self.host.registerNamespace("event", NS_EVENT)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
64 self.host.plugins["INVITATION"].registerNamespace(NS_EVENT,
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
65 self.register)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
66 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
67 "eventGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
68 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
69 in_sign="ssss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
70 out_sign="(ia{ss})",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
71 method=self._eventGet,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
72 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
73 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
74 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
75 "eventCreate",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
76 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
77 in_sign="ia{ss}ssss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
78 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
79 method=self._eventCreate,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
80 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
81 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
82 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
83 "eventModify",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
84 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
85 in_sign="sssia{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
86 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
87 method=self._eventModify,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
88 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
89 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
90 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
91 "eventsList",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
92 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
93 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
94 out_sign="aa{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
95 method=self._eventsList,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
96 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
97 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
98 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
99 "eventInviteeGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
100 ".plugin",
3083
3c924cb207d9 plugin events: fixed eventInviteeGet signature
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
101 in_sign="ssss",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
102 out_sign="a{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
103 method=self._eventInviteeGet,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
104 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
105 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
106 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
107 "eventInviteeSet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
108 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
109 in_sign="ssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
110 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
111 method=self._eventInviteeSet,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
112 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
113 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
114 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
115 "eventInviteesList",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
116 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
117 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
118 out_sign="a{sa{ss}}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
119 method=self._eventInviteesList,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
120 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
121 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
122 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
123 "eventInvite",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
124 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
125 in_sign="sssss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
126 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
127 method=self._invite,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
128 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
129 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
130 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
131 "eventInviteByEmail",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
132 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
133 in_sign="ssssassssssss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
134 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
135 method=self._inviteByEmail,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
136 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
137 )
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
139 def getHandler(self, client):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
140 return EventsHandler(self)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
141
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
142 def _parseEventElt(self, event_elt):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
143 """Helper method to parse event element
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
144
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
145 @param (domish.Element): event_elt
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
146 @return (tuple[int, dict[unicode, unicode]): timestamp, event_data
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
147 """
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
148 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
149 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
150 except StopIteration:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
151 timestamp = -1
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
152
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
153 data = {}
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
154
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
155 for key in ("name",):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
156 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
157 data[key] = event_elt[key]
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
158 except KeyError:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
159 continue
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
160
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
161 for elt_name in ("description",):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
162 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
163 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
164 except StopIteration:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
165 continue
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
166 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
167 data[elt_name] = str(elt)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
168
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
169 for elt_name in ("image", "background-image"):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
170 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
171 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
172 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
173 except StopIteration:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
174 continue
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
175 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
176 log.warning(_("no src found for image"))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
177
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
178 for uri_type in ("invitees", "blog"):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
179 try:
2246
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
180 elt = next(event_elt.elements(NS_EVENT, uri_type))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
181 uri = data[uri_type + "_uri"] = elt["uri"]
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
182 uri_data = xmpp_uri.parseXMPPUri(uri)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
183 if uri_data["type"] != "pubsub":
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
184 raise ValueError
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
185 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
186 log.warning(_("no {uri_type} element found!").format(uri_type=uri_type))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
187 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
188 log.warning(_("incomplete {uri_type} element").format(uri_type=uri_type))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
189 except ValueError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
190 log.warning(_("bad {uri_type} element").format(uri_type=uri_type))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
191 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
192 data[uri_type + "_service"] = uri_data["path"]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
193 data[uri_type + "_node"] = uri_data["node"]
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
194
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
195 for meta_elt in event_elt.elements(NS_EVENT, "meta"):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
196 key = meta_elt["name"]
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
197 if key in data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
198 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
199 "Ignoring conflicting meta element: {xml}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
200 xml=meta_elt.toXml()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
201 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
202 )
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
203 continue
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
204 data[key] = str(meta_elt)
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
205 if event_elt.link:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
206 link_elt = event_elt.link
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
207 data["service"] = link_elt["service"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
208 data["node"] = link_elt["node"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
209 data["item"] = link_elt["item"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
210 if event_elt.getAttribute("creator") == "true":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
211 data["creator"] = True
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
212 return timestamp, data
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
213
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
214 @defer.inlineCallbacks
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
215 def getEventElement(self, client, service, node, id_):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
216 """Retrieve event element
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
217
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
218 @param service(jid.JID): pubsub service
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
219 @param node(unicode): pubsub node
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
220 @param id_(unicode, None): event id
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
221 @return (domish.Element): event element
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
222 @raise exceptions.NotFound: no event element found
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
223 """
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
224 if not id_:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
225 id_ = NS_EVENT
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
226 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
227 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
228 event_elt = next(items[0].elements(NS_EVENT, "event"))
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
229 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
230 raise exceptions.NotFound(_("No event element has been found"))
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
231 except IndexError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
232 raise exceptions.NotFound(_("No event with this id has been found"))
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
233 defer.returnValue(event_elt)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
234
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
235 def register(self, client, name, extra, service, node, event_id, item_elt,
2931
b256e90612d0 plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
236 creator=False):
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
237 """Register evenement in personal events list
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
238
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
239 @param service(jid.JID): pubsub service of the event
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
240 @param node(unicode): event node
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
241 @param event_id(unicode): event id
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
242 @param event_elt(domish.Element): event element
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
243 note that this element will be modified in place
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
244 @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
245 """
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
246 event_elt = item_elt.event
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
247 link_elt = event_elt.addElement("link")
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
248 link_elt["service"] = service.full()
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
249 link_elt["node"] = node
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
250 link_elt["item"] = event_id
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
251 __, event_data = self._parseEventElt(event_elt)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
252 name = event_data.get('name')
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
253 if 'image' in event_data:
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
254 extra = {'thumb_url': event_data['image']}
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
255 else:
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
256 extra = None
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
257 return self.host.plugins['LIST_INTEREST'].registerPubsub(
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
258 client, NS_EVENT, service, node, event_id, creator,
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
259 name=name, element=event_elt, extra=extra)
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
260
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
261 def _eventGet(self, service, node, id_="", profile_key=C.PROF_KEY_NONE):
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
262 service = jid.JID(service) if service else None
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
263 node = node if node else NS_EVENT
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
264 client = self.host.getClient(profile_key)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
265 return self.eventGet(client, service, node, id_)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
266
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
267 @defer.inlineCallbacks
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
268 def eventGet(self, client, service, node, id_=NS_EVENT):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
269 """Retrieve event data
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
270
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
271 @param service(unicode, None): PubSub service
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
272 @param node(unicode): PubSub node of the event
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
273 @param id_(unicode): id_ with even data
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
274 @return (tuple[int, dict[unicode, unicode]): event data:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
275 - timestamp of the event
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
276 - event metadata where key can be:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
277 location: location of the event
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
278 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
279 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
280 """
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
281 event_elt = yield self.getEventElement(client, service, node, id_)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
282
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
283 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
284
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
285 def _eventCreate(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
286 self, timestamp, data, service, node, id_="", profile_key=C.PROF_KEY_NONE
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
287 ):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
288 service = jid.JID(service) if service else None
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
289 node = node or None
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
290 client = self.host.getClient(profile_key)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
291 data["register"] = C.bool(data.get("register", C.BOOL_FALSE))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
292 return self.eventCreate(client, timestamp, data, service, node, id_ or NS_EVENT)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
293
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 @defer.inlineCallbacks
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
295 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
296 """Create or replace an event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
297
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
298 @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
299 @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
300 None will create instant node.
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
301 @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
302 @param timestamp(timestamp, None)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
303 @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
304 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
305 key can be:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
306 - name: name of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
307 - description: details
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
308 - image: main picture of the event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
309 - background-image: image to use as background
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
310 - 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
311 @return (unicode): created node
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
312 """
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
313 if not event_id:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
314 raise ValueError(_("event_id must be set"))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
315 if not service:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
316 service = client.jid.userhostJID()
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
317 if not node:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
318 node = NS_EVENT + "__" + shortuuid.uuid()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
319 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
320 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
321 formatted_date = utils.xmpp_date(timestamp)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
322 event_elt.addElement((NS_EVENT, "date"), content=formatted_date)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
323 register = data.pop("register", False)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
324 for key in ("name",):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
325 if key in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
326 event_elt[key] = data.pop(key)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
327 for key in ("description",):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
328 if key in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
329 event_elt.addElement((NS_EVENT, key), content=data.pop(key))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
330 for key in ("image", "background-image"):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
331 if key in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
332 elt = event_elt.addElement((NS_EVENT, key))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
333 elt["src"] = data.pop(key)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
334
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
335 # we first create the invitees and blog nodes (if not specified in data)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
336 for uri_type in ("invitees", "blog"):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
337 key = uri_type + "_uri"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
338 for to_delete in ("service", "node"):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
339 k = uri_type + "_" + to_delete
2246
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
340 if k in data:
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
341 del data[k]
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
342 if key not in data:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
343 # FIXME: affiliate invitees
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
344 uri_node = yield self._p.createNode(client, service)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
345 yield self._p.setConfiguration(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
346 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
347 service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
348 uri_node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
349 {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
350 )
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
351 uri_service = service
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
352 else:
2246
e8641b7718dc plugin events: fixed blog/invitees uri handling
Goffi <goffi@goffi.org>
parents: 2243
diff changeset
353 uri = data.pop(key)
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
354 uri_data = xmpp_uri.parseXMPPUri(uri)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
355 if uri_data["type"] != "pubsub":
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
356 raise ValueError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
357 _("The given URI is not valid: {uri}").format(uri=uri)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
358 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
359 uri_service = jid.JID(uri_data["path"])
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
360 uri_node = uri_data["node"]
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
361
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
362 elt = event_elt.addElement((NS_EVENT, uri_type))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
363 elt["uri"] = xmpp_uri.buildXMPPUri(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
364 "pubsub", path=uri_service.full(), node=uri_node
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
365 )
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
366
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
367 # remaining data are put in <meta> elements
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
368 for key in list(data.keys()):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
369 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
370 elt["name"] = key
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
371
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
372 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
373 try:
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
374 # 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
375 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
376 except error.StanzaError as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
377 if e.condition == "conflict":
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
378 log.debug(_("requested node already exists"))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
379
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
380 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
381
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
382 if register:
2931
b256e90612d0 plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
383 yield self.register(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
384 client, None, {}, service, node, event_id, item_elt, creator=True)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
385 defer.returnValue(node)
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
386
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
387 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
388 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
389 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
390 if not node:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
391 raise ValueError(_("missing node"))
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
392 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
393 return self.eventModify(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
394 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
395 )
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
396
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
397 @defer.inlineCallbacks
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
398 def eventModify(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
399 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
400 ):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
401 """Update an event
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
402
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
403 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
404 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
405 """
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
406 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
407 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
408 new_data = event_metadata
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
409 if data_update:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
410 for k, v in data_update.items():
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
411 new_data[k] = v
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
412 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
413
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
414 def _eventsListSerialise(self, events):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
415 for timestamp, data in events:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
416 data["date"] = str(timestamp)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
417 data["creator"] = C.boolConst(data.get("creator", False))
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
418 return [e[1] for e in events]
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
419
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
420 def _eventsList(self, service, node, profile):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
421 service = jid.JID(service) if service else None
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
422 node = node or None
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
423 client = self.host.getClient(profile)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
424 d = self.eventsList(client, service, node)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
425 d.addCallback(self._eventsListSerialise)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
426 return d
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
427
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
428 @defer.inlineCallbacks
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
429 def eventsList(self, client, service, node=None):
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
430 """Retrieve list of registered events
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
431
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
432 @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
433 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
434 items, metadata = yield self.host.plugins['LIST_INTEREST'].listInterests(
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
435 client, service, node, namespace=NS_EVENT)
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
436 events = []
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
437 for item in items:
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
438 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
439 event_elt = next(item.interest.pubsub.elements(NS_EVENT, "event"))
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
440 except StopIteration:
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
441 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
442 _("No event found in item {item_id}, ignoring").format(
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
443 item_id=item["id"])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
444 )
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
445 else:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
446 timestamp, data = self._parseEventElt(event_elt)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
447 events.append((timestamp, data))
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
448 defer.returnValue(events)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
449
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
450 def _eventInviteeGet(self, service, node, invitee_jid_s, profile_key):
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
451 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
452 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
453 client = self.host.getClient(profile_key)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
454 invitee_jid = jid.JID(invitee_jid_s) if invitee_jid_s else None
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
455 return self.eventInviteeGet(client, service, node, invitee_jid)
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
456
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
457 @defer.inlineCallbacks
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
458 def eventInviteeGet(self, client, service, node, invitee_jid=None):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
459 """Retrieve attendance from event node
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
460
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
461 @param service(unicode, None): PubSub service
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
462 @param node(unicode): PubSub node of the event's invitees
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
463 @param invitee_jid(jid.JId, None): jid of the invitee to retrieve (None to
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
464 retrieve profile's invitation). The bare jid correspond to the PubSub item id.
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
465 @return (dict): a dict with current attendance status,
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
466 an empty dict is returned if nothing has been answered yed
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
467 """
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
468 if invitee_jid is None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
469 invitee_jid = client.jid
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
470 try:
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
471 items, metadata = yield self._p.getItems(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
472 client, service, node, item_ids=[invitee_jid.userhost()]
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
473 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
474 event_elt = next(items[0].elements(NS_EVENT, "invitee"))
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
475 except (exceptions.NotFound, IndexError):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
476 # no item found, event data are not set yet
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
477 defer.returnValue({})
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
478 data = {}
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
479 for key in ("attend", "guests"):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
480 try:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
481 data[key] = event_elt[key]
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
482 except KeyError:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
483 continue
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
484 defer.returnValue(data)
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
485
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
486 def _eventInviteeSet(self, service, node, event_data, profile_key):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
487 service = jid.JID(service) if service else None
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
488 node = node if node else NS_EVENT
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
489 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
490 return self.eventInviteeSet(client, service, node, event_data)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
491
2243
5e12fc5ae52a plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents: 2231
diff changeset
492 def eventInviteeSet(self, client, service, node, data):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
493 """Set or update attendance data in event node
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
494
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
495 @param service(unicode, None): PubSub service
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
496 @param node(unicode): PubSub node of the event
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 @param data(dict[unicode, unicode]): data to update
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 key can be:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
499 attend: one of "yes", "no", "maybe"
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 guests: an int
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
501 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
502 event_elt = domish.Element((NS_EVENT, "invitee"))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
503 for key in ("attend", "guests"):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
504 try:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
505 event_elt[key] = data.pop(key)
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
506 except KeyError:
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
507 pass
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
508 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
509 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
510
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 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
512 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
513 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
514 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
515 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
516
78048f002a3c plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents: 2291
diff changeset
517 @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
518 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
519 """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
520
78048f002a3c plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents: 2291
diff changeset
521 @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
522 @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
523 @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
524 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
525 """
2360
72cbb6478f97 plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents: 2303
diff changeset
526 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
527 invitees = {}
78048f002a3c plugin events: added eventInviteesList method to get all R.S.V.P. at once.
Goffi <goffi@goffi.org>
parents: 2291
diff changeset
528 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
529 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
530 event_elt = next(item.elements(NS_EVENT, "invitee"))
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
531 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
532 # 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
533 log.warning(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
534 "no data found for {item_id} (service: {service}, node: {node})"
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
535 .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
536 else:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
537 data = {}
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
538 for key in ("attend", "guests"):
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
539 try:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
540 data[key] = event_elt[key]
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
541 except KeyError:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
542 continue
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
543 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
544 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
545
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
546 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
547 client = self.host.getClient(profile)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
548 service = jid.JID(service) if service else None
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
549 node = node or None
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
550 item_id = item_id or None
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
551 invitee_jid = jid.JID(invitee_jid)
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
552 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
553
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
554 @defer.inlineCallbacks
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
555 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
556 """Invite an entity to the event
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
557
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
558 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
559 @pararm invitee_jid(jid.JID): entity to invite
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
560 @param service(jid.JID, None): pubsub service
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
561 None to use client's PEP
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
562 @param node(unicode): event node
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
563 @param item_id(unicode): event id
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
564 """
2931
b256e90612d0 plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
565 # FIXME: handle name and extra
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
566 name = ''
2931
b256e90612d0 plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
567 extra = {}
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
568 if self._b is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
569 raise exceptions.FeatureNotFound(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
570 _('"XEP-0277" (blog) plugin is needed for this feature')
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
571 )
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
572 if item_id is None:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
573 item_id = NS_EVENT
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
574
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
575 # first we authorize our invitee to see the nodes of interest
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
576 yield self._p.setNodeAffiliations(client, service, node, {invitee_jid: "member"})
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
577 log.debug(_("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
578 __, event_data = yield self.eventGet(client, service, node, item_id)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
579 log.debug(_("got event data"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
580 invitees_service = jid.JID(event_data["invitees_service"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
581 invitees_node = event_data["invitees_node"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
582 blog_service = jid.JID(event_data["blog_service"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
583 blog_node = event_data["blog_node"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
584 yield self._p.setNodeAffiliations(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
585 client, invitees_service, invitees_node, {invitee_jid: "publisher"}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
586 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
587 log.debug(_("affiliation set on invitee node"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
588 yield self._p.setNodeAffiliations(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
589 client, blog_service, blog_node, {invitee_jid: "member"}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
590 )
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
591 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
592
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
593 for item in blog_items:
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
594 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
595 comments_service = jid.JID(item["comments_service"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
596 comments_node = item["comments_node"]
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
597 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
598 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
599 "no comment service set for item {item_id}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
600 item_id=item["id"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
601 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
602 )
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
603 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
604 yield self._p.setNodeAffiliations(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
605 client, comments_service, comments_node, {invitee_jid: "publisher"}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
606 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
607 log.debug(_("affiliation set on blog and comments nodes"))
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
608
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
609 # now we send the invitation
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
610 pubsub_invitation = self.host.plugins['INVITATION']
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
611 pubsub_invitation.sendPubsubInvitation(client, invitee_jid, service, node,
2941
83cbd4545274 plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents: 2935
diff changeset
612 item_id, name, extra)
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
613
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
614 def _inviteByEmail(self, service, node, id_=NS_EVENT, email="", emails_extra=None,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
615 name="", host_name="", language="", url_template="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
616 message_subject="", message_body="",
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
617 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
618 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
619 kwargs = {
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
620 "profile": client.profile,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
621 "emails_extra": [str(e) for e in emails_extra],
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
622 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
623 for key in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
624 "email",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
625 "name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
626 "host_name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
627 "language",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
628 "url_template",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
629 "message_subject",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
630 "message_body",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
631 ):
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
632 value = locals()[key]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
633 kwargs[key] = str(value)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
634 return self.inviteByEmail(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
635 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
636 )
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
637
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
638 @defer.inlineCallbacks
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
639 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
640 """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
641
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
642 @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
643 @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
644 @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
645 """
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
646 if self._i is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
647 raise exceptions.FeatureNotFound(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
648 _('"Invitations" plugin is needed for this feature')
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
649 )
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
650 if self._b is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
651 raise exceptions.FeatureNotFound(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
652 _('"XEP-0277" (blog) plugin is needed for this feature')
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
653 )
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
654 service = service or client.jid.userhostJID()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
655 event_uri = xmpp_uri.buildXMPPUri(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
656 "pubsub", path=service.full(), node=node, item=id_
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
657 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
658 kwargs["extra"] = {"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
659 invitation_data = yield self._i.create(**kwargs)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
660 invitee_jid = invitation_data["jid"]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
661 log.debug(_("invitation created"))
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
662 # 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
663 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
664
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
665
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
666 @implementer(iwokkel.IDisco)
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
667 class EventsHandler(XMPPHandler):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
668
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
669 def __init__(self, plugin_parent):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
670 self.plugin_parent = plugin_parent
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
671
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
672 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
673 return [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
674 disco.DiscoFeature(NS_EVENT),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
675 ]
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
676
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
677 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
678 return []