core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol

This commit is contained in:
Goffi 2013-12-10 17:25:31 +01:00
commit 2ad1019de7
2 changed files with 28 additions and 15 deletions

View file

@ -218,7 +218,7 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
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 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
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 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
"""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 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
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"""

View file

@ -98,7 +98,7 @@ class GroupBlog(object):
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 @@ class GroupBlog(object):
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 @@ class GroupBlog(object):
#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 @@ class GroupBlog(object):
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 @@ class GroupBlog(object):
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 @@ class GroupBlog(object):
#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 @@ class GroupBlog(object):
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 @@ class GroupBlog(object):
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)