plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):

serItemsData is used for normal callbacks, and serItemsDataD for callbacks which return deferred. These methods simplifly the code by making the re-use of getItems more easy.
This commit is contained in:
Goffi 2015-08-15 22:20:56 +02:00
commit 7e83aaedb3

View file

@ -61,6 +61,7 @@ class XEP_0277(object):
def __init__(self, host):
log.info(_("Microblogging plugin initialization"))
self.host = host
self._p = self.host.plugins["XEP-0060"] # this facilitate the access to pubsub plugin
self.host.plugins["XEP-0163"].addPEPEvent("MICROBLOG", NS_MICROBLOG, self.microblogCB, self.sendMicroblog, notify=False)
host.bridge.addMethod("getLastMicroblogs", ".plugin",
in_sign='sis', out_sign='(aa{ss}a{ss})',
@ -310,7 +311,7 @@ class XEP_0277(object):
log.error("Microblog data's content value must not be empty")
raise failure.Failure(exceptions.DataError('empty content'))
item = yield self.data2entry(data, profile)
ret = yield self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile)
ret = yield self._p.publish(None, NS_MICROBLOG, [item], profile_key=profile)
defer.returnValue(ret)
## get ##
@ -373,8 +374,7 @@ class XEP_0277(object):
if not _jid:
log.error(_("Can't find profile's jid"))
return
C = self.host.plugins["XEP-0060"]
_options = {C.OPT_ACCESS_MODEL: access, C.OPT_PERSIST_ITEMS: 1, C.OPT_MAX_ITEMS: -1, C.OPT_DELIVER_PAYLOADS: 1, C.OPT_SEND_ITEM_SUBSCRIBE: 1}
_options = {self._p.OPT_ACCESS_MODEL: access, self._p.OPT_PERSIST_ITEMS: 1, self._p.OPT_MAX_ITEMS: -1, self._p.OPT_DELIVER_PAYLOADS: 1, self._p.OPT_SEND_ITEM_SUBSCRIBE: 1}
def cb(result):
#Node is created with right permission
@ -396,10 +396,10 @@ class XEP_0277(object):
fatal_err(s_error)
def create_node():
return self.host.plugins["XEP-0060"].createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key)
return self._p.createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key)
def change_node_options():
return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key)
return self._p.setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key)
create_node().addCallback(cb).addErrback(err_cb)
@ -466,5 +466,5 @@ class XEP_0277(object):
@return (str): session id
"""
client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key)
return self.host.plugins["XEP-0060"].subscribeToMany(node_data, client.jid.userhostJID(), profile_key=profile_key)
return self._p.subscribeToMany(node_data, client.jid.userhostJID(), profile_key=profile_key)