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
1 changed files with 41 additions and 8 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue