diff src/plugins/plugin_misc_groupblog.py @ 726:ade9997fabfa

core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
author Goffi <goffi@goffi.org>
date Tue, 10 Dec 2013 17:25:31 +0100
parents 6aa71c853bf5
children 80c1072390f3
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py	Tue Dec 03 13:51:08 2013 +0100
+++ b/src/plugins/plugin_misc_groupblog.py	Tue Dec 10 17:25:31 2013 +0100
@@ -98,7 +98,7 @@
 
         host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin",
                               in_sign='sasis', out_sign='a{saa{ss}}',
-                              method=self.getMassiveLastGroupBlogs,
+                              method=self._getMassiveLastGroupBlogs,
                               async=True)
 
         host.bridge.addMethod("getGroupBlogComments", ".plugin",
@@ -111,7 +111,7 @@
                               async=True)
 
         host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
-                              method=self.massiveSubscribeGroupBlogs,
+                              method=self._massiveSubscribeGroupBlogs,
                               async=True)
 
         host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
@@ -435,6 +435,13 @@
         #TODO: we need to use the server corresponding the the host of the jid
         return self._initialise(profile_key).addCallback(initialised)
 
+    def _getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'):
+        if publishers_type == 'JID':
+            publishers_jids = [jid.JID(publisher) for publisher in publishers]
+        else:
+            publishers_jid = publishers
+        return getMassiveLastGroupBlogs(publishers_type, publishers_jid, max_items, profile_key)
+
     def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'):
         """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")
@@ -460,7 +467,7 @@
 
             if publishers_type == "ALL":
                 contacts = client.roster.getItems()
-                jids = [contact.jid.userhost() for contact in contacts]
+                jids = [contact.jid.userhostJID() for contact in contacts]
             elif publishers_type == "GROUP":
                 jids = []
                 for _group in publishers:
@@ -473,12 +480,11 @@
             mblogs = []
 
 
-            for jid_s in jids:
-                _jid = jid.JID(jid_s)
-                d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(_jid),
+            for jid_ in jids:
+                d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid_),
                                                            max_items=max_items, profile_key=profile_key)
-                d.addCallback(self._itemsConstruction, _jid, client)
-                d.addCallback(lambda gbdata, source_jid: (source_jid, gbdata), jid_s)
+                d.addCallback(self._itemsConstruction, jid_, client)
+                d.addCallback(lambda gbdata, source_jid: (source_jid, gbdata), jid_.full())
 
                 mblogs.append(d)
             dlist = defer.DeferredList(mblogs)
@@ -504,6 +510,13 @@
         #TODO: we need to use the server corresponding the the host of the jid
         return self._initialise(profile_key).addCallback(initialised)
 
+    def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'):
+        if publishers_type == 'JID':
+            publishers_jids = [jid.JID(publisher) for publisher in publishers]
+        else:
+            publishers_jid = publishers
+        return massiveSubscribeGroupBlogs(publishers_type, publishers_jid, profile_key)
+
     def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'):
         """Subscribe microblogs for a list of groups or jids
         @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
@@ -516,7 +529,7 @@
 
             if publishers_type == "ALL":
                 contacts = client.roster.getItems()
-                jids = [contact.jid.userhost() for contact in contacts]
+                jids = [contact.jid.userhostJID() for contact in contacts]
             elif publishers_type == "GROUP":
                 jids = []
                 for _group in publishers:
@@ -527,8 +540,8 @@
                 raise UnknownType
 
             mblogs = []
-            for _jid in jids:
-                d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
+            for jid_ in jids:
+                d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid_),
                                                             profile_key=profile_key)
                 mblogs.append(d)
             dlist = defer.DeferredList(mblogs)