comparison libervia/backend/plugins/plugin_tmp_directory_subscription.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_tmp_directory_subscription.py@524856bd7b19
children
comparison
equal deleted inserted replaced
4070:d10748475025 4071:4b842c1fb686
1 #!/usr/bin/env python3
2
3
4 # SAT plugin for directory subscription
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Jérôme Poisson (goffi@goffi.org)
6 # Copyright (C) 2015, 2016 Adrien Cossa (souliane@mailoo.org)
7
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
17
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 from libervia.backend.core.i18n import _, D_
22 from libervia.backend.core.constants import Const as C
23 from libervia.backend.core.log import getLogger
24
25 log = getLogger(__name__)
26
27
28 PLUGIN_INFO = {
29 C.PI_NAME: "Directory subscription plugin",
30 C.PI_IMPORT_NAME: "DIRECTORY-SUBSCRIPTION",
31 C.PI_TYPE: "TMP",
32 C.PI_PROTOCOLS: [],
33 C.PI_DEPENDENCIES: ["XEP-0050", "XEP-0055"],
34 C.PI_RECOMMENDATIONS: [],
35 C.PI_MAIN: "DirectorySubscription",
36 C.PI_HANDLER: "no",
37 C.PI_DESCRIPTION: _("""Implementation of directory subscription"""),
38 }
39
40
41 NS_COMMANDS = "http://jabber.org/protocol/commands"
42 CMD_UPDATE_SUBSCRIBTION = "update"
43
44
45 class DirectorySubscription(object):
46 def __init__(self, host):
47 log.info(_("Directory subscription plugin initialization"))
48 self.host = host
49 host.import_menu(
50 (D_("Service"), D_("Directory subscription")),
51 self.subscribe,
52 security_limit=1,
53 help_string=D_("User directory subscription"),
54 )
55
56 def subscribe(self, raw_data, profile):
57 """Request available commands on the jabber search service associated to profile's host.
58
59 @param raw_data (dict): data received from the frontend
60 @param profile (unicode): %(doc_profile)s
61 @return: a deferred dict{unicode: unicode}
62 """
63 d = self.host.plugins["XEP-0055"]._get_host_services(profile)
64
65 def got_services(services):
66 service_jid = services[0]
67 session_id, session_data = self.host.plugins[
68 "XEP-0050"
69 ].requesting.new_session(profile=profile)
70 session_data["jid"] = service_jid
71 session_data["node"] = CMD_UPDATE_SUBSCRIBTION
72 data = {"session_id": session_id}
73 return self.host.plugins["XEP-0050"]._requesting_entity(data, profile)
74
75 return d.addCallback(got_services)