comparison libervia/backend/plugins/plugin_exp_invitation_file.py @ 4071:4b842c1fb686

refactoring: renamed `sat` package to `libervia.backend`
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 11:49:51 +0200
parents sat/plugins/plugin_exp_invitation_file.py@524856bd7b19
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4070:d10748475025 4071:4b842c1fb686
1 #!/usr/bin/env python3
2
3 # SàT plugin to send invitations for file sharing
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 from libervia.backend.core.i18n import _
20 from libervia.backend.core.constants import Const as C
21 from libervia.backend.core.log import getLogger
22 from libervia.backend.core.xmpp import SatXMPPEntity
23 from libervia.backend.tools.common import data_format
24 from twisted.internet import defer
25 from twisted.words.protocols.jabber import jid
26
27 log = getLogger(__name__)
28
29
30 PLUGIN_INFO = {
31 C.PI_NAME: "File Sharing Invitation",
32 C.PI_IMPORT_NAME: "FILE_SHARING_INVITATION",
33 C.PI_TYPE: "EXP",
34 C.PI_PROTOCOLS: [],
35 C.PI_DEPENDENCIES: ["XEP-0329", "INVITATION"],
36 C.PI_RECOMMENDATIONS: [],
37 C.PI_MAIN: "FileSharingInvitation",
38 C.PI_HANDLER: "no",
39 C.PI_DESCRIPTION: _("Experimental handling of invitations for file sharing"),
40 }
41
42
43 class FileSharingInvitation:
44
45 def __init__(self, host):
46 log.info(_("File Sharing Invitation plugin initialization"))
47 self.host = host
48 ns_fis = host.get_namespace("fis")
49 host.plugins["INVITATION"].register_namespace(ns_fis, self.on_invitation)
50 host.bridge.add_method(
51 "fis_invite",
52 ".plugin",
53 in_sign="ssssssss",
54 out_sign="",
55 method=self._send_file_sharing_invitation,
56 async_=True
57 )
58
59 def _send_file_sharing_invitation(
60 self, invitee_jid_s, service_s, repos_type=None, namespace=None, path=None,
61 name=None, extra_s='', profile_key=C.PROF_KEY_NONE):
62 client = self.host.get_client(profile_key)
63 invitee_jid = jid.JID(invitee_jid_s)
64 service = jid.JID(service_s)
65 extra = data_format.deserialise(extra_s)
66 return defer.ensureDeferred(
67 self.host.plugins["INVITATION"].send_file_sharing_invitation(
68 client, invitee_jid, service, repos_type=repos_type or None,
69 namespace=namespace or None, path=path or None, name=name or None,
70 extra=extra)
71 )
72
73 def on_invitation(
74 self,
75 client: SatXMPPEntity,
76 namespace: str,
77 name: str,
78 extra: dict,
79 service: jid.JID,
80 repos_type: str,
81 sharing_ns: str,
82 path: str
83 ):
84 if repos_type == "files":
85 type_human = _("file sharing")
86 elif repos_type == "photos":
87 type_human = _("photo album")
88 else:
89 log.warning("Unknown repository type: {repos_type}".format(
90 repos_type=repos_type))
91 repos_type = "file"
92 type_human = _("file sharing")
93 log.info(_(
94 '{profile} has received an invitation for a files repository ({type_human}) '
95 'with namespace {sharing_ns!r} at path [{path}]').format(
96 profile=client.profile, type_human=type_human, sharing_ns=sharing_ns,
97 path=path)
98 )
99 return defer.ensureDeferred(
100 self.host.plugins['LIST_INTEREST'].register_file_sharing(
101 client, service, repos_type, sharing_ns, path, name, extra
102 )
103 )