Mercurial > libervia-backend
changeset 3867:c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
if not sended is set, `client.jid` is used.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 21 Jul 2022 18:02:33 +0200 |
parents | 915fb230cb28 |
children | 37d2c0282304 |
files | sat/plugins/plugin_xep_0060.py |
diffstat | 1 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py Wed Jul 20 17:55:11 2022 +0200 +++ b/sat/plugins/plugin_xep_0060.py Thu Jul 21 18:02:33 2022 +0200 @@ -534,7 +534,7 @@ 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 @@ service, nodeIdentifier, [item_elt], - extra + extra=extra ) try: return published_ids[0] @@ -570,9 +570,10 @@ 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 @@ """ 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 @@ 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 @@ 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 @@ 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, )