Mercurial > libervia-backend
annotate sat/plugins/plugin_exp_list_of_interest.py @ 3249:f16c96c7a91a
core (xmpp): helper method to launch a plugin method:
the `p` client method can be used to launch a method for a plugin, with a default value if
the plugin is not available (or an Exception to raise).
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 03 Apr 2020 18:02:31 +0200 |
parents | 559a625a236b |
children | 0c3b7ee2628f |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 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) |
3136 | 5 # Copyright (C) 2009-2020 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 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _ |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core.constants import Const as C |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.log import getLogger |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from wokkel import disco, iwokkel, pubsub |
3028 | 24 from zope.interface import implementer |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 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
|
26 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
|
27 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from twisted.words.xish import domish |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 log = getLogger(__name__) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 PLUGIN_INFO = { |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 C.PI_NAME: "List of Interest", |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 C.PI_IMPORT_NAME: "LIST_INTEREST", |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 C.PI_TYPE: "EXP", |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_PROTOCOLS: [], |
3028 | 38 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0329"], |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_RECOMMENDATIONS: [], |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_MAIN: "ListInterest", |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_HANDLER: "yes", |
3028 | 42 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
|
43 } |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 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
|
46 |
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 class ListInterest(object): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 namespace = NS_LIST_INTEREST |
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 def __init__(self, host): |
3028 | 52 log.info(_("List of Interest plugin initialization")) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 self.host = host |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 self._p = self.host.plugins["XEP-0060"] |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
55 host.bridge.addMethod( |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
56 "interestsList", |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
57 ".plugin", |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
58 in_sign="ssss", |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
59 out_sign="aa{ss}", |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
60 method=self._listInterests, |
3028 | 61 async_=True, |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
62 ) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 def getHandler(self, client): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 return ListInterestHandler(self) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 @defer.inlineCallbacks |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 def createNode(self, client): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 try: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 # 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
|
71 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
|
72 yield self._p.createNode( |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 client, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 client.jid.userhostJID(), |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 nodeIdentifier=NS_LIST_INTEREST, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 options=options, |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 ) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 except jabber_error.StanzaError as e: |
3028 | 79 if e.condition == "conflict": |
80 log.debug(_("requested node already exists")) | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 @defer.inlineCallbacks |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 def registerPubsub(self, client, namespace, service, node, item_id=None, |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
84 creator=False, name=None, element=None, extra=None): |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 """Register an interesting element in personal list |
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 @param namespace(unicode): namespace of the interest |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 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
|
89 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
|
90 @param service(jid.JID): target pubsub service |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 @param node(unicode): target pubsub node |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 @param item_id(unicode, None): target pubsub id |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 @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
|
94 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
|
95 @param name(unicode, None): name of the interest |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 @param element(domish.Element, None): element to attach |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 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
|
98 @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
|
99 - 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
|
100 """ |
2940
ef554aca3eb1
plugin list interest: initialise extra with an empty dict if not set in registerPubsub
Goffi <goffi@goffi.org>
parents:
2936
diff
changeset
|
101 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
|
102 extra = {} |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 yield self.createNode(client) |
3028 | 104 interest_elt = domish.Element((NS_LIST_INTEREST, "interest")) |
105 interest_elt["namespace"] = namespace | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 if name is not None: |
3028 | 107 interest_elt['name'] = name |
108 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
|
109 if thumb_url: |
3028 | 110 interest_elt['thumb_url'] = thumb_url |
111 pubsub_elt = interest_elt.addElement("pubsub") | |
112 pubsub_elt["service"] = service.full() | |
113 pubsub_elt["node"] = node | |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 if item_id is not None: |
3028 | 115 pubsub_elt["item"] = item_id |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 if creator: |
3028 | 117 pubsub_elt["creator"] = C.BOOL_TRUE |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 if element is not None: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 pubsub_elt.addChild(element) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 item_elt = pubsub.Item(payload=interest_elt) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 yield self._p.publish( |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 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
|
123 ) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 @defer.inlineCallbacks |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
126 def registerFileSharing( |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
127 self, client, service, repos_type=None, namespace=None, path=None, name=None, |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
128 extra=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
|
129 """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
|
130 |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
131 @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
|
132 @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
|
133 @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
|
134 @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
|
135 @param name(unicode, None): name of the repository |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
136 @param extra(dict, None): as ad for [registerPubsub] |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
137 """ |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
138 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
|
139 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
|
140 yield self.createNode(client) |
3028 | 141 interest_elt = domish.Element((NS_LIST_INTEREST, "interest")) |
142 interest_elt["namespace"] = self.host.getNamespace("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
|
143 if name is not None: |
3028 | 144 interest_elt['name'] = name |
145 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
|
146 if thumb_url: |
3028 | 147 interest_elt['thumb_url'] = thumb_url |
148 file_sharing_elt = interest_elt.addElement("file_sharing") | |
149 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
|
150 if repos_type is not None: |
3028 | 151 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
|
152 if namespace is not None: |
3028 | 153 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
|
154 if path is not None: |
3028 | 155 file_sharing_elt["path"] = path |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
156 item_elt = pubsub.Item(payload=interest_elt) |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
157 yield self._p.publish( |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
158 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
|
159 ) |
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
160 |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
161 def _listInterestsSerialise(self, interests_data): |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
162 interests = [] |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
163 for item_elt in interests_data[0]: |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
164 interest_data = {} |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
165 interest_elt = item_elt.interest |
3028 | 166 if interest_elt.hasAttribute('namespace'): |
167 interest_data['namespace'] = interest_elt.getAttribute('namespace') | |
168 if interest_elt.hasAttribute('name'): | |
169 interest_data['name'] = interest_elt.getAttribute('name') | |
170 if interest_elt.hasAttribute('thumb_url'): | |
171 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
|
172 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
|
173 if elt.uri != NS_LIST_INTEREST: |
3028 | 174 log.warning("unexpected child element, ignoring: {xml}".format( |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
175 xml = elt.toXml())) |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
176 continue |
3028 | 177 if elt.name == 'pubsub': |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
178 interest_data.update({ |
3028 | 179 "type": "pubsub", |
180 "service": elt['service'], | |
181 "node": elt['node'], | |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
182 }) |
3028 | 183 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
|
184 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
|
185 interest_data[attr] = elt[attr] |
3028 | 186 elif elt.name == 'file_sharing': |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
187 interest_data.update({ |
3028 | 188 "type": "file_sharing", |
189 "service": elt['service'], | |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
190 }) |
3028 | 191 if elt.hasAttribute('type'): |
192 interest_data['subtype'] = elt['type'] | |
193 for attr in ('namespace', 'path'): | |
2933
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
194 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
|
195 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
|
196 else: |
3028 | 197 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
|
198 continue |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
199 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
|
200 |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
201 return interests |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
202 |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
203 def _listInterests(self, service, node, namespace, profile): |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
204 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
|
205 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
|
206 namespace = namespace or None |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
207 client = self.host.getClient(profile) |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
208 d = self.listInterests(client, service, node, namespace) |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
209 d.addCallback(self._listInterestsSerialise) |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
210 return d |
47df940738a7
plugin list of interest: added an interestsList bridge method + handle thumb_url
Goffi <goffi@goffi.org>
parents:
2913
diff
changeset
|
211 |
2913
672e6be3290f
plugins sharing invitation, invitation, list of interest: handle invitation to a file sharing repository
Goffi <goffi@goffi.org>
parents:
2912
diff
changeset
|
212 @defer.inlineCallbacks |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 def listInterests(self, client, service=None, node=None, namespace=None): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 """Retrieve list of interests |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 @param service(jid.JID, None): service to use |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 None to use own PEP |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 @param node(unicode, None): node to use |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 None to use default node |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 @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
|
221 None to retrieve all interests |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 @return: same as [XEP_0060.getItems] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 """ |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 # 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
|
225 if not node: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 node = NS_LIST_INTEREST |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 items, metadata = yield self._p.getItems(client, service, node) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 if namespace is not None: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 filtered_items = [] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 for item in items: |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 try: |
3028 | 232 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
|
233 except StopIteration: |
3028 | 234 log.warning(_("Missing interest element: {xml}").format( |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 xml=interest_elt.toXml())) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 continue |
3028 | 237 if interest_elt.getAttribute("namespace") == namespace: |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 filtered_items.append(item) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 items = filtered_items |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 defer.returnValue((items, metadata)) |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 |
3028 | 244 @implementer(iwokkel.IDisco) |
2912
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 class ListInterestHandler(XMPPHandler): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 def __init__(self, plugin_parent): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 self.plugin_parent = plugin_parent |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 return [ |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 disco.DiscoFeature(NS_LIST_INTEREST), |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 ] |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
a3faf1c86596
plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 return [] |