changeset 529:c18e0e108925

plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
author Goffi <goffi@goffi.org>
date Mon, 22 Oct 2012 00:10:21 +0200
parents f899f6e2a9d1
children 6c07127ad2ed
files src/plugins/plugin_exp_parrot.py src/plugins/plugin_misc_groupblog.py
diffstat 2 files changed, 38 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_exp_parrot.py	Sun Oct 21 22:31:57 2012 +0200
+++ b/src/plugins/plugin_exp_parrot.py	Mon Oct 22 00:10:21 2012 +0200
@@ -87,7 +87,6 @@
                     src_txt = from_jid.resource
                     if src_txt == self.host.plugins["XEP-0045"].getRoomNick(from_jid.userhost(), profile):
                         #we won't repeat our own messages
-                        print "\n\nDISCARD\n\n"
                         return True
                 else:
                     src_txt = from_jid.user
--- a/src/plugins/plugin_misc_groupblog.py	Sun Oct 21 22:31:57 2012 +0200
+++ b/src/plugins/plugin_misc_groupblog.py	Mon Oct 22 00:10:21 2012 +0200
@@ -70,6 +70,9 @@
 class BadAccessListError(Exception):
     pass
 
+class UnknownType(Exception):
+    pass
+
 class GroupBlog():
     """This class use a SàT PubSub Service to manage access on microblog"""
 
@@ -271,17 +274,26 @@
             if publishers_type == "ALL":
                 contacts = client.roster.getItems()
                 jids = [contact.jid.userhost() for contact in contacts]
-                mblogs = []
-                for _jid in jids:
-                    d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
-                                                               max_items=max_items, profile_key=profile_key)
-                    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)
-                return dlist
-
-            return defer.fail("Unknown type")
+            elif publishers_type == "GROUP":
+                jids = []
+                for _group in publishers:
+                    jids.extend(client.roster.getJidsFromGroup(_group))
+            elif publishers_type == 'JID':
+                jids = publishers
+            else:
+                raise UnknownType
+            
+            mblogs = []
+            
+            for _jid in jids:
+                d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
+                                                           max_items=max_items, profile_key=profile_key)
+                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)
+            
+            return dlist
 
 
         #TODO: custom exception
@@ -315,15 +327,22 @@
             if publishers_type == "ALL":
                 contacts = client.roster.getItems()
                 jids = [contact.jid.userhost() for contact in contacts]
-                mblogs = []
-                for _jid in jids:
-                    d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
-                                                                profile_key=profile_key)
-                    mblogs.append(d)
-                dlist = defer.DeferredList(mblogs)
-                return dlist
+            elif publishers_type == "GROUP":
+                jids = []
+                for _group in publishers:
+                    jids.extend(client.roster.getJidsFromGroup(_group))
+            elif publishers_type == 'JID':
+                jids = publishers
+            else:
+                raise UnknownType
 
-            return defer.fail("Unknown type")
+            mblogs = []
+            for _jid in jids:
+                d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
+                                                            profile_key=profile_key)
+                mblogs.append(d)
+            dlist = defer.DeferredList(mblogs)
+            return dlist
 
 
         #TODO: custom exception