changeset 1000:6f1e03068b5f

primitivus: fixes contact group update
author souliane <souliane@mailoo.org>
date Sun, 27 Apr 2014 18:22:12 +0200
parents c37a24922f27
children eb3601ff73bc
files frontends/src/primitivus/contact_list.py frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_contact_list.py frontends/src/wix/contact_list.py
diffstat 4 files changed, 40 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/contact_list.py	Fri Apr 11 11:02:42 2014 +0200
+++ b/frontends/src/primitivus/contact_list.py	Sun Apr 27 18:22:12 2014 +0200
@@ -234,20 +234,32 @@
         self.update()
 
     def replace(self, jid, groups=None, attributes=None):
-        """add a contact to the list if doesn't exist, else update it"""
+        """Add a contact to the list if doesn't exist, else update it.
+
+        @param jid (JID)
+        @param groups (list): list of groups or None to ignore the groups membership.
+        @param attributes (dict)
+
+        XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
+        """
         QuickContactList.replace(self, jid, groups, attributes)
         if jid.bare in self.specials:
             return
-        if not groups:
-            groups = [None]
         if not attributes:
-            attributes={}
-        assert isinstance(groups, list)
+            attributes = {}
         assert isinstance(jid, JID)
-        for group in groups:
-            if not self.groups.has_key(group):
-                self.groups[group] = [True,set()]  #[unfold,list_of_contacts]
-            self.groups[group][1].add(jid.bare)
+        if groups is not None:
+            if not groups:
+                groups = [None]
+            for group in [group for group in self.groups if group not in groups]:
+                try:  # remove the contact from a previous group
+                    self.groups[group][1].remove(jid.bare)
+                except KeyError:
+                    pass
+            for group in groups:
+                if group not in self.groups:
+                    self.groups[group] = [True, set()]  # [unfold, list_of_contacts]
+                self.groups[group][1].add(jid.bare)
         self.update()
 
     def remove(self, jid):
@@ -264,9 +276,9 @@
             del self.groups[group]
         self.update()
 
-    def add(self, jid, param_groups=[None]):
+    def add(self, jid, param_groups=None):
         """add a contact to the list"""
-        self.replace(jid,param_groups)
+        self.replace(jid, param_groups)
 
     def setSpecial(self, special_jid, special_type, show=False):
         """Set entity as a special
--- a/frontends/src/primitivus/primitivus	Fri Apr 11 11:02:42 2014 +0200
+++ b/frontends/src/primitivus/primitivus	Sun Apr 27 18:22:12 2014 +0200
@@ -388,8 +388,7 @@
         if not from_jid in self.contact_list and from_jid.bare != self.profiles[profile]['whoami'].bare:
             #XXX: needed to show entities which haven't sent any
             #     presence information and which are not in roster
-            #TODO: put these entities in a "not in roster" list
-            self.contact_list.replace(from_jid)
+            self.contact_list.replace(from_jid, ['Not in roster'])
 
         if JID(self.contact_list.selected).bare != from_jid.bare:
             self.contact_list.putAlert(from_jid)
--- a/frontends/src/quick_frontend/quick_contact_list.py	Fri Apr 11 11:02:42 2014 +0200
+++ b/frontends/src/quick_frontend/quick_contact_list.py	Sun Apr 27 18:22:12 2014 +0200
@@ -54,7 +54,14 @@
         self.specials.clear()
 
     def replace(self, jid, groups=None, attributes=None):
-        """add a contact to the list if doesn't exist, else update it"""
+        """Add a contact to the list if doesn't exist, else update it.
+
+        @param jid (JID)
+        @param groups (list): list of groups or None to ignore the groups membership.
+        @param attributes (dict)
+
+        XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
+        """
         if attributes and 'name' in attributes:
             self.setCache(jid, 'name', attributes['name'])
 
--- a/frontends/src/wix/contact_list.py	Fri Apr 11 11:02:42 2014 +0200
+++ b/frontends/src/wix/contact_list.py	Sun Apr 27 18:22:12 2014 +0200
@@ -76,6 +76,14 @@
         self.replace(jid)
 
     def replace(self, contact, groups=None, attributes=None):
+        """Add a contact to the list if doesn't exist, else update it.
+
+        @param jid (JID)
+        @param groups (list): list of groups or None to ignore the groups membership.
+        @param attributes (dict)
+
+        XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
+        """
         debug(_("update %s") % contact)
         if not self.__find_idx(contact):
             self.add(contact, groups)