telepathy: Handle contact removals from groups
authorPhilip Withnall <philip@tecnocode.co.uk>
Sun, 4 Mar 2012 13:10:30 +0000 (13:10 +0000)
committerPhilip Withnall <philip@tecnocode.co.uk>
Mon, 26 Mar 2012 11:01:44 +0000 (12:01 +0100)
Closes: https://bugzilla.gnome.org/show_bug.cgi?id=669984

NEWS
backends/telepathy/lib/tpf-persona-store.vala
backends/telepathy/lib/tpf-persona.vala
folks/individual.vala

diff --git a/NEWS b/NEWS
index c0cc840..c1c9858 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Bugs fixed:
 * Bug 670348 — Handle Telepathy CMs crashing/being invalidated
 * Bug 671900 — Folks should not suggest linking contacts from telepathy-salut
 * Bug 670872 — Should be less sensitive to accentuated chars
+* Bug 669984 — Does not notify when contacts are added to groups
 
 Overview of changes from libfolks 0.6.6 to libfolks 0.6.7
 =============================================================
index 7506289..aec05b8 100644 (file)
@@ -1733,25 +1733,61 @@ public class Tpf.PersonaStore : Folks.PersonaStore
               var channel_handle = (Handle) adds.index (i);
               var contact_handle = channel.group_get_handle_owner (
                 channel_handle);
-              var persona = this._handle_persona_map[contact_handle];
-              if (persona == null)
+
+              HashSet<uint>? contact_handles =
+                  this._channel_group_incoming_adds[channel];
+              if (contact_handles == null)
                 {
-                  HashSet<uint>? contact_handles =
-                      this._channel_group_incoming_adds[channel];
-                  if (contact_handles == null)
-                    {
-                      contact_handles = new HashSet<uint> ();
-                      this._channel_group_incoming_adds[channel] =
-                          contact_handles;
-                    }
-                  contact_handles.add (contact_handle);
+                  contact_handles = new HashSet<uint> ();
+                  this._channel_group_incoming_adds[channel] =
+                      contact_handles;
                 }
+              contact_handles.add (contact_handle);
             }
         }
 
       this._channel_groups_add_new_personas ();
     }
 
+  private void _channel_group_handle_incoming_removes (Channel channel,
+      Array<uint> removes)
+    {
+      var removes_length = removes != null ? removes.length : 0;
+      if (removes_length >= 1)
+        {
+          var members_removed = new GLib.List<Persona> ();
+
+          HashSet<Persona> members = this._channel_group_personas_map[channel];
+          if (members == null)
+            members = new HashSet<Persona> ();
+
+          for (var i = 0; i < removes.length; i++)
+            {
+              var channel_handle = (Handle) removes.index (i);
+              var contact_handle = channel.group_get_handle_owner (
+                channel_handle);
+              var persona = this._handle_persona_map[contact_handle];
+
+
+              if (persona != null)
+                {
+                  members.remove (persona);
+                  members_removed.prepend (persona);
+                }
+            }
+
+          this._channel_group_personas_map[channel] = members;
+
+          var name = channel.get_identifier ();
+          if (this._group_is_display_group (name) &&
+              members_removed.length () > 0)
+            {
+              members_removed.reverse ();
+              this.group_members_changed (name, null, members_removed);
+            }
+        }
+    }
+
   private void _set_up_new_group_channel (Channel channel)
     {
       /* hold a ref to the channel here until it's ready, so it doesn't
@@ -1817,6 +1853,11 @@ public class Tpf.PersonaStore : Folks.PersonaStore
       if (added != null)
         this._channel_group_pend_incoming_adds.begin (channel, added, false);
 
+      if (removed != null)
+        {
+          this._channel_group_handle_incoming_removes (channel, removed);
+        }
+
       /* FIXME: continue for the other arrays */
     }
 
index 0b8f864..597d134 100644 (file)
@@ -425,14 +425,12 @@ public class Tpf.Persona : Folks.Persona,
 
       if (is_member)
         {
-          if (!this._groups.contains (group))
-            {
-              this._groups.add (group);
-              changed = true;
-            }
+          changed = this._groups.add (group);
         }
       else
-        changed = this._groups.remove (group);
+        {
+          changed = this._groups.remove (group);
+        }
 
       if (changed == true)
         this.group_changed (group, is_member);
index 2a0f6cd..2f9050d 100644 (file)
@@ -1205,14 +1205,8 @@ public class Folks.Individual : Object,
 
       foreach (var group in new_groups)
         {
-          if (!this._groups.contains (group))
+          if (this._groups.add (group))
             {
-              this._groups.add (group);
-              foreach (var g in this._groups)
-                {
-                  debug ("   %s", g);
-                }
-
               this.group_changed (group, true);
             }
         }