changeset 3835:f599e0e36444

cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items: rel 369
author Goffi <goffi@goffi.org>
date Sun, 10 Jul 2022 16:15:09 +0200
parents 3260401fdb98
children e183f1fbfa8d
files sat_frontends/jp/cmd_pubsub.py
diffstat 1 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_pubsub.py	Sun Jul 10 16:15:09 2022 +0200
+++ b/sat_frontends/jp/cmd_pubsub.py	Sun Jul 10 16:15:09 2022 +0200
@@ -1610,6 +1610,53 @@
             self.host.quit()
 
 
+class Reference(base.CommandBase):
+    def __init__(self, host):
+        super().__init__(
+            host,
+            "reference",
+            use_pubsub=True,
+            pubsub_flags={C.NODE, C.SINGLE_ITEM},
+            help=_("send a reference/mention to pubsub item"),
+        )
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "-t",
+            "--type",
+            default="mention",
+            choices=("data", "mention"),
+            help=_("type of reference to send (DEFAULT: mention)"),
+        )
+        self.parser.add_argument(
+            "recipient",
+            help=_("recipient of the reference")
+        )
+
+    async def start(self):
+        service = self.args.service or await self.host.get_profile_jid()
+        if self.args.item:
+            anchor = uri.buildXMPPUri(
+                "pubsub", path=service, node=self.args.node, item=self.args.item
+            )
+        else:
+            anchor = uri.buildXMPPUri("pubsub", path=service, node=self.args.node)
+
+        try:
+            await self.host.bridge.referenceSend(
+                self.args.recipient,
+                anchor,
+                self.args.type,
+                "",
+                self.profile,
+            )
+        except Exception as e:
+            self.disp(f"can't send reference: {e}", error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        else:
+            self.host.quit()
+
+
 class Search(base.CommandBase):
     """This command do a search without using MAM
 
@@ -2530,6 +2577,7 @@
         Unsubscribe,
         Subscriptions,
         Affiliations,
+        Reference,
         Search,
         Transform,
         Hook,