summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-06-24 23:22:42 +0200
committermathieui <mathieui@mathieui.net>2013-06-24 23:22:42 +0200
commitf4a4b799864bcb30628d41355f44a4b67a993582 (patch)
tree0e5678ab8152ebd556580848a62ca27103a43bc0
parentb70c154ff6527ed4916bb7802ba5ed5375e1db60 (diff)
downloadpoezio-f4a4b799864bcb30628d41355f44a4b67a993582.tar.gz
poezio-f4a4b799864bcb30628d41355f44a4b67a993582.tar.bz2
poezio-f4a4b799864bcb30628d41355f44a4b67a993582.tar.xz
poezio-f4a4b799864bcb30628d41355f44a4b67a993582.zip
fix #2327 (don’t include chatrooms in the roster)
it might be a little slower than before (more checks)
-rw-r--r--src/roster.py28
1 files 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()