comparison sat/plugins/plugin_xep_0277.py @ 3848:e9c380ef41c8

plugin XEP-0277: return ID of published item in `send` and bridge's `mbSend`
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 5b192a5eb72d
children 37a1193d90db
comparison
equal deleted inserted replaced
3847:aaa4e7815ba8 3848:e9c380ef41c8
107 107
108 host.bridge.addMethod( 108 host.bridge.addMethod(
109 "mbSend", 109 "mbSend",
110 ".plugin", 110 ".plugin",
111 in_sign="ssss", 111 in_sign="ssss",
112 out_sign="", 112 out_sign="s",
113 method=self._mbSend, 113 method=self._mbSend,
114 async_=True, 114 async_=True,
115 ) 115 )
116 host.bridge.addMethod( 116 host.bridge.addMethod(
117 "mbRepeat", 117 "mbRepeat",
946 self, 946 self,
947 client: SatXMPPEntity, 947 client: SatXMPPEntity,
948 data: dict, 948 data: dict,
949 service: Optional[jid.JID] = None, 949 service: Optional[jid.JID] = None,
950 node: Optional[str] = NS_MICROBLOG 950 node: Optional[str] = NS_MICROBLOG
951 ) -> None: 951 ) -> Optional[str]:
952 """Send XEP-0277's microblog data 952 """Send XEP-0277's microblog data
953 953
954 @param data: microblog data (must include at least a "content" or a "title" key). 954 @param data: microblog data (must include at least a "content" or a "title" key).
955 see http://wiki.goffi.org/wiki/Bridge_API_-_Microblogging/en for details 955 see http://wiki.goffi.org/wiki/Bridge_API_-_Microblogging/en for details
956 @param service: PubSub service where the microblog must be published 956 @param service: PubSub service where the microblog must be published
957 None to publish on profile's PEP 957 None to publish on profile's PEP
958 @param node: PubSub node to use (defaut to microblog NS) 958 @param node: PubSub node to use (defaut to microblog NS)
959 None is equivalend as using default value 959 None is equivalend as using default value
960 @return: ID of the published item
960 """ 961 """
961 # TODO: check that all data keys are used, this would avoid sending publicly a private message 962 # TODO: check that all data keys are used, this would avoid sending publicly a private message
962 # by accident (e.g. if group plugin is not loaded, and "group*" key are not used) 963 # by accident (e.g. if group plugin is not loaded, and "group*" key are not used)
963 if node is None: 964 if node is None:
964 node = NS_MICROBLOG 965 node = NS_MICROBLOG
973 try: 974 try:
974 await self._manageComments(client, data, service, node, item_id, access=None) 975 await self._manageComments(client, data, service, node, item_id, access=None)
975 except error.StanzaError: 976 except error.StanzaError:
976 log.warning("Can't create comments node for item {}".format(item_id)) 977 log.warning("Can't create comments node for item {}".format(item_id))
977 item = await self.data2entry(client, data, item_id, service, node) 978 item = await self.data2entry(client, data, item_id, service, node)
978 return await self._p.publish(client, service, node, [item]) 979 await self._p.publish(client, service, node, [item])
980 return item_id
979 981
980 def _mbRepeat( 982 def _mbRepeat(
981 self, 983 self,
982 service_s: str, 984 service_s: str,
983 node: str, 985 node: str,