[folks] telepathy: Handle contact removals from groups



commit 0010985fe858635b1ba059cdfa1b4d5e2468dd4a
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Mar 4 13:10:30 2012 +0000

    telepathy: Handle contact removals from groups
    
    Closes: https://bugzilla.gnome.org/show_bug.cgi?id=669984

 NEWS                                          |    1 +
 backends/telepathy/lib/tpf-persona-store.vala |   63 ++++++++++++++++++++----
 backends/telepathy/lib/tpf-persona.vala       |   10 ++--
 folks/individual.vala                         |    8 +---
 4 files changed, 58 insertions(+), 24 deletions(-)
---
diff --git a/NEWS b/NEWS
index c0cc840..c1c9858 100644
--- 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
 =============================================================
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index 7506289..aec05b8 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -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 */
     }
 
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 0b8f864..597d134 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -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);
diff --git a/folks/individual.vala b/folks/individual.vala
index 2a0f6cd..2f9050d 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -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);
             }
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]