diff src/plugins/plugin_xep_0277.py @ 339:b0b773f432e5

plugin XEP-00277: setMicroblogAccess is now asynchronous
author Goffi <goffi@goffi.org>
date Thu, 26 May 2011 16:48:23 +0200
parents 0aa6ca6cdbdd
children 6fe6ae70904a
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Thu May 26 16:47:39 2011 +0200
+++ b/src/plugins/plugin_xep_0277.py	Thu May 26 16:48:23 2011 +0200
@@ -48,6 +48,9 @@
 "description": _("""Implementation of microblogging Protocol""")
 }
 
+class NodeAccessChangeException(Exception):
+    pass
+
 class XEP_0277():
 
     def __init__(self, host):
@@ -66,6 +69,7 @@
                                     })
         host.bridge.addMethod("setMicroblogAccess", ".communication", in_sign='ss', out_sign='',
                                method=self.setMicroblogAccess,
+                               async = True,
                                doc = {
                                      })
 
@@ -152,7 +156,7 @@
         d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key)
         d.addCallbacks(lambda items: callback(map(self._item2mbdata, items)), errback)
         
-    def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@'):
+    def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None):
         """Create a microblog node on PEP with given access
         If the node already exists, it change options
         @param access: Node access model, according to xep-0060 #4.5
@@ -166,10 +170,12 @@
         def cb(result):
             #Node is created with right permission
             debug(_("Microblog node has now access %s") % access)
+            callback()
 
         def fatal_err(s_error):
             #Something went wrong
             error(_("Can't set microblog access"))
+            errback(NodeAccessChangeException())
 
         def err_cb(s_error):
             #If the node already exists, the condition is "conflict",