annotate sat/plugins/plugin_exp_events.py @ 2757:1f612547fb2e

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