plugin XEP-0060: use serialised options in psSubscribe + triggers update
This commit is contained in:
parent
24a1355686
commit
feee36791b
2 changed files with 23 additions and 16 deletions
|
|
@ -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 @@ class XEP_0060(object):
|
|||
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 @@ class XEP_0060(object):
|
|||
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 @@ class XEP_0060(object):
|
|||
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 @@ class XEP_0060(object):
|
|||
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 @@ class XEP_0060(object):
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -1471,7 +1471,7 @@ class Subscribe(base.CommandBase):
|
|||
sub_id = await self.host.bridge.psSubscribe(
|
||||
self.args.service,
|
||||
self.args.node,
|
||||
{},
|
||||
data_format.serialise(options),
|
||||
self.profile,
|
||||
)
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Reference in a new issue