Mercurial > libervia-backend
comparison sat/plugins/plugin_exp_list_of_interest.py @ 3299:83795ff8a633
plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 09 Jun 2020 06:25:20 +0200 |
parents | 0c3b7ee2628f |
children | f17379123571 |
comparison
equal
deleted
inserted
replaced
3298:d0e8b0a3ef9c | 3299:83795ff8a633 |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 from sat.tools.common import data_format | |
23 from wokkel import disco, iwokkel, pubsub | 24 from wokkel import disco, iwokkel, pubsub |
24 from zope.interface import implementer | 25 from zope.interface import implementer |
25 from twisted.internet import defer | 26 from twisted.internet import defer |
26 from twisted.words.protocols.jabber import error as jabber_error, jid | 27 from twisted.words.protocols.jabber import error as jabber_error, jid |
27 from twisted.words.protocols.jabber.xmlstream import XMPPHandler | 28 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
56 "interestsList", | 57 "interestsList", |
57 ".plugin", | 58 ".plugin", |
58 in_sign="ssss", | 59 in_sign="ssss", |
59 out_sign="aa{ss}", | 60 out_sign="aa{ss}", |
60 method=self._listInterests, | 61 method=self._listInterests, |
62 async_=True, | |
63 ) | |
64 host.bridge.addMethod( | |
65 "interestsRegisterFileSharing", | |
66 ".plugin", | |
67 in_sign="sssssss", | |
68 out_sign="", | |
69 method=self._registerFileSharing, | |
61 async_=True, | 70 async_=True, |
62 ) | 71 ) |
63 | 72 |
64 def getHandler(self, client): | 73 def getHandler(self, client): |
65 return ListInterestHandler(self) | 74 return ListInterestHandler(self) |
120 item_elt = pubsub.Item(payload=interest_elt) | 129 item_elt = pubsub.Item(payload=interest_elt) |
121 yield self._p.publish( | 130 yield self._p.publish( |
122 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] | 131 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] |
123 ) | 132 ) |
124 | 133 |
125 @defer.inlineCallbacks | 134 def _registerFileSharing( |
126 def registerFileSharing( | 135 self, service, repos_type, namespace, path, name, extra_raw, |
136 profile | |
137 ): | |
138 client = self.host.getClient(profile) | |
139 extra = data_format.deserialise(extra_raw) | |
140 | |
141 return defer.ensureDeferred(self.registerFileSharing( | |
142 client, jid.JID(service), repos_type or None, namespace or None, path or None, | |
143 name or None, extra | |
144 )) | |
145 | |
146 | |
147 async def registerFileSharing( | |
127 self, client, service, repos_type=None, namespace=None, path=None, name=None, | 148 self, client, service, repos_type=None, namespace=None, path=None, name=None, |
128 extra=None): | 149 extra=None): |
129 """Register an interesting file repository in personal list | 150 """Register an interesting file repository in personal list |
130 | 151 |
131 @param service(jid.JID): service of the file repository | 152 @param service(jid.JID): service of the file repository |
132 @param repos_type(unicode): type of the repository | 153 @param repos_type(unicode): type of the repository |
133 @param namespace(unicode, None): namespace of the repository | 154 @param namespace(unicode, None): namespace of the repository |
134 @param path(unicode, None): path of the repository | 155 @param path(unicode, None): path of the repository |
135 @param name(unicode, None): name of the repository | 156 @param name(unicode, None): name of the repository |
136 @param extra(dict, None): as ad for [registerPubsub] | 157 @param extra(dict, None): same as [registerPubsub] |
137 """ | 158 """ |
138 if extra is None: | 159 if extra is None: |
139 extra = {} | 160 extra = {} |
140 yield self.createNode(client) | 161 await self.createNode(client) |
141 interest_elt = domish.Element((NS_LIST_INTEREST, "interest")) | 162 interest_elt = domish.Element((NS_LIST_INTEREST, "interest")) |
142 interest_elt["namespace"] = self.host.getNamespace("fis") | 163 interest_elt["namespace"] = self.host.getNamespace("fis") |
143 if name is not None: | 164 if name is not None: |
144 interest_elt['name'] = name | 165 interest_elt['name'] = name |
145 thumb_url = extra.get('thumb_url') | 166 thumb_url = extra.get('thumb_url') |
152 if namespace is not None: | 173 if namespace is not None: |
153 file_sharing_elt["namespace"] = namespace | 174 file_sharing_elt["namespace"] = namespace |
154 if path is not None: | 175 if path is not None: |
155 file_sharing_elt["path"] = path | 176 file_sharing_elt["path"] = path |
156 item_elt = pubsub.Item(payload=interest_elt) | 177 item_elt = pubsub.Item(payload=interest_elt) |
157 yield self._p.publish( | 178 await self._p.publish( |
158 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] | 179 client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] |
159 ) | 180 ) |
160 | 181 |
161 def _listInterestsSerialise(self, interests_data): | 182 def _listInterestsSerialise(self, interests_data): |
162 interests = [] | 183 interests = [] |