annotate sat/plugins/plugin_exp_invitation_file.py @ 4002:5245b675f7ad

plugin XEP-0313: don't wait for MAM to be retrieved in connection workflow: MAM retrieval can be long, and can be done after connection, message just need to be sorted when being inserted (i.e. frontends must do insort). To avoid blocking connection for too long and result in bad UX and timeout risk, one2one MAM message are not retrieved in background.
author Goffi <goffi@goffi.org>
date Fri, 10 Mar 2023 17:22:45 +0100
parents be6d91572633
children 524856bd7b19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
3 # SàT plugin to send invitations for file sharing
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3462
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from sat.core.i18n import _
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.constants import Const as C
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.log import getLogger
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
22 from sat.core.xmpp import SatXMPPEntity
2931
b256e90612d0 plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents: 2917
diff changeset
23 from sat.tools.common import data_format
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
24 from twisted.internet import defer
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import jid
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 log = getLogger(__name__)
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 PLUGIN_INFO = {
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 C.PI_NAME: "File Sharing Invitation",
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 C.PI_IMPORT_NAME: "FILE_SHARING_INVITATION",
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 C.PI_TYPE: "EXP",
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_PROTOCOLS: [],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
35 C.PI_DEPENDENCIES: ["XEP-0329", "INVITATION"],
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_RECOMMENDATIONS: [],
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_MAIN: "FileSharingInvitation",
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_HANDLER: "no",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
39 C.PI_DESCRIPTION: _("Experimental handling of invitations for file sharing"),
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 }
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
43 class FileSharingInvitation:
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
46 log.info(_("File Sharing Invitation plugin initialization"))
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.host = host
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
48 ns_fis = host.getNamespace("fis")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
49 host.plugins["INVITATION"].registerNamespace(ns_fis, self.onInvitation)
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 host.bridge.addMethod(
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 "FISInvite",
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 ".plugin",
2931
b256e90612d0 plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents: 2917
diff changeset
53 in_sign="ssssssss",
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 out_sign="",
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 method=self._sendFileSharingInvitation,
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
56 async_=True
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 )
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def _sendFileSharingInvitation(
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self, invitee_jid_s, service_s, repos_type=None, namespace=None, path=None,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
61 name=None, extra_s='', profile_key=C.PROF_KEY_NONE):
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 client = self.host.getClient(profile_key)
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 invitee_jid = jid.JID(invitee_jid_s)
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 service = jid.JID(service_s)
2931
b256e90612d0 plugins invitation*, events: added an extra parameter and use it to keep a thumnail URL
Goffi <goffi@goffi.org>
parents: 2917
diff changeset
65 extra = data_format.deserialise(extra_s)
3324
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
66 return defer.ensureDeferred(
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
67 self.host.plugins["INVITATION"].sendFileSharingInvitation(
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
68 client, invitee_jid, service, repos_type=repos_type or None,
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
69 namespace=namespace or None, path=path or None, name=name or None,
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
70 extra=extra)
b57b5e42e894 plugins invitation, invitation-file: adapt service JID and affiliation:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
71 )
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
73 def onInvitation(
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
74 self,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
75 client: SatXMPPEntity,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
76 namespace: str,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
77 name: str,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
78 extra: dict,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
79 service: jid.JID,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
80 repos_type: str,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
81 sharing_ns: str,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
82 path: str
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
83 ):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
84 if repos_type == "files":
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
85 type_human = _("file sharing")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
86 elif repos_type == "photos":
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
87 type_human = _("photo album")
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
89 log.warning("Unknown repository type: {repos_type}".format(
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 repos_type=repos_type))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
91 repos_type = "file"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
92 type_human = _("file sharing")
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 log.info(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2931
diff changeset
94 '{profile} has received an invitation for a files repository ({type_human}) '
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
95 'with namespace {sharing_ns!r} at path [{path}]').format(
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
96 profile=client.profile, type_human=type_human, sharing_ns=sharing_ns,
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
97 path=path)
2917
adf6e33a3e50 plugin invitation file: wrong plugin had been uploaded:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 )
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
99 return defer.ensureDeferred(
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
100 self.host.plugins['LIST_INTEREST'].registerFileSharing(
3462
12dc234f698c plugin invitation: pubsub invitations:
Goffi <goffi@goffi.org>
parents: 3324
diff changeset
101 client, service, repos_type, sharing_ns, path, name, extra
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
102 )
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
103 )