changeset 2442:b8ffb7f8056b

plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
author Goffi <goffi@goffi.org>
date Sun, 19 Nov 2017 16:41:59 +0100
parents e86dc8cb4345
children 81a45e7886c9
files frontends/src/jp/cmd_pubsub.py src/plugins/plugin_xep_0060.py
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_pubsub.py	Sun Nov 19 16:38:35 2017 +0100
+++ b/frontends/src/jp/cmd_pubsub.py	Sun Nov 19 16:41:59 2017 +0100
@@ -658,14 +658,17 @@
     def add_parser_options(self):
         pass
 
-    def psSubscribeCb(self):
+    def psSubscribeCb(self, sub_id):
         self.disp(_(u'subscription done'), 1)
+        if sub_id:
+            self.disp(_(u'subscription id: {sub_id}').format(sub_id=sub_id))
         self.host.quit()
 
     def start(self):
         self.host.bridge.psSubscribe(
             self.args.service,
             self.args.node,
+            {},
             self.profile,
             callback=self.psSubscribeCb,
             errback=partial(self.errback,
--- a/src/plugins/plugin_xep_0060.py	Sun Nov 19 16:38:35 2017 +0100
+++ b/src/plugins/plugin_xep_0060.py	Sun Nov 19 16:41:59 2017 +0100
@@ -98,7 +98,7 @@
         host.bridge.addMethod("psItemSend", ".plugin", in_sign='ssssa{ss}s', out_sign='s', method=self._sendItem, async=True)
         host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True)
         host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True)
-        host.bridge.addMethod("psSubscribe", ".plugin", in_sign='sss', out_sign='', method=self._subscribe, async=True)
+        host.bridge.addMethod("psSubscribe", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._subscribe, async=True)
         host.bridge.addMethod("psUnsubscribe", ".plugin", in_sign='sss', out_sign='', method=self._unsubscribe, async=True)
         host.bridge.addMethod("psSubscriptionsGet", ".plugin", in_sign='sss', out_sign='aa{ss}', method=self._subscriptions, async=True)
         host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany)
@@ -587,10 +587,12 @@
         client = self.host.getClient(profile_key)
         return client.pubsub_client.retractItems(service, nodeIdentifier, itemIdentifiers, notify=True)
 
-    def _subscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
+    def _subscribe(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE):
         client = self.host.getClient(profile_key)
         service = None if not service else jid.JID(service)
-        return self.subscribe(client, service, nodeIdentifier)
+        d = self.subscribe(client, service, nodeIdentifier, options=options or None)
+        d.addCallback(lambda subscription: subscription.subscriptionIdentifier or u'')
+        return d
 
     def subscribe(self, client, service, nodeIdentifier, sub_jid=None, options=None):
         # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe