From 68fb304032c9db5d18326c391ca2e5274340b0ba Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 31 Aug 2022 17:07:03 +0200 Subject: [PATCH] cli (pubsub/attachment/set): update reactions handling: - reactions data has been updated following changes in XEP-0470 plugin - it is now possible to remove a reaction using uppercase `-R` - short option from `--replace` has been removed, as it is more handy to use `-R` to remove reactions rel 371 --- sat_frontends/jp/cmd_pubsub.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/sat_frontends/jp/cmd_pubsub.py b/sat_frontends/jp/cmd_pubsub.py index 4aff6feb..217401a7 100644 --- a/sat_frontends/jp/cmd_pubsub.py +++ b/sat_frontends/jp/cmd_pubsub.py @@ -2473,7 +2473,6 @@ class AttachmentSet(base.CommandBase): def add_parser_options(self): self.parser.add_argument( - "-R", "--replace", action="store_true", help=_( @@ -2492,9 +2491,16 @@ class AttachmentSet(base.CommandBase): self.parser.add_argument( "-r", "--reactions", - # FIXME: to be replace by "extend" when we stop supporting python 3.7 + # FIXME: to be replaced by "extend" when we stop supporting python 3.7 action="append", - help=_("add emojis to react to an item") + help=_("emojis to add to react to an item") + ) + self.parser.add_argument( + "-R", + "--reactions-remove", + # FIXME: to be replaced by "extend" when we stop supporting python 3.7 + action="append", + help=_("emojis to remove from reactions to an item") ) async def start(self): @@ -2510,11 +2516,16 @@ class AttachmentSet(base.CommandBase): self.args.noticed = C.BOOL_TRUE mb_data["extra"]["noticed"] = C.bool(self.args.noticed) - if self.args.reactions is not None: - mb_data["extra"]["reaction"] = { - "operation": operation, - "reactions": [r for emojis in self.args.reactions for r in emojis] + if self.args.reactions or self.args.reactions_remove: + reactions = mb_data["extra"]["reactions"] = { + "operation": operation } + if self.args.replace: + reactions["reactions"] = self.args.reactions + else: + reactions["add"] = self.args.reactions + reactions["remove"] = self.args.reactions_remove + if not mb_data["extra"]: self.parser.error(_("At leat one attachment must be specified."))