plugin XEP-0060: add trigger points
This commit is contained in:
parent
9ef1f7a1f8
commit
5dcbd8eeef
1 changed files with 43 additions and 8 deletions
|
|
@ -586,12 +586,25 @@ class XEP_0060(object):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
async def publish(self, client, service, nodeIdentifier, items=None, options=None):
|
async def publish(
|
||||||
return await client.pubsub_client.publish(
|
self,
|
||||||
|
client: SatXMPPEntity,
|
||||||
|
service: jid.JID,
|
||||||
|
nodeIdentifier: str,
|
||||||
|
items: Optional[List[domish.Element]] = None,
|
||||||
|
options: Optional[dict] = None
|
||||||
|
) -> List[str]:
|
||||||
|
published_ids = await client.pubsub_client.publish(
|
||||||
service, nodeIdentifier, items, client.pubsub_client.parent.jid,
|
service, nodeIdentifier, items, client.pubsub_client.parent.jid,
|
||||||
options=options
|
options=options
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await self.host.trigger.asyncPoint(
|
||||||
|
"XEP-0060_publish", client, service, nodeIdentifier, items, options,
|
||||||
|
published_ids
|
||||||
|
)
|
||||||
|
return published_ids
|
||||||
|
|
||||||
def _unwrapMAMMessage(self, message_elt):
|
def _unwrapMAMMessage(self, message_elt):
|
||||||
try:
|
try:
|
||||||
item_elt = reduce(
|
item_elt = reduce(
|
||||||
|
|
@ -670,6 +683,12 @@ class XEP_0060(object):
|
||||||
raise ValueError("items_id can't be used with rsm")
|
raise ValueError("items_id can't be used with rsm")
|
||||||
if extra is None:
|
if extra is None:
|
||||||
extra = {}
|
extra = {}
|
||||||
|
cont, ret = await self.host.trigger.asyncReturnPoint(
|
||||||
|
"XEP-0060_getItems", client, service, node, max_items, item_ids, sub_id,
|
||||||
|
rsm_request, extra
|
||||||
|
)
|
||||||
|
if not cont:
|
||||||
|
return ret
|
||||||
try:
|
try:
|
||||||
mam_query = extra["mam"]
|
mam_query = extra["mam"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
@ -1097,11 +1116,23 @@ class XEP_0060(object):
|
||||||
d.addCallback(lambda subscription: subscription.subscriptionIdentifier or "")
|
d.addCallback(lambda subscription: subscription.subscriptionIdentifier or "")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
async def subscribe(self, client, service, nodeIdentifier, sub_jid=None, options=None):
|
async def subscribe(
|
||||||
|
self,
|
||||||
|
client: SatXMPPEntity,
|
||||||
|
service: 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
|
# TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe
|
||||||
return await client.pubsub_client.subscribe(
|
subscription = await client.pubsub_client.subscribe(
|
||||||
service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options
|
service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options
|
||||||
)
|
)
|
||||||
|
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):
|
def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
|
||||||
client = self.host.getClient(profile_key)
|
client = self.host.getClient(profile_key)
|
||||||
|
|
@ -1110,20 +1141,24 @@ class XEP_0060(object):
|
||||||
|
|
||||||
async def unsubscribe(
|
async def unsubscribe(
|
||||||
self,
|
self,
|
||||||
client,
|
client: SatXMPPEntity,
|
||||||
service,
|
service: jid.JID,
|
||||||
nodeIdentifier,
|
nodeIdentifier: str,
|
||||||
sub_jid=None,
|
sub_jid=None,
|
||||||
subscriptionIdentifier=None,
|
subscriptionIdentifier=None,
|
||||||
sender=None,
|
sender=None,
|
||||||
):
|
):
|
||||||
return await client.pubsub_client.unsubscribe(
|
await client.pubsub_client.unsubscribe(
|
||||||
service,
|
service,
|
||||||
nodeIdentifier,
|
nodeIdentifier,
|
||||||
sub_jid or client.jid.userhostJID(),
|
sub_jid or client.jid.userhostJID(),
|
||||||
subscriptionIdentifier,
|
subscriptionIdentifier,
|
||||||
sender,
|
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):
|
def _subscriptions(self, service, nodeIdentifier="", profile_key=C.PROF_KEY_NONE):
|
||||||
client = self.host.getClient(profile_key)
|
client = self.host.getClient(profile_key)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue