diff 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
line wrap: on
line diff
--- 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]
         )