diff sat_frontends/jp/cmd_pubsub.py @ 3758:b7cef1b24f83

plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation: - update psSubscriptionsGet to use serialised return value - implement XEP-0376 Pubsub Account Management - implement XEP-0465 Public Pubsub Subscriptions - CLI `pubsub` commands updated accordingly, and added `--public` flags to `subscribe`, `Subscriptions` and `node Subscriptions get` ⚠ `XEP-0465` is speculative, the XEP has been accepted by council but not published yet. As is should be the next one, and current latest one is `XEP-0464`, `XEP-0465` has been anticipated. rel 365
author Goffi <goffi@goffi.org>
date Fri, 13 May 2022 18:38:05 +0200
parents 5bda9d2e8b35
children f599e0e36444
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_pubsub.py	Fri May 13 18:29:42 2022 +0200
+++ b/sat_frontends/jp/cmd_pubsub.py	Fri May 13 18:38:05 2022 +0200
@@ -497,11 +497,19 @@
         )
 
     def add_parser_options(self):
-        pass
+        self.parser.add_argument(
+            "--public",
+            action="store_true",
+            help=_("get public subscriptions"),
+        )
 
     async def start(self):
+        if self.args.public:
+            method = self.host.bridge.psPublicNodeSubscriptionsGet
+        else:
+            method = self.host.bridge.psNodeSubscriptionsGet
         try:
-            subscriptions = await self.host.bridge.psNodeSubscriptionsGet(
+            subscriptions = await method(
                 self.args.service,
                 self.args.node,
                 self.profile,
@@ -1464,9 +1472,26 @@
         )
 
     def add_parser_options(self):
-        pass
+        self.parser.add_argument(
+            "--public",
+            action="store_true",
+            help=_("make the registration visible for everybody"),
+        )
 
     async def start(self):
+        options = {}
+        if self.args.public:
+            namespaces = await self.host.bridge.namespacesGet()
+            try:
+                ns_pps = namespaces["pps"]
+            except KeyError:
+                self.disp(
+                    "Pubsub Public Subscription plugin is not loaded, can't use --public "
+                    "option, subscription stopped", error=True
+                )
+                self.host.quit(C.EXIT_MISSING_FEATURE)
+            else:
+                options[f"{{{ns_pps}}}public"] = True
         try:
             sub_id = await self.host.bridge.psSubscribe(
                 self.args.service,
@@ -1528,14 +1553,25 @@
         )
 
     def add_parser_options(self):
-        pass
+        self.parser.add_argument(
+            "--public",
+            action="store_true",
+            help=_("get public subscriptions"),
+        )
 
     async def start(self):
+        if self.args.public:
+            method = self.host.bridge.psPublicSubscriptionsGet
+        else:
+            method = self.host.bridge.psSubscriptionsGet
         try:
-            subscriptions = await self.host.bridge.psSubscriptionsGet(
-                self.args.service,
-                self.args.node,
-                self.profile,
+            subscriptions = data_format.deserialise(
+                await method(
+                    self.args.service,
+                    self.args.node,
+                    self.profile,
+                ),
+                type_check=list
             )
         except Exception as e:
             self.disp(_("can't retrieve subscriptions: {e}").format(e=e), error=True)