plugin XEP-0060: sender can now be specified in sendItems and publish:

if not sended is set, `client.jid` is used.
This commit is contained in:
Goffi 2022-07-21 18:02:33 +02:00
commit c20e09fb22

View file

@ -534,7 +534,7 @@ class XEP_0060(object):
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 @@ class XEP_0060(object):
service,
nodeIdentifier,
[item_elt],
extra
extra=extra
)
try:
return published_ids[0]
@ -570,9 +570,10 @@ class XEP_0060(object):
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 @@ class XEP_0060(object):
"""
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 @@ class XEP_0060(object):
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 @@ class XEP_0060(object):
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 @@ class XEP_0060(object):
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,
)