diff src/plugins/plugin_xep_0277.py @ 1451:9b88b19b1ca8

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.
author Goffi <goffi@goffi.org>
date Sat, 15 Aug 2015 22:20:56 +0200
parents 7797dda847ae
children 5116d70ddd1c
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Sat Aug 15 22:20:43 2015 +0200
+++ b/src/plugins/plugin_xep_0277.py	Sat Aug 15 22:20:56 2015 +0200
@@ -61,6 +61,7 @@
     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 @@
             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 @@
         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 @@
                 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 @@
         @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)