Mercurial > libervia-backend
annotate sat/plugins/plugin_exp_invitation.py @ 3187:d92a144f3589
plugin download: use cache if dest_path is empty:
if dest_path is not set, the file will be downloaded in cache. A new name will be
generated using a hash of the uri. If the file is already downloded in cache, it won't be
downloaded again (in this case returned progress_id is an empty string).
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 26 Feb 2020 22:03:11 +0100 |
parents | 559a625a236b |
children | b57b5e42e894 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2231 | 3 |
4 # SAT plugin to detect language (experimental) | |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
2231 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
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 | 22 from sat.core.constants import Const as C |
23 from sat.core.log import getLogger | |
24 from twisted.internet import defer | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
25 from twisted.words.protocols.jabber import jid |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
26 from wokkel import disco, iwokkel |
3028 | 27 from zope.interface import implementer |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
28 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
29 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
30 log = getLogger(__name__) |
2231 | 31 |
32 | |
33 PLUGIN_INFO = { | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
34 C.PI_NAME: "Invitation", |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
35 C.PI_IMPORT_NAME: "INVITATION", |
2231 | 36 C.PI_TYPE: "EXP", |
37 C.PI_PROTOCOLS: [], | |
3028 | 38 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329"], |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
39 C.PI_RECOMMENDATIONS: [], |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
40 C.PI_MAIN: "Invitation", |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
41 C.PI_HANDLER: "yes", |
3028 | 42 C.PI_DESCRIPTION: _("Experimental handling of invitations"), |
2231 | 43 } |
44 | |
3028 | 45 NS_INVITATION = "https://salut-a-toi/protocol/invitation:0" |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
46 INVITATION = '/message/invitation[@xmlns="{ns_invit}"]'.format( |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
47 ns_invit=NS_INVITATION |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
48 ) |
3028 | 49 NS_INVITATION_LIST = NS_INVITATION + "#list" |
2231 | 50 |
51 | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
52 class Invitation(object): |
2231 | 53 |
54 def __init__(self, host): | |
3028 | 55 log.info(_("Invitation plugin initialization")) |
2231 | 56 self.host = host |
57 self._p = self.host.plugins["XEP-0060"] | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
58 # map from namespace of the invitation to callback handling it |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
59 self._ns_cb = {} |
2231 | 60 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
61 def getHandler(self, client): |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
62 return PubsubInvitationHandler(self) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
63 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
64 def registerNamespace(self, namespace, callback): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
65 """Register a callback for a namespace |
2243
5e12fc5ae52a
plugin events: separation of event node and invitees node
Goffi <goffi@goffi.org>
parents:
2231
diff
changeset
|
66 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
67 @param namespace(unicode): namespace handled |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
68 @param callback(callbable): method handling the invitation |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
69 For pubsub invitation, it will be called with following arguments: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
70 - client |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
71 - name(unicode, None): name of the event |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
72 - extra(dict): extra data |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
73 - service(jid.JID): pubsub service jid |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
74 - node(unicode): pubsub node |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
75 - item_id(unicode, None): pubsub item id |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
76 - item_elt(domish.Element): item of the invitation |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
77 For file sharing invitation, it will be called with following arguments: |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
78 - client |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
79 - name(unicode, None): name of the repository |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
80 - extra(dict): extra data |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
81 - service(jid.JID): service jid of the file repository |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
82 - repos_type(unicode): type of the repository, can be: |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
83 - files: generic file sharing |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
84 - photos: photos album |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
85 - namespace(unicode, None): namespace of the repository |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
86 - path(unicode, None): path of the repository |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
87 @raise exceptions.ConflictError: this namespace is already registered |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
88 """ |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
89 if namespace in self._ns_cb: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
90 raise exceptions.ConflictError( |
3028 | 91 "invitation namespace {namespace} is already register with {callback}" |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
92 .format(namespace=namespace, callback=self._ns_cb[namespace])) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
93 self._ns_cb[namespace] = callback |
2231 | 94 |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
95 def _generateBaseInvitation(self, client, invitee_jid, name, extra): |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
96 """Generate common mess_data end invitation_elt |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
97 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
98 @param invitee_jid(jid.JID): entitee to send invitation to |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
99 @param name(unicode, None): name of the shared repository |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
100 @param extra(dict, None): extra data, where key can be: |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
101 - thumb_url: URL of a thumbnail |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
102 @return (tuple[dict, domish.Element): mess_data and invitation_elt |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
103 """ |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
104 mess_data = { |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
105 "from": client.jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
106 "to": invitee_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
107 "uid": "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
108 "message": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
109 "type": C.MESS_TYPE_CHAT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
110 "subject": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
111 "extra": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
112 } |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
113 client.generateMessageXML(mess_data) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
114 invitation_elt = mess_data["xml"].addElement("invitation", NS_INVITATION) |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
115 if name is not None: |
3028 | 116 invitation_elt["name"] = name |
117 thumb_url = extra.get('thumb_url') | |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
118 if thumb_url: |
3028 | 119 if not thumb_url.startswith('http'): |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
120 log.warning( |
3028 | 121 "only http URLs are allowed for thumbnails, got {url}, ignoring" |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
122 .format(url=thumb_url)) |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
123 else: |
3028 | 124 invitation_elt['thumb_url'] = thumb_url |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
125 return mess_data, invitation_elt |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
126 |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
127 def sendPubsubInvitation(self, client, invitee_jid, service, node, |
2941
83cbd4545274
plugin events: fixed invitation + set name and thumb_url from event element
Goffi <goffi@goffi.org>
parents:
2931
diff
changeset
|
128 item_id, name, extra): |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
129 """Send an pubsub invitation in a <message> stanza |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
130 |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
131 @param invitee_jid(jid.JID): entitee to send invitation to |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
132 @param service(jid.JID): pubsub service |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
133 @param node(unicode): pubsub node |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
134 @param item_id(unicode): pubsub id |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
135 @param name(unicode, None): see [_generateBaseInvitation] |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
136 @param extra(dict, None): see [_generateBaseInvitation] |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
137 """ |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
138 if extra is None: |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
139 extra = {} |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
140 mess_data, invitation_elt = self._generateBaseInvitation( |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
141 client, invitee_jid, name, extra) |
3028 | 142 pubsub_elt = invitation_elt.addElement("pubsub") |
143 pubsub_elt["service"] = service.full() | |
144 pubsub_elt["node"] = node | |
145 pubsub_elt["item"] = item_id | |
146 return client.send(mess_data["xml"]) | |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
147 |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
148 def sendFileSharingInvitation(self, client, invitee_jid, service, repos_type=None, |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
149 namespace=None, path=None, name=None, extra=None): |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
150 """Send a file sharing invitation in a <message> stanza |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
151 |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
152 @param invitee_jid(jid.JID): entitee to send invitation to |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
153 @param service(jid.JID): file sharing service |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
154 @param repos_type(unicode, None): type of files repository, can be: |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
155 - None, "files": files sharing |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
156 - "photos": photos album |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
157 @param namespace(unicode, None): namespace of the shared repository |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
158 @param path(unicode, None): path of the shared repository |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
159 @param name(unicode, None): see [_generateBaseInvitation] |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
160 @param extra(dict, None): see [_generateBaseInvitation] |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
161 """ |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
162 if extra is None: |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
163 extra = {} |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
164 mess_data, invitation_elt = self._generateBaseInvitation( |
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
165 client, invitee_jid, name, extra) |
3028 | 166 file_sharing_elt = invitation_elt.addElement("file_sharing") |
167 file_sharing_elt["service"] = service.full() | |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
168 if repos_type is not None: |
3028 | 169 if repos_type not in ("files", "photos"): |
170 msg = "unknown repository type: {repos_type}".format( | |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
171 repos_type=repos_type) |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
172 log.warning(msg) |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
173 raise exceptions.DateError(msg) |
3028 | 174 file_sharing_elt["type"] = repos_type |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
175 if namespace is not None: |
3028 | 176 file_sharing_elt["namespace"] = namespace |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
177 if path is not None: |
3028 | 178 file_sharing_elt["path"] = path |
179 return client.send(mess_data["xml"]) | |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
180 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
181 @defer.inlineCallbacks |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
182 def _parsePubsubElt(self, client, pubsub_elt): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
183 try: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
184 service = jid.JID(pubsub_elt["service"]) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
185 node = pubsub_elt["node"] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
186 item_id = pubsub_elt.getAttribute("item") |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
187 except (RuntimeError, KeyError): |
3028 | 188 log.warning(_("Bad invitation, ignoring")) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
189 raise exceptions.DataError |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
190 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
191 try: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
192 items, metadata = yield self._p.getItems(client, service, node, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
193 item_ids=[item_id]) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
194 except Exception as e: |
3028 | 195 log.warning(_("Can't get item linked with invitation: {reason}").format( |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
196 reason=e)) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
197 try: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
198 item_elt = items[0] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
199 except IndexError: |
3028 | 200 log.warning(_("Invitation was linking to a non existing item")) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
201 raise exceptions.DataError |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
202 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
203 try: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
204 namespace = item_elt.firstChildElement().uri |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
205 except Exception as e: |
3028 | 206 log.warning(_("Can't retrieve namespace of invitation: {reason}").format( |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
207 reason = e)) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
208 raise exceptions.DataError |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
209 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
210 args = [service, node, item_id, item_elt] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
211 defer.returnValue((namespace, args)) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
212 |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
213 def _parseFileSharingElt(self, client, file_sharing_elt): |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
214 try: |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
215 service = jid.JID(file_sharing_elt["service"]) |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
216 except (RuntimeError, KeyError): |
3028 | 217 log.warning(_("Bad invitation, ignoring")) |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
218 raise exceptions.DataError |
3028 | 219 repos_type = file_sharing_elt.getAttribute("type", "files") |
220 namespace = file_sharing_elt.getAttribute("namespace") | |
221 path = file_sharing_elt.getAttribute("path") | |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
222 args = [service, repos_type, namespace, path] |
3028 | 223 ns_fis = self.host.getNamespace("fis") |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
224 return ns_fis, args |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
225 |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
226 @defer.inlineCallbacks |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
227 def onInvitation(self, message_elt, client): |
3028 | 228 log.debug("invitation received [{profile}]".format(profile=client.profile)) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
229 invitation_elt = message_elt.invitation |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
230 |
3028 | 231 name = invitation_elt.getAttribute("name") |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
232 extra = {} |
3028 | 233 if invitation_elt.hasAttribute("thumb_url"): |
234 extra['thumb_url'] = invitation_elt['thumb_url'] | |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
235 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
236 for elt in invitation_elt.elements(): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
237 if elt.uri != NS_INVITATION: |
3028 | 238 log.warning("unexpected element: {xml}".format(xml=elt.toXml())) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
239 continue |
3028 | 240 if elt.name == "pubsub": |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
241 method = self._parsePubsubElt |
3028 | 242 elif elt.name == "file_sharing": |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
243 method = self._parseFileSharingElt |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
244 else: |
3028 | 245 log.warning("not implemented invitation element: {xml}".format( |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
246 xml = elt.toXml())) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
247 continue |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
248 try: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
249 namespace, args = yield method(client, elt) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
250 except exceptions.DataError: |
3028 | 251 log.warning("Can't parse invitation element: {xml}".format( |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
252 xml = elt.toXml())) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
253 continue |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
254 |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
255 try: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
256 cb = self._ns_cb[namespace] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
257 except KeyError: |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
258 log.warning(_( |
3028 | 259 'No handler for namespace "{namespace}", invitation ignored') |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
260 .format(namespace=namespace)) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
261 else: |
2931
b256e90612d0
plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
262 cb(client, name, extra, *args) |
2287
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
263 |
ea869f30f204
plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
264 |
3028 | 265 @implementer(iwokkel.IDisco) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
266 class PubsubInvitationHandler(XMPPHandler): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
267 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
268 def __init__(self, plugin_parent): |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
269 self.plugin_parent = plugin_parent |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
270 |
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
271 def connectionInitialized(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
272 self.xmlstream.addObserver( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
273 INVITATION, self.plugin_parent.onInvitation, client=self.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
274 ) |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
275 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
276 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
277 return [ |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
278 disco.DiscoFeature(NS_INVITATION), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
279 ] |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
280 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
281 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
2616
1cc88adb5142
plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents:
2612
diff
changeset
|
282 return [] |