changeset 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 7c806491c76a
children c1cd6c0c2c38
files src/core/xmpp.py src/plugins/plugin_misc_groupblog.py
diffstat 2 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/xmpp.py	Tue Dec 03 13:51:08 2013 +0100
+++ b/src/core/xmpp.py	Tue Dec 10 17:25:31 2013 +0100
@@ -218,7 +218,7 @@
         info(_("new contact in roster list: %s"), item.jid.full())
         #self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile)
 
-        bare_jid = item.jid.userhost()
+        bare_jid = item.jid.userhostJID()
         self._jids[bare_jid] = item
         for group in item.groups:
             self._groups.setdefault(group, set()).add(bare_jid)
@@ -227,7 +227,7 @@
     def onRosterRemove(self, entity):
         """Called when a roster removal event is received"""
         print _("removing %s from roster list") % entity.full()
-        bare_jid = entity.userhost()
+        bare_jid = entity.userhostJID()
 
         # we first remove item from local cache (self._groups and self._jids)
         try:
@@ -256,7 +256,7 @@
         """Return RosterItem for a given jid
         @param jid: jid of the contact
         @return: RosterItem or None if contact is not in cache"""
-        return self._jids.get(jid.userhost(), None)
+        return self._jids.get(jid.userhostJID(), None)
 
     def getBareJids(self):
         """Return all bare jids (as unicode) of the roster"""
@@ -264,7 +264,7 @@
 
     def isJidInRoster(self, entity_jid):
         """Return True if jid is in roster"""
-        return entity_jid.userhost() in self._jids
+        return entity_jid.userhostJID() in self._jids
 
     def getItems(self):
         """Return all items of the roster"""
--- 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)