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:
|
||||
return []
|
||||
|
||||
async def publish(self, client, service, nodeIdentifier, items=None, options=None):
|
||||
return await client.pubsub_client.publish(
|
||||
async def 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,
|
||||
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):
|
||||
try:
|
||||
item_elt = reduce(
|
||||
|
|
@ -670,6 +683,12 @@ class XEP_0060(object):
|
|||
raise ValueError("items_id can't be used with rsm")
|
||||
if extra is None:
|
||||
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:
|
||||
mam_query = extra["mam"]
|
||||
except KeyError:
|
||||
|
|
@ -1097,11 +1116,23 @@ class XEP_0060(object):
|
|||
d.addCallback(lambda subscription: subscription.subscriptionIdentifier or "")
|
||||
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
|
||||
return await client.pubsub_client.subscribe(
|
||||
subscription = await client.pubsub_client.subscribe(
|
||||
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):
|
||||
client = self.host.getClient(profile_key)
|
||||
|
|
@ -1110,20 +1141,24 @@ class XEP_0060(object):
|
|||
|
||||
async def unsubscribe(
|
||||
self,
|
||||
client,
|
||||
service,
|
||||
nodeIdentifier,
|
||||
client: SatXMPPEntity,
|
||||
service: jid.JID,
|
||||
nodeIdentifier: str,
|
||||
sub_jid=None,
|
||||
subscriptionIdentifier=None,
|
||||
sender=None,
|
||||
):
|
||||
return await client.pubsub_client.unsubscribe(
|
||||
await client.pubsub_client.unsubscribe(
|
||||
service,
|
||||
nodeIdentifier,
|
||||
sub_jid or client.jid.userhostJID(),
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue