annotate libervia/backend/plugins/plugin_exp_list_of_interest.py @ 4281:9e63e02318ec

core: show warning instead of exception in case of missing dependency when loading plugins
author Goffi <goffi@goffi.org>
date Fri, 12 Jul 2024 18:53:00 +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: 2940
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin to detect language (experimental)
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3350
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 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
22 from libervia.backend.core.xmpp import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
23 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
24 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.tools.common import data_format
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.tools.common import uri
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from wokkel import disco, iwokkel, pubsub
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
28 from zope.interface import implementer
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from twisted.internet import defer
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
30 from twisted.words.protocols.jabber import error as jabber_error, jid
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from twisted.words.xish import domish
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 log = getLogger(__name__)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 PLUGIN_INFO = {
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_NAME: "List of Interest",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_IMPORT_NAME: "LIST_INTEREST",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_TYPE: "EXP",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_PROTOCOLS: [],
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
42 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329", "XEP-0106"],
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_RECOMMENDATIONS: [],
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_MAIN: "ListInterest",
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 C.PI_HANDLER: "yes",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
46 C.PI_DESCRIPTION: _("Experimental handling of interesting XMPP locations"),
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 }
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 NS_LIST_INTEREST = "https://salut-a-toi/protocol/list-interest:0"
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 class ListInterest(object):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 namespace = NS_LIST_INTEREST
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
56 log.info(_("List of Interest plugin initialization"))
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.host = host
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self._p = self.host.plugins["XEP-0060"]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
59 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
60 "interests_list",
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
61 ".plugin",
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
62 in_sign="ssss",
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
63 out_sign="aa{ss}",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
64 method=self._list_interests,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
65 async_=True,
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
66 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
67 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
68 "interests_file_sharing_register",
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
69 ".plugin",
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
70 in_sign="sssssss",
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
71 out_sign="",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
72 method=self._register_file_sharing,
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
73 async_=True,
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
74 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
75 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
76 "interest_retract",
3303
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
77 ".plugin",
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
78 in_sign="sss",
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
79 out_sign="",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
80 method=self._interest_retract,
3303
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
81 async_=True,
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
82 )
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
84 def get_handler(self, client):
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 return ListInterestHandler(self)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 @defer.inlineCallbacks
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 def createNode(self, client):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 try:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 # TODO: check auto-create, no need to create node first if available
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_WHITELIST}
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 yield self._p.createNode(
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 client,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 client.jid.userhostJID(),
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 nodeIdentifier=NS_LIST_INTEREST,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 options=options,
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 )
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 except jabber_error.StanzaError as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
99 if e.condition == "conflict":
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
100 log.debug(_("requested node already exists"))
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
102 async def register_pubsub(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
103 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
104 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
105 namespace,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
106 service,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
107 node,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
108 item_id=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
109 creator=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
110 name=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
111 element=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
112 extra=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
113 ):
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 """Register an interesting element in personal list
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 @param namespace(unicode): namespace of the interest
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 this is used as a cache, to avoid the need to retrieve the item only to get
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 its 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
119 @param service(jid.JID): target pubsub service
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 @param node(unicode): target pubsub node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 @param item_id(unicode, None): target pubsub id
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 @param creator(bool): True if client's profile is the creator of the node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 This is used a cache, to avoid the need to retrieve affiliations
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 @param name(unicode, None): name of the interest
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 @param element(domish.Element, None): element to attach
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 may be used to cache some extra data
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
127 @param extra(dict, None): extra data, key can be:
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
128 - thumb_url: http(s) URL of a thumbnail
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 """
2940
ef554aca3eb1 plugin list interest: initialise extra with an empty dict if not set in registerPubsub
Goffi <goffi@goffi.org>
parents: 2936
diff changeset
130 if extra is None:
ef554aca3eb1 plugin list interest: initialise extra with an empty dict if not set in registerPubsub
Goffi <goffi@goffi.org>
parents: 2936
diff changeset
131 extra = {}
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
132 await self.createNode(client)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
133 interest_elt = domish.Element((NS_LIST_INTEREST, "interest"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
134 interest_elt["namespace"] = namespace
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 if name is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
136 interest_elt["name"] = name
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
137 thumb_url = extra.get("thumb_url")
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
138 if thumb_url:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
139 interest_elt["thumb_url"] = thumb_url
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
140 pubsub_elt = interest_elt.addElement("pubsub")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
141 pubsub_elt["service"] = service.full()
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
142 pubsub_elt["node"] = node
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 if item_id is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
144 pubsub_elt["item"] = item_id
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 if creator:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
146 pubsub_elt["creator"] = C.BOOL_TRUE
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 if element is not None:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 pubsub_elt.addChild(element)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
149 uri_kwargs = {"path": service.full(), "node": node}
3322
56ee491c0df6 plugin list for interest: build ID using URI or file path metadata:
Goffi <goffi@goffi.org>
parents: 3304
diff changeset
150 if item_id:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
151 uri_kwargs["id"] = item_id
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
152 interest_uri = uri.build_xmpp_uri("pubsub", **uri_kwargs)
3322
56ee491c0df6 plugin list for interest: build ID using URI or file path metadata:
Goffi <goffi@goffi.org>
parents: 3304
diff changeset
153 # we use URI of the interest as item id to avoid duplicates
56ee491c0df6 plugin list for interest: build ID using URI or file path metadata:
Goffi <goffi@goffi.org>
parents: 3304
diff changeset
154 item_elt = pubsub.Item(interest_uri, payload=interest_elt)
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
155 await self._p.publish(
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 )
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
158
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
159 def _register_file_sharing(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
160 self, service, repos_type, namespace, path, name, extra_raw, profile
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
161 ):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
162 client = self.host.get_client(profile)
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
163 extra = data_format.deserialise(extra_raw)
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
164
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
165 return defer.ensureDeferred(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
166 self.register_file_sharing(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
167 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
168 jid.JID(service),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
169 repos_type or None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
170 namespace or None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
171 path or None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
172 name or None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
173 extra,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
174 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
175 )
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
176
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
177 def normalise_file_sharing_service(self, client, service):
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
178 # FIXME: Q&D fix as the bare file sharing service JID will lead to user own
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
179 # repository, which thus would not be the same for the host and the guest.
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
180 # By specifying the user part, we for the use of the host repository.
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
181 # A cleaner way should be implemented
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
182 if service.user is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
183 service.user = self.host.plugins["XEP-0106"].escape(client.jid.user)
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
184
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
185 def get_file_sharing_id(self, service, namespace, path):
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
186 return f"{service}_{namespace or ''}_{path or ''}"
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
187
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
188 async def register_file_sharing(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
189 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
190 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
191 service,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
192 repos_type=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
193 namespace=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
194 path=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
195 name=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
196 extra=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
197 ):
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
198 """Register an interesting file repository in personal list
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
199
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
200 @param service(jid.JID): service 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
201 @param repos_type(unicode): type 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
202 @param 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
203 @param path(unicode, None): path 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
204 @param name(unicode, None): name of the repository
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
205 @param extra(dict, None): same as [register_pubsub]
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
206 """
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
207 if extra is None:
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
208 extra = {}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
209 self.normalise_file_sharing_service(client, service)
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
210 await self.createNode(client)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
211 item_id = self.get_file_sharing_id(service, namespace, path)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
212 interest_elt = domish.Element((NS_LIST_INTEREST, "interest"))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
213 interest_elt["namespace"] = 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
214 if name is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
215 interest_elt["name"] = name
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
216 thumb_url = extra.get("thumb_url")
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
217 if thumb_url:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
218 interest_elt["thumb_url"] = thumb_url
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
219
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
220 file_sharing_elt = interest_elt.addElement("file_sharing")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
221 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
222 if repos_type is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
223 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
224 if namespace is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
225 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
226 if path is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
227 file_sharing_elt["path"] = path
3322
56ee491c0df6 plugin list for interest: build ID using URI or file path metadata:
Goffi <goffi@goffi.org>
parents: 3304
diff changeset
228 item_elt = pubsub.Item(item_id, payload=interest_elt)
3299
83795ff8a633 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
Goffi <goffi@goffi.org>
parents: 3270
diff changeset
229 await self._p.publish(
2913
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
230 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt]
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
231 )
672e6be3290f plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
232
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
233 def _list_interests_serialise(self, interests_data):
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
234 interests = []
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
235 for item_elt in interests_data[0]:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
236 interest_data = {"id": item_elt["id"]}
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
237 interest_elt = item_elt.interest
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
238 if interest_elt.hasAttribute("namespace"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
239 interest_data["namespace"] = interest_elt.getAttribute("namespace")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
240 if interest_elt.hasAttribute("name"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
241 interest_data["name"] = interest_elt.getAttribute("name")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
242 if interest_elt.hasAttribute("thumb_url"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
243 interest_data["thumb_url"] = interest_elt.getAttribute("thumb_url")
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
244 elt = interest_elt.firstChildElement()
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
245 if elt.uri != NS_LIST_INTEREST:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
246 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
247 "unexpected child element, ignoring: {xml}".format(xml=elt.toXml())
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
248 )
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
249 continue
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
250 if elt.name == "pubsub":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
251 interest_data.update(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
252 {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
253 "type": "pubsub",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
254 "service": elt["service"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
255 "node": elt["node"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
256 }
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
257 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
258 for attr in ("item", "creator"):
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
259 if elt.hasAttribute(attr):
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
260 interest_data[attr] = elt[attr]
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
261 elif elt.name == "file_sharing":
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
262 interest_data.update(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
263 {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
264 "type": "file_sharing",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
265 "service": elt["service"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
266 }
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
267 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
268 if elt.hasAttribute("type"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
269 interest_data["subtype"] = elt["type"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
270 for attr in ("files_namespace", "path"):
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
271 if elt.hasAttribute(attr):
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
272 interest_data[attr] = elt[attr]
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
273 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
274 log.warning("unknown element, ignoring: {xml}".format(xml=elt.toXml()))
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
275 continue
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
276 interests.append(interest_data)
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
277
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
278 return interests
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
279
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
280 def _list_interests(self, service, node, namespace, profile):
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
281 service = jid.JID(service) if service else None
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
282 node = node or None
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
283 namespace = namespace or None
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
284 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
285 d = defer.ensureDeferred(self.list_interests(client, service, node, namespace))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
286 d.addCallback(self._list_interests_serialise)
2933
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
287 return d
47df940738a7 plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents: 2913
diff changeset
288
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
289 async def list_interests(self, client, service=None, node=None, namespace=None):
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 """Retrieve list of interests
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
291
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 @param service(jid.JID, None): service to use
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 None to use own PEP
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 @param node(unicode, None): node to use
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 None to use default node
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 @param namespace(unicode, None): filter interests of this namespace
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 None to retrieve all interests
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
298 @return: same as [XEP_0060.get_items]
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 """
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 # TODO: if a MAM filter were available, it would improve performances
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 if not node:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 node = NS_LIST_INTEREST
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
303 items, metadata = await self._p.get_items(client, service, node)
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 if namespace is not None:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 filtered_items = []
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 for item in items:
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
308 interest_elt = next(item.elements(NS_LIST_INTEREST, "interest"))
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 except StopIteration:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
310 log.warning(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
311 _("Missing interest element: {xml}").format(xml=item.toXml())
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
312 )
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 continue
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
314 if interest_elt.getAttribute("namespace") == namespace:
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 filtered_items.append(item)
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 items = filtered_items
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
317
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
318 return (items, metadata)
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
319
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
320 def _interest_retract(self, service_s, item_id, profile_key):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
321 d = self._p._retract_item(service_s, NS_LIST_INTEREST, item_id, True, profile_key)
3303
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
322 d.addCallback(lambda __: None)
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
323 return d
f17379123571 plugin list of interest: new "interestRetract" method
Goffi <goffi@goffi.org>
parents: 3299
diff changeset
324
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
325 async def get(self, client: SatXMPPEntity, item_id: str) -> dict:
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
326 """Retrieve a specific interest in profile's list"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
327 items_data = await self._p.get_items(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
328 client, None, NS_LIST_INTEREST, item_ids=[item_id]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
329 )
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
330 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3584
diff changeset
331 return self._list_interests_serialise(items_data)[0]
3350
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
332 except IndexError:
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
333 raise exceptions.NotFound
cc6164a4973b plugin list of interests: normalize item ID + added `get` method
Goffi <goffi@goffi.org>
parents: 3344
diff changeset
334
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
335
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2940
diff changeset
336 @implementer(iwokkel.IDisco)
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 class ListInterestHandler(XMPPHandler):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
338
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 def __init__(self, plugin_parent):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 self.plugin_parent = plugin_parent
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
341
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 return [
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 disco.DiscoFeature(NS_LIST_INTEREST),
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 ]
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
346
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 return []