From f4a4b799864bcb30628d41355f44a4b67a993582 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 24 Jun 2013 23:22:42 +0200 Subject: =?UTF-8?q?fix=20#2327=20(don=E2=80=99t=20include=20chatrooms=20in?= =?UTF-8?q?=20the=20roster)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it might be a little slower than before (more checks) --- src/roster.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/roster.py b/src/roster.py index 8c1b8f3e..a288ec4d 100644 --- a/src/roster.py +++ b/src/roster.py @@ -101,6 +101,13 @@ class Roster(object): """Our JID""" return self.__node.jid + def get_and_set(self, jid): + if not jid in self.contacts: + contact = Contact(self.__node[jid]) + self.contacts[jid] = contact + return contact + return self.contacts[jid] + def set_node(self, value): """Set the SleekXMPP RosterSingle for our roster""" self.__node = value @@ -135,7 +142,12 @@ class Roster(object): def jids(self): """List of the contact JIDS""" - return [key for key in self.__node.keys() if key != self.jid] + l = [] + for key in self.__node.keys(): + contact = self.get_and_set(key) + if key != self.jid and (contact and self.exists(contact)): + l.append(key) + return l def get_contacts(self): """ @@ -181,7 +193,7 @@ class Roster(object): """ n = 0 for contact in self: - if len(contact): + if self.exists(contact) and len(contact): n += 1 return n @@ -208,7 +220,7 @@ class Roster(object): (used to return the display size, but now we have the display cache in RosterWin for that) """ - return len(self.contacts) + return len(self.jids()) def __repr__(self): ret = '== Roster:\nContacts:\n' @@ -231,6 +243,15 @@ class Roster(object): except IOError: return + def exists(self, contact): + if not contact: + return False + for group in contact.groups: + if contact not in self.groups.get(group, tuple()): + return False + return True + + class RosterGroup(object): """ A RosterGroup is a group containing contacts @@ -298,6 +319,5 @@ class RosterGroup(object): """Return the number of connected contacts""" return len([1 for contact in self.contacts if len(contact)]) - # Shared roster object roster = Roster() -- cgit v1.2.3