Mercurial > libervia-backend
changeset 3757:5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 13 May 2022 18:29:42 +0200 |
parents | aa923e6b369f |
children | b7cef1b24f83 |
files | sat/plugins/plugin_xep_0060.py sat_frontends/jp/cmd_pubsub.py |
diffstat | 2 files changed, 23 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py Fri May 13 18:22:06 2022 +0200 +++ b/sat/plugins/plugin_xep_0060.py Fri May 13 18:29:42 2022 +0200 @@ -17,7 +17,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -from typing import Optional, List, Tuple +from typing import Optional, List, Tuple, Dict, Union from collections import namedtuple import urllib.request, urllib.parse, urllib.error from functools import reduce @@ -255,7 +255,7 @@ host.bridge.addMethod( "psSubscribe", ".plugin", - in_sign="ssa{ss}s", + in_sign="ssss", out_sign="s", method=self._subscribe, async_=True, @@ -1147,7 +1147,12 @@ client = self.host.getClient(profile_key) service = None if not service else jid.JID(service) d = defer.ensureDeferred( - self.subscribe(client, service, nodeIdentifier, options=options or None) + self.subscribe( + client, + service, + nodeIdentifier, + options=data_format.deserialise(options) + ) ) d.addCallback(lambda subscription: subscription.subscriptionIdentifier or "") return d @@ -1161,14 +1166,15 @@ options: Optional[dict] = None ) -> pubsub.Subscription: # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe + cont, trigger_sub = await self.host.trigger.asyncReturnPoint( + "XEP-0060_subscribe", client, service, nodeIdentifier, sub_jid, options, + ) + if not cont: + return trigger_sub subscription = await client.pubsub_client.subscribe( service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options, sender=client.jid.userhostJID() ) - await self.host.trigger.asyncPoint( - "XEP-0060_subscribe", client, service, nodeIdentifier, sub_jid, options, - subscription - ) return subscription def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): @@ -1181,10 +1187,15 @@ client: SatXMPPEntity, service: jid.JID, nodeIdentifier: str, - sub_jid=None, - subscriptionIdentifier=None, - sender=None, - ): + sub_jid: Optional[jid.JID] = None, + subscriptionIdentifier: Optional[str] = None, + sender: Optional[jid.JID] = None, + ) -> None: + if not await self.host.trigger.asyncPoint( + "XEP-0060_unsubscribe", client, service, nodeIdentifier, sub_jid, + subscriptionIdentifier, sender + ): + return await client.pubsub_client.unsubscribe( service, nodeIdentifier, @@ -1192,10 +1203,6 @@ subscriptionIdentifier, sender, ) - await self.host.trigger.asyncPoint( - "XEP-0060_unsubscribe", client, service, nodeIdentifier, sub_jid, - subscriptionIdentifier, sender - ) def _subscriptions(self, service, nodeIdentifier="", profile_key=C.PROF_KEY_NONE): client = self.host.getClient(profile_key)
--- a/sat_frontends/jp/cmd_pubsub.py Fri May 13 18:22:06 2022 +0200 +++ b/sat_frontends/jp/cmd_pubsub.py Fri May 13 18:29:42 2022 +0200 @@ -1471,7 +1471,7 @@ sub_id = await self.host.bridge.psSubscribe( self.args.service, self.args.node, - {}, + data_format.serialise(options), self.profile, ) except Exception as e: