# HG changeset patch # User Goffi # Date 1591676720 -7200 # Node ID 83795ff8a63344ec9890aa1743d194ddc9d53102 # Parent d0e8b0a3ef9cd89345b9c971c8a0b63ad8eb0330 plugin list of interest: expose `interestsRegisterFileSharing` to bridge + use coroutines diff -r d0e8b0a3ef9c -r 83795ff8a633 sat/plugins/plugin_exp_invitation_file.py --- a/sat/plugins/plugin_exp_invitation_file.py Tue Jun 09 06:23:37 2020 +0200 +++ b/sat/plugins/plugin_exp_invitation_file.py Tue Jun 09 06:25:20 2020 +0200 @@ -21,6 +21,7 @@ from sat.core.constants import Const as C from sat.core.log import getLogger from sat.tools.common import data_format +from twisted.internet import defer from twisted.words.protocols.jabber import jid log = getLogger(__name__) @@ -70,7 +71,7 @@ if repos_type == "files": type_human = _("file sharing") elif repos_type == "photos": - type_human = _("photos album") + type_human = _("photo album") else: log.warning("Unknown repository type: {repos_type}".format( repos_type=repos_type)) @@ -81,5 +82,8 @@ 'with namespace "{namespace}" at path [{path}]').format( profile=client.profile, type_human=type_human, namespace=namespace, path=path) ) - return self.host.plugins['LIST_INTEREST'].registerFileSharing( - client, service, repos_type, namespace, path, name, extra) + return defer.ensureDeferred( + self.host.plugins['LIST_INTEREST'].registerFileSharing( + client, service, repos_type, namespace, path, name, extra + ) + ) diff -r d0e8b0a3ef9c -r 83795ff8a633 sat/plugins/plugin_exp_list_of_interest.py --- a/sat/plugins/plugin_exp_list_of_interest.py Tue Jun 09 06:23:37 2020 +0200 +++ b/sat/plugins/plugin_exp_list_of_interest.py Tue Jun 09 06:25:20 2020 +0200 @@ -20,6 +20,7 @@ from sat.core.i18n import _ from sat.core.constants import Const as C from sat.core.log import getLogger +from sat.tools.common import data_format from wokkel import disco, iwokkel, pubsub from zope.interface import implementer from twisted.internet import defer @@ -60,6 +61,14 @@ method=self._listInterests, async_=True, ) + host.bridge.addMethod( + "interestsRegisterFileSharing", + ".plugin", + in_sign="sssssss", + out_sign="", + method=self._registerFileSharing, + async_=True, + ) def getHandler(self, client): return ListInterestHandler(self) @@ -122,8 +131,20 @@ client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] ) - @defer.inlineCallbacks - def registerFileSharing( + def _registerFileSharing( + self, service, repos_type, namespace, path, name, extra_raw, + profile + ): + client = self.host.getClient(profile) + extra = data_format.deserialise(extra_raw) + + return defer.ensureDeferred(self.registerFileSharing( + client, jid.JID(service), repos_type or None, namespace or None, path or None, + name or None, extra + )) + + + async def registerFileSharing( self, client, service, repos_type=None, namespace=None, path=None, name=None, extra=None): """Register an interesting file repository in personal list @@ -133,11 +154,11 @@ @param namespace(unicode, None): namespace of the repository @param path(unicode, None): path of the repository @param name(unicode, None): name of the repository - @param extra(dict, None): as ad for [registerPubsub] + @param extra(dict, None): same as [registerPubsub] """ if extra is None: extra = {} - yield self.createNode(client) + await self.createNode(client) interest_elt = domish.Element((NS_LIST_INTEREST, "interest")) interest_elt["namespace"] = self.host.getNamespace("fis") if name is not None: @@ -154,7 +175,7 @@ if path is not None: file_sharing_elt["path"] = path item_elt = pubsub.Item(payload=interest_elt) - yield self._p.publish( + await self._p.publish( client, client.jid.userhostJID(), NS_LIST_INTEREST, items=[item_elt] )