plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
This commit is contained in:
parent
71d61f372f
commit
e22336c6f2
4 changed files with 41 additions and 8 deletions
|
|
@ -236,7 +236,7 @@ class Events(object):
|
|||
if e.condition == u'conflict':
|
||||
log.debug(_(u"requested node already exists"))
|
||||
|
||||
yield self._p.publish(service, node, items=[item_elt], profile_key=client.profile)
|
||||
yield self._p.publish(client, service, node, items=[item_elt])
|
||||
|
||||
defer.returnValue(node)
|
||||
|
||||
|
|
@ -313,4 +313,4 @@ class Events(object):
|
|||
except KeyError:
|
||||
pass
|
||||
item_elt = pubsub.Item(id=client.jid.userhost(), payload=event_elt)
|
||||
return self._p.publish(service, node, items=[item_elt], profile_key=client.profile)
|
||||
return self._p.publish(client, service, node, items=[item_elt])
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ from sat.core.constants import Const as C
|
|||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from sat.core import exceptions
|
||||
|
||||
from sat.tools import sat_defer
|
||||
|
||||
from twisted.words.protocols.jabber import jid, error
|
||||
|
|
@ -93,7 +92,8 @@ class XEP_0060(object):
|
|||
host.bridge.addMethod("psNodeAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeAffiliations, async=True)
|
||||
host.bridge.addMethod("psNodeAffiliationsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeAffiliations, async=True)
|
||||
host.bridge.addMethod("psNodeDelete", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True)
|
||||
host.bridge.addMethod("psItemGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True)
|
||||
host.bridge.addMethod("psItemsGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True)
|
||||
host.bridge.addMethod("psItemSend", ".plugin", in_sign='ssssa{ss}s', out_sign='s', method=self._sendItem, async=True)
|
||||
host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True)
|
||||
host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True)
|
||||
host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany)
|
||||
|
|
@ -258,8 +258,41 @@ class XEP_0060(object):
|
|||
# d.addCallback(lambda subs: [sub.getAttribute('node') for sub in subs if sub.getAttribute('subscription') == filter_])
|
||||
# return d
|
||||
|
||||
def publish(self, service, nodeIdentifier, items=None, profile_key=C.PROF_KEY_NONE):
|
||||
def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE):
|
||||
client = self.host.getClient(profile_key)
|
||||
service = None if not service else jid.JID(service)
|
||||
d = self.sendItem(client, service, nodeIdentifier, payload, item_id or None, extra)
|
||||
d.addCallback(lambda ret: ret or u'')
|
||||
return d
|
||||
|
||||
def _getPublishedItemId(self, iq_elt, original_id):
|
||||
"""return item of published id if found in answer
|
||||
|
||||
if not found original_id is returned, or empty string if it is None or empty string
|
||||
"""
|
||||
try:
|
||||
item_id = iq_elt.pubsub.publish.item['id']
|
||||
except (AttributeError, KeyError):
|
||||
item_id = None
|
||||
return item_id or original_id
|
||||
|
||||
def sendItem(self, client, service, nodeIdentifier, payload, item_id=None, extra=None):
|
||||
"""high level method to send one item
|
||||
|
||||
@param service(jid.JID, None): service to send the item to
|
||||
None to use PEP
|
||||
@param NodeIdentifier(unicode): PubSub node to use
|
||||
@param item_id(unicode, None): id to use or None to create one
|
||||
@param payload(domish.Element, unicode): payload of the item to send
|
||||
@param extra(dict, None): extra option, not used yet
|
||||
@return (unicode, None): id of the created item
|
||||
"""
|
||||
item_elt = pubsub.Item(id=item_id, payload=payload)
|
||||
d = self.publish(client, service, nodeIdentifier, [item_elt])
|
||||
d.addCallback(self._getPublishedItemId, item_id)
|
||||
return d
|
||||
|
||||
def publish(self, client, service, nodeIdentifier, items=None):
|
||||
return client.pubsub_client.publish(service, nodeIdentifier, items, client.pubsub_client.parent.jid)
|
||||
|
||||
def _unwrapMAMMessage(self, message_elt):
|
||||
|
|
|
|||
|
|
@ -98,9 +98,9 @@ class XEP_0163(object):
|
|||
@param data: domish.Element to use as payload
|
||||
@param profile: profile which send the data
|
||||
"""
|
||||
|
||||
client = self.host.getClient(profile)
|
||||
item = pubsub.Item(payload=data)
|
||||
return self.host.plugins["XEP-0060"].publish(None, node, [item], profile_key=profile)
|
||||
return self.host.plugins["XEP-0060"].publish(client, None, node, [item])
|
||||
|
||||
def PEPSend(self, event_type, data, profile_key=C.PROF_KEY_NONE):
|
||||
"""Send personal event after checking the data is alright
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ class XEP_0277(object):
|
|||
except error.StanzaError:
|
||||
log.warning(u"Can't create comments node for item {}".format(item_id))
|
||||
item = yield self.data2entry(data, item_id, client.profile)
|
||||
ret = yield self._p.publish(service, node, [item], profile_key=client.profile)
|
||||
ret = yield self._p.publish(client, service, node, [item])
|
||||
defer.returnValue(ret)
|
||||
|
||||
## retract ##
|
||||
|
|
|
|||
Loading…
Reference in a new issue