diff src/plugins/plugin_misc_groupblog.py @ 470:5c916b99d0f6

plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
author Goffi <goffi@goffi.org>
date Sun, 01 Apr 2012 19:48:31 +0200
parents 47af60767013
children 6cd04adddaea
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py	Sun Apr 01 19:45:35 2012 +0200
+++ b/src/plugins/plugin_misc_groupblog.py	Sun Apr 01 19:48:31 2012 +0200
@@ -167,7 +167,7 @@
 
 
         
-    def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
+    def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
         """Get the last published microblogs
         @param pub_jid: jid of the publisher
         @param max_items: how many microblogs we want to get
@@ -180,20 +180,17 @@
             profile, client = result
             d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
                                                        max_items=max_items, profile_key=profile_key)
-            d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback)
+            d.addCallback(lambda items: map(self.host.plugins["XEP-0277"].item2mbdata, items))
 
-        assert(callback)
         self.initialise(profile_key).addCallback(initialised)
         #TODO: we need to use the server corresponding the the host of the jid
 
-    def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
+    def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@'):
         """Get the last published microblogs for a list of groups or jids
         @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
         @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
         @param max_items: how many microblogs we want to get
         @param profile_key: profile key
-        @param callback: used for the async answer
-        @param errback: used for the async answer
         """
         def sendResult(result):
             """send result of DeferredList (list of microblogs to the calling method"""
@@ -205,31 +202,27 @@
                     source_jid, data = value
                     ret[source_jid] = data
             
-            callback(ret)
+            return ret
 
         def initialised(result):
             profile, client = result
 
             if publishers_type == "ALL":
                 contacts = client.roster.getItems()
-                print "contacts:", contacts
                 jids = [contact.jid.userhost() for contact in contacts]
-                print "jids:", jids
                 mblogs = []
                 for _jid in jids:
                     d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(_jid).userhost(),
                                                                max_items=max_items, profile_key=profile_key)
-                    #TODO: check empty result (nothing published so far) 
                     d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid)
                     mblogs.append(d)
                 dlist = defer.DeferredList(mblogs)
-                dlist.addCallback(sendResult) 
+                dlist.addCallback(sendResult)
+                return dlist
 
-            #d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
-            #                                           max_items=max_items, profile_key=profile_key)
-            #d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback)
+            return defer.fail("Unknown type")
 
-        assert(callback)
+
         #TODO: custom exception
         if publishers_type not in ["GROUP", "JID", "ALL"]:
             raise Exception("Bad call, unknown publishers_type")