annotate libervia/backend/plugins/plugin_exp_invitation.py @ 4272:89a0999884ac default tip @

cli (list/set): add "--comments" argument.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:46:55 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3351
diff changeset
3 # SàT plugin to manage invitations
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3462
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # 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
8 # the Free Software Foundation, either version 3 of the License, or
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # 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
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
19 from typing import Optional
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
20 from zope.interface import implementer
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
21 from twisted.internet import defer
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
22 from twisted.words.protocols.jabber import jid
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
23 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
24 from wokkel import disco, iwokkel
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
27 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
29 from libervia.backend.core.xmpp import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
30 from libervia.backend.tools import utils
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
31
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
32 log = getLogger(__name__)
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 PLUGIN_INFO = {
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
36 C.PI_NAME: "Invitation",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
37 C.PI_IMPORT_NAME: "INVITATION",
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_TYPE: "EXP",
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_PROTOCOLS: [],
3781
e2a1ac1afb38 plugin invitation: use `store` hint to be sure that the invitation is archived
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
40 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329", "XEP-0334", "LIST_INTEREST"],
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
41 C.PI_RECOMMENDATIONS: ["EMAIL_INVITATION"],
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
42 C.PI_MAIN: "Invitation",
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
43 C.PI_HANDLER: "yes",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
44 C.PI_DESCRIPTION: _("Experimental handling of invitations"),
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 }
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
47 NS_INVITATION = "https://salut-a-toi/protocol/invitation:0"
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
48 INVITATION = '/message/invitation[@xmlns="{ns_invit}"]'.format(ns_invit=NS_INVITATION)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
49 NS_INVITATION_LIST = NS_INVITATION + "#list"
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
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
52 class Invitation(object):
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
55 log.info(_("Invitation plugin initialization"))
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.host = host
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self._p = self.host.plugins["XEP-0060"]
3781
e2a1ac1afb38 plugin invitation: use `store` hint to be sure that the invitation is archived
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
58 self._h = self.host.plugins["XEP-0334"]
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
59 # 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
60 self._ns_cb = {}
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
62 def get_handler(self, client):
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
63 return PubsubInvitationHandler(self)
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
64
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
65 def register_namespace(self, namespace, callback):
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
66 """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
67
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
68 @param namespace(unicode): namespace handled
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
69 @param callback(callbable): method handling the invitation
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
70 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
71 - 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
72 - 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
73 - extra(dict): extra data
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
74 - service(jid.JID): pubsub service jid
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
75 - node(unicode): pubsub node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
76 - item_id(unicode, None): pubsub item id
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
77 - 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
78 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
79 - 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
80 - 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
81 - 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
82 - 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
83 - 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
84 - 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
85 - 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
86 - 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
87 - 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
88 @raise exceptions.ConflictError: this namespace is already registered
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
89 """
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
90 if namespace in self._ns_cb:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
91 raise exceptions.ConflictError(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
92 "invitation namespace {namespace} is already register with {callback}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
93 namespace=namespace, callback=self._ns_cb[namespace]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
94 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
95 )
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
96 self._ns_cb[namespace] = callback
2231
230fc5b609a8 plugin event: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
98 def _generate_base_invitation(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
99 """Generate common mess_data end invitation_elt
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
100
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
101 @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
102 @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
103 @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
104 - 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
105 @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
106 """
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
107 mess_data = {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
108 "from": client.jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
109 "to": invitee_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
110 "uid": "",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
111 "message": {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
112 "type": C.MESS_TYPE_CHAT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
113 "subject": {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
114 "extra": {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
115 }
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
116 client.generate_message_xml(mess_data)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
117 self._h.add_hint_elements(mess_data["xml"], [self._h.HINT_STORE])
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
118 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
119 if name is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
120 invitation_elt["name"] = name
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
121 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
122 if thumb_url:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
123 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
124 log.warning(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
125 "only http URLs are allowed for thumbnails, got {url}, ignoring".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
126 url=thumb_url
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
127 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
128 )
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
129 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
130 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
131 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
132
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
133 def send_pubsub_invitation(
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
134 self,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
135 client: SatXMPPEntity,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
136 invitee_jid: jid.JID,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
137 service: jid.JID,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
138 node: str,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
139 item_id: Optional[str],
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
140 name: Optional[str],
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
141 extra: Optional[dict],
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
142 ) -> 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
143 """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
144
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
145 @param invitee_jid: entitee to send invitation to
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
146 @param service: pubsub service
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
147 @param node: pubsub node
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
148 @param item_id: pubsub id
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
149 None when the invitation is for a whole node
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
150 @param name: see [_generate_base_invitation]
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
151 @param extra: see [_generate_base_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
152 """
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
153 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
154 extra = {}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
155 mess_data, invitation_elt = self._generate_base_invitation(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
156 client, invitee_jid, name, extra
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
157 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
158 pubsub_elt = invitation_elt.addElement("pubsub")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
159 pubsub_elt["service"] = service.full()
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
160 pubsub_elt["node"] = node
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
161 if item_id is None:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
162 try:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
163 namespace = extra.pop("namespace")
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
164 except KeyError:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
165 raise exceptions.DataError('"namespace" key is missing in "extra" data')
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
166 node_data_elt = pubsub_elt.addElement("node_data")
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
167 node_data_elt["namespace"] = namespace
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
168 try:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
169 node_data_elt.addChild(extra["element"])
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
170 except KeyError:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
171 pass
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
172 else:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
173 pubsub_elt["item"] = item_id
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
174 if "element" in extra:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
175 invitation_elt.addChild(extra.pop("element"))
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
176 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
177
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
178 async def send_file_sharing_invitation(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
179 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
180 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
181 invitee_jid,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
182 service,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
183 repos_type=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
184 namespace=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
185 path=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
186 name=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
187 extra=None,
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
188 ):
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
189 """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
190
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
191 @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
192 @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
193 @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
194 - 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
195 - "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
196 @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
197 @param path(unicode, None): path of the shared repository
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
198 @param name(unicode, None): see [_generate_base_invitation]
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
199 @param extra(dict, None): see [_generate_base_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
200 """
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
201 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
202 extra = {}
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
203 li_plg = self.host.plugins["LIST_INTEREST"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
204 li_plg.normalise_file_sharing_service(client, service)
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
205
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
206 # FIXME: not the best place to adapt permission, but it's necessary to check them
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
207 # for UX
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
208 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
209 await self.host.plugins["XEP-0329"].affiliationsSet(
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
210 client, service, namespace, path, {invitee_jid: "member"}
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
211 )
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
212 except Exception as e:
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
213 log.warning(f"Can't set affiliation: {e}")
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
214
3351
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
215 if "thumb_url" not in extra:
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
216 # we have no thumbnail, we check in our own list of interests if there is one
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
217 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
218 item_id = li_plg.get_file_sharing_id(service, namespace, path)
3351
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
219 own_interest = await li_plg.get(client, item_id)
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
220 except exceptions.NotFound:
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
221 log.debug(
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
222 "no thumbnail found for file sharing interest at "
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
223 f"[{service}/{namespace}]{path}"
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
224 )
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
225 else:
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
226 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
227 extra["thumb_url"] = own_interest["thumb_url"]
3351
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
228 except KeyError:
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
229 pass
19bad15f4c0a plugin invitation: if "thumb_url" is not set, try to use one from list of interests
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
230
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
231 mess_data, invitation_elt = self._generate_base_invitation(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
232 client, invitee_jid, name, extra
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
233 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
234 file_sharing_elt = invitation_elt.addElement("file_sharing")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
235 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
236 if repos_type is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
237 if repos_type not in ("files", "photos"):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
238 msg = "unknown repository type: {repos_type}".format(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
239 repos_type=repos_type
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
240 )
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
241 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
242 raise exceptions.DateError(msg)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
243 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
244 if namespace is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
245 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
246 if path is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
247 file_sharing_elt["path"] = path
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
248 client.send(mess_data["xml"])
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
249
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
250 async def _parse_pubsub_elt(self, client, pubsub_elt):
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
251 try:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
252 service = jid.JID(pubsub_elt["service"])
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
253 node = pubsub_elt["node"]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
254 except (RuntimeError, KeyError):
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
255 raise exceptions.DataError("Bad invitation, ignoring")
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
256
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
257 item_id = pubsub_elt.getAttribute("item")
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
258
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
259 if item_id is not None:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
260 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
261 items, metadata = await self._p.get_items(
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
262 client, service, node, item_ids=[item_id]
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
263 )
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
264 except Exception as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
265 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
266 _("Can't get item linked with invitation: {reason}").format(reason=e)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
267 )
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
268 try:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
269 item_elt = items[0]
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
270 except IndexError:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
271 log.warning(_("Invitation was linking to a non existing item"))
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
272 raise exceptions.DataError
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
273
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
274 try:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
275 namespace = item_elt.firstChildElement().uri
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
276 except Exception as e:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
277 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
278 _("Can't retrieve namespace of invitation: {reason}").format(reason=e)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
279 )
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
280 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
281
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
282 args = [service, node, item_id, item_elt]
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
283 else:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
284 try:
3859
3ef988734869 core: fix calls to `domish.Element.elements`:
Goffi <goffi@goffi.org>
parents: 3781
diff changeset
285 node_data_elt = next(pubsub_elt.elements(NS_INVITATION, "node_data"))
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
286 except StopIteration:
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
287 raise exceptions.DataError("Bad invitation, ignoring")
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
288 namespace = node_data_elt["namespace"]
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
289 args = [service, node, None, node_data_elt]
2287
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
290
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
291 return 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
292
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
293 async def _parse_file_sharing_elt(self, client, file_sharing_elt):
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
294 try:
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
295 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
296 except (RuntimeError, KeyError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
297 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
298 raise exceptions.DataError
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
299 repos_type = file_sharing_elt.getAttribute("type", "files")
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
300 sharing_ns = file_sharing_elt.getAttribute("namespace")
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
301 path = file_sharing_elt.getAttribute("path")
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
302 args = [service, repos_type, sharing_ns, path]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
303 ns_fis = self.host.get_namespace("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
304 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
305
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
306 async def on_invitation(self, message_elt, client):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
307 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
308 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
309
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
310 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
311 extra = {}
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
312 if invitation_elt.hasAttribute("thumb_url"):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
313 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
314
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
315 for elt in invitation_elt.elements():
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
316 if elt.uri != NS_INVITATION:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
317 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
318 continue
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
319 if elt.name == "pubsub":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
320 method = self._parse_pubsub_elt
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
321 elif elt.name == "file_sharing":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
322 method = self._parse_file_sharing_elt
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
323 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
324 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
325 "not implemented invitation element: {xml}".format(xml=elt.toXml())
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
326 )
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
327 continue
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
328 try:
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
329 namespace, args = await method(client, elt)
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
330 except exceptions.DataError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
331 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
332 "Can't parse invitation element: {xml}".format(xml=elt.toXml())
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
333 )
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
334 continue
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
335
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
336 try:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
337 cb = self._ns_cb[namespace]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
338 except KeyError:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
339 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
340 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
341 'No handler for namespace "{namespace}", invitation ignored'
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
342 ).format(namespace=namespace)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
343 )
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
344 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
345 await utils.as_deferred(cb, client, namespace, 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
346
ea869f30f204 plugin events: added eventInvite command as a helper for the complex invitation workflow:
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
347
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2941
diff changeset
348 @implementer(iwokkel.IDisco)
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
349 class PubsubInvitationHandler(XMPPHandler):
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
350
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
351 def __init__(self, plugin_parent):
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
352 self.plugin_parent = plugin_parent
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
353
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
354 def connectionInitialized(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
355 self.xmlstream.addObserver(
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
356 INVITATION,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
357 lambda message_elt: defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3859
diff changeset
358 self.plugin_parent.on_invitation(message_elt, client=self.parent)
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
359 ),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
360 )
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
361
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
362 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
363 return [
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
364 disco.DiscoFeature(NS_INVITATION),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
365 ]
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
366
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
367 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
2616
1cc88adb5142 plugin events: invitations improvments + personal list
Goffi <goffi@goffi.org>
parents: 2612
diff changeset
368 return []