From c20e09fb2288182fe57f6bacac3453f114e5fae0 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 21 Jul 2022 18:02:33 +0200 Subject: [PATCH] plugin XEP-0060: sender can now be specified in `sendItems` and `publish`: if not sended is set, `client.jid` is used. --- sat/plugins/plugin_xep_0060.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/sat/plugins/plugin_xep_0060.py b/sat/plugins/plugin_xep_0060.py index 4e734cbf..f3822e0c 100644 --- a/sat/plugins/plugin_xep_0060.py +++ b/sat/plugins/plugin_xep_0060.py @@ -534,7 +534,7 @@ class XEP_0060(object): msg=e)) extra = data_format.deserialise(extra_ser) return defer.ensureDeferred(self.sendItems( - client, service, nodeIdentifier, items, extra + client, service, nodeIdentifier, items, extra=extra )) async def sendItem( @@ -560,7 +560,7 @@ class XEP_0060(object): service, nodeIdentifier, [item_elt], - extra + extra=extra ) try: return published_ids[0] @@ -570,9 +570,10 @@ class XEP_0060(object): async def sendItems( self, client: SatXMPPEntity, - service: jid.JID, + service: Optional[jid.JID], nodeIdentifier: str, items: List[domish.Element], + sender: Optional[jid.JID] = None, extra: Optional[Dict[str, Any]] = None ) -> List[str]: """High level method to send several items at once @@ -595,6 +596,8 @@ class XEP_0060(object): """ if extra is None: extra = {} + if service is None: + service = client.jid.userhostJID() parsed_items = [] for item in items: if item.name != 'item': @@ -604,7 +607,9 @@ class XEP_0060(object): publish_options = extra.get(self.EXTRA_PUBLISH_OPTIONS) try: iq_result = await self.publish( - client, service, nodeIdentifier, parsed_items, options=publish_options) + client, service, nodeIdentifier, parsed_items, options=publish_options, + sender=sender + ) except error.StanzaError as e: if ((e.condition == 'conflict' and e.appCondition and e.appCondition.name == 'precondition-not-met' @@ -646,14 +651,19 @@ class XEP_0060(object): service: jid.JID, nodeIdentifier: str, items: Optional[List[domish.Element]] = None, - options: Optional[dict] = None + options: Optional[dict] = None, + sender: Optional[jid.JID] = None ) -> domish.Element: """Publish pubsub items + @param sender: sender of the request, + client.jid will be used if nto set @return: IQ result stanza """ + if sender is None: + sender = client.jid iq_result_elt = await client.pubsub_client.publish( - service, nodeIdentifier, items, client.pubsub_client.parent.jid, + service, nodeIdentifier, items, sender, options=options ) @@ -1184,12 +1194,14 @@ class XEP_0060(object): async def subscribe( self, client: SatXMPPEntity, - service: jid.JID, + service: Optional[jid.JID], nodeIdentifier: str, sub_jid: Optional[jid.JID] = None, options: Optional[dict] = None ) -> pubsub.Subscription: # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe + if service is None: + service = client.jid.userhostJID() cont, trigger_sub = await self.host.trigger.asyncReturnPoint( "XEP-0060_subscribe", client, service, nodeIdentifier, sub_jid, options, )