Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0060.py @ 4327:554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
- Former bookmarks implementation is now labeled as "legacy".
- XEP-0402 is now used for bookmarks when relevant namespaces are found, and it fallbacks
to legacy XEP-0048/XEP-0049 bookmarks otherwise.
- CLI legacy bookmark commands have been moved to `bookmarks legacy`
- CLI bookmarks commands now use the new XEP-0402 (with fallback to legacy one
automatically used if necessary).
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Nov 2024 11:43:27 +0100 |
parents | a0ed5c976bf8 |
children | 111dce64dcb5 |
comparison
equal
deleted
inserted
replaced
4326:5fd6a4dc2122 | 4327:554a87ae17a6 |
---|---|
100 OWPOL_ORIGINAL = "original_publisher" | 100 OWPOL_ORIGINAL = "original_publisher" |
101 OWPOL_ANY_PUB = "any_publisher" | 101 OWPOL_ANY_PUB = "any_publisher" |
102 ID_SINGLETON = "current" | 102 ID_SINGLETON = "current" |
103 EXTRA_PUBLISH_OPTIONS = "publish_options" | 103 EXTRA_PUBLISH_OPTIONS = "publish_options" |
104 EXTRA_ON_PRECOND_NOT_MET = "on_precondition_not_met" | 104 EXTRA_ON_PRECOND_NOT_MET = "on_precondition_not_met" |
105 EXTRA_AUTOCREATE = "autocreate" | |
105 # extra disco needed for RSM, cf. XEP-0060 § 6.5.4 | 106 # extra disco needed for RSM, cf. XEP-0060 § 6.5.4 |
106 DISCO_RSM = "http://jabber.org/protocol/pubsub#rsm" | 107 DISCO_RSM = "http://jabber.org/protocol/pubsub#rsm" |
107 | 108 |
108 def __init__(self, host): | 109 def __init__(self, host): |
109 log.info(_("PubSub plugin initialization")) | 110 log.info(_("PubSub plugin initialization")) |
606 use this option carefully, and not give public access to a node | 607 use this option carefully, and not give public access to a node |
607 which has not on purpose. | 608 which has not on purpose. |
608 * publish_without_options: re-publish without the publish-options. | 609 * publish_without_options: re-publish without the publish-options. |
609 A warning will be logged showing that the publish-options could not | 610 A warning will be logged showing that the publish-options could not |
610 be used | 611 be used |
612 - self.EXTRA_AUTOCREATE(bool): Create the node if it's not found, and the | |
613 service doesn't do autocreate itself. | |
611 @return: ids of the created items | 614 @return: ids of the created items |
612 """ | 615 """ |
613 if extra is None: | 616 if extra is None: |
614 extra = {} | 617 extra = {} |
615 if service is None: | 618 if service is None: |
629 parsed_items, | 632 parsed_items, |
630 options=publish_options, | 633 options=publish_options, |
631 sender=sender, | 634 sender=sender, |
632 ) | 635 ) |
633 except error.StanzaError as e: | 636 except error.StanzaError as e: |
634 if ( | 637 if e.condition == "item-not-found": |
638 if extra.get(self.EXTRA_AUTOCREATE, False): | |
639 # Autocreate is requested, we create the requested node. | |
640 await self.createNode( | |
641 client, service, nodeIdentifier, publish_options | |
642 ) | |
643 # And we try again. | |
644 iq_result = await self.publish( | |
645 client, | |
646 service, | |
647 nodeIdentifier, | |
648 parsed_items, | |
649 options=publish_options, | |
650 sender=sender, | |
651 ) | |
652 else: | |
653 raise e | |
654 | |
655 elif ( | |
635 e.condition == "conflict" | 656 e.condition == "conflict" |
636 and e.appCondition | 657 and e.appCondition |
637 and e.appCondition.name == "precondition-not-met" | 658 and e.appCondition.name == "precondition-not-met" |
638 and publish_options is not None | 659 and publish_options is not None |
639 ): | 660 ): |
688 async def publish( | 709 async def publish( |
689 self, | 710 self, |
690 client: SatXMPPEntity, | 711 client: SatXMPPEntity, |
691 service: jid.JID, | 712 service: jid.JID, |
692 nodeIdentifier: str, | 713 nodeIdentifier: str, |
693 items: Optional[List[domish.Element]] = None, | 714 items: list[pubsub.Item]|None = None, |
694 options: Optional[dict] = None, | 715 options: dict|None = None, |
695 sender: Optional[jid.JID] = None, | 716 sender: jid.JID|None = None, |
696 extra: Optional[Dict[str, Any]] = None, | 717 extra: dict[str, Any]|None = None, |
697 ) -> domish.Element: | 718 ) -> domish.Element: |
698 """Publish pubsub items | 719 """Publish pubsub items |
699 | 720 |
700 @param sender: sender of the request, | 721 @param sender: sender of the request, |
701 client.jid will be used if nto set | 722 client.jid will be used if not set |
702 @param extra: extra data | 723 @param extra: extra data |
703 not used directly by ``publish``, but may be used in triggers | 724 not used directly by ``publish``, but may be used in triggers |
704 @return: IQ result stanza | 725 @return: IQ result stanza |
705 @trigger XEP-0060_publish: called just before publication. | 726 @trigger XEP-0060_publish: called just before publication. |
706 if it returns False, extra must have a "iq_result_elt" key set with | 727 if it returns False, extra must have a "iq_result_elt" key set with |
784 return d | 805 return d |
785 | 806 |
786 async def get_items( | 807 async def get_items( |
787 self, | 808 self, |
788 client: SatXMPPEntity, | 809 client: SatXMPPEntity, |
789 service: Optional[jid.JID], | 810 service: jid.JID|None, |
790 node: str, | 811 node: str, |
791 max_items: Optional[int] = None, | 812 max_items: int|None = None, |
792 item_ids: Optional[List[str]] = None, | 813 item_ids: list[str]|None = None, |
793 sub_id: Optional[str] = None, | 814 sub_id: str|None = None, |
794 rsm_request: Optional[rsm.RSMRequest] = None, | 815 rsm_request: rsm.RSMRequest|None = None, |
795 extra: Optional[dict] = None, | 816 extra: dict|None = None, |
796 ) -> Tuple[List[domish.Element], dict]: | 817 ) -> tuple[list[domish.Element], dict]: |
797 """Retrieve pubsub items from a node. | 818 """Retrieve pubsub items from a node. |
798 | 819 |
799 @param service (JID, None): pubsub service. | 820 @param service: pubsub service. |
800 @param node (str): node id. | 821 @param node: node id. |
801 @param max_items (int): optional limit on the number of retrieved items. | 822 @param max_items: optional limit on the number of retrieved items. |
802 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be | 823 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be |
803 used with rsm_request). If requested items don't exist, they won't be | 824 used with rsm_request). If requested items don't exist, they won't be |
804 returned, meaning that we can have an empty list as result (NotFound | 825 returned, meaning that we can have an empty list as result (NotFound |
805 exception is NOT raised). | 826 exception is NOT raised). |
806 @param sub_id (str): optional subscription identifier. | 827 @param sub_id : optional subscription identifier. |
807 @param rsm_request (rsm.RSMRequest): RSM request data | 828 @param rsm_request: RSM request data |
808 @return: a deferred couple (list[dict], dict) containing: | 829 @return: a deferred tuple containing: |
809 - list of items | 830 - list of items |
810 - metadata with the following keys: | 831 - metadata with the following keys: |
811 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index | 832 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index |
812 value of RSMResponse | 833 value of RSMResponse |
813 - service, node: service and node used | 834 - service, node: service and node used |
978 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options | 999 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options |
979 ) | 1000 ) |
980 | 1001 |
981 def createNode( | 1002 def createNode( |
982 self, | 1003 self, |
983 client: SatXMPPClient, | 1004 client: SatXMPPEntity, |
984 service: jid.JID, | 1005 service: jid.JID, |
985 nodeIdentifier: Optional[str] = None, | 1006 nodeIdentifier: Optional[str] = None, |
986 options: Optional[Dict[str, str]] = None, | 1007 options: Optional[Dict[str, str]] = None, |
987 ) -> str: | 1008 ) -> defer.Deferred[str]: |
988 """Create a new node | 1009 """Create a new node |
989 | 1010 |
990 @param service: PubSub service, | 1011 @param service: PubSub service, |
991 @param NodeIdentifier: node name use None to create instant node (identifier will | 1012 @param NodeIdentifier: node name use None to create instant node (identifier will |
992 be returned by this method) | 1013 be returned by this method) |
1232 notify, | 1253 notify, |
1233 ) | 1254 ) |
1234 | 1255 |
1235 def retract_items( | 1256 def retract_items( |
1236 self, | 1257 self, |
1237 client: SatXMPPClient, | 1258 client: SatXMPPEntity, |
1238 service: jid.JID, | 1259 service: jid.JID, |
1239 nodeIdentifier: str, | 1260 nodeIdentifier: str, |
1240 itemIdentifiers: Iterable[str], | 1261 itemIdentifiers: Iterable[str], |
1241 notify: bool = True, | 1262 notify: bool = True, |
1242 ) -> defer.Deferred: | 1263 ) -> defer.Deferred: |