comparison sat_frontends/jp/cmd_pubsub.py @ 3889:1ab5fb468a41

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
author Goffi <goffi@goffi.org>
date Wed, 31 Aug 2022 17:07:03 +0200
parents 915fb230cb28
children 6939594ba77e
comparison
equal deleted inserted replaced
3888:aa7197b67c26 3889:1ab5fb468a41
2471 help=_("attach data to an item"), 2471 help=_("attach data to an item"),
2472 ) 2472 )
2473 2473
2474 def add_parser_options(self): 2474 def add_parser_options(self):
2475 self.parser.add_argument( 2475 self.parser.add_argument(
2476 "-R",
2477 "--replace", 2476 "--replace",
2478 action="store_true", 2477 action="store_true",
2479 help=_( 2478 help=_(
2480 "replace previous versions of attachments (DEFAULT: update previous " 2479 "replace previous versions of attachments (DEFAULT: update previous "
2481 "version)" 2480 "version)"
2490 help=_("mark item as (un)noticed (DEFAULT: keep current value))") 2489 help=_("mark item as (un)noticed (DEFAULT: keep current value))")
2491 ) 2490 )
2492 self.parser.add_argument( 2491 self.parser.add_argument(
2493 "-r", 2492 "-r",
2494 "--reactions", 2493 "--reactions",
2495 # FIXME: to be replace by "extend" when we stop supporting python 3.7 2494 # FIXME: to be replaced by "extend" when we stop supporting python 3.7
2496 action="append", 2495 action="append",
2497 help=_("add emojis to react to an item") 2496 help=_("emojis to add to react to an item")
2497 )
2498 self.parser.add_argument(
2499 "-R",
2500 "--reactions-remove",
2501 # FIXME: to be replaced by "extend" when we stop supporting python 3.7
2502 action="append",
2503 help=_("emojis to remove from reactions to an item")
2498 ) 2504 )
2499 2505
2500 async def start(self): 2506 async def start(self):
2501 mb_data = { 2507 mb_data = {
2502 "service": self.args.service, 2508 "service": self.args.service,
2508 if self.args.noticed != "keep": 2514 if self.args.noticed != "keep":
2509 if self.args.noticed is None: 2515 if self.args.noticed is None:
2510 self.args.noticed = C.BOOL_TRUE 2516 self.args.noticed = C.BOOL_TRUE
2511 mb_data["extra"]["noticed"] = C.bool(self.args.noticed) 2517 mb_data["extra"]["noticed"] = C.bool(self.args.noticed)
2512 2518
2513 if self.args.reactions is not None: 2519 if self.args.reactions or self.args.reactions_remove:
2514 mb_data["extra"]["reaction"] = { 2520 reactions = mb_data["extra"]["reactions"] = {
2515 "operation": operation, 2521 "operation": operation
2516 "reactions": [r for emojis in self.args.reactions for r in emojis]
2517 } 2522 }
2523 if self.args.replace:
2524 reactions["reactions"] = self.args.reactions
2525 else:
2526 reactions["add"] = self.args.reactions
2527 reactions["remove"] = self.args.reactions_remove
2528
2518 2529
2519 if not mb_data["extra"]: 2530 if not mb_data["extra"]:
2520 self.parser.error(_("At leat one attachment must be specified.")) 2531 self.parser.error(_("At leat one attachment must be specified."))
2521 2532
2522 try: 2533 try: