=?utf-8?q?=5Bfolks=5D_Bug_679618_=E2=80=94_Crash_when_unsetting_all_group?= =?utf-8?q?s?=



commit 553b3e12454281604b48c27c5b14a6cfc746d142
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Jul 9 21:18:41 2012 +0100

    Bug 679618 â Crash when unsetting all groups
    
    Rework the group changing code in Tpf.Persona so that:
     1. change_groups() no longer changes the set of groups while iterating
        over it; and
     2. batch Telepathy calls are made where possible, rather than one call per
        group change.
    
    Closes: https://bugzilla.gnome.org/show_bug.cgi?id=679618

 NEWS                                    |    1 +
 backends/telepathy/lib/tpf-persona.vala |   30 ++++++++++--------------------
 2 files changed, 11 insertions(+), 20 deletions(-)
---
diff --git a/NEWS b/NEWS
index 79462fb..396cdf6 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Dependencies:
 Bugs fixed:
 â Bug 673918 â Port to newer libgee
 â Bug 629537 â Support anti-linking
+â Bug 679618 â Crash when unsetting all groups
 
 API changes:
 â Add AntiLinkable interface and implement it on Kf.Persona and Edsf.Persona
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 005a30d..8134d52 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -474,24 +474,13 @@ public class Tpf.Persona : Folks.Persona,
   public async void change_group (string group, bool is_member)
       throws GLib.Error
     {
-      if (this._groups.contains (group) != is_member)
-        {
-          yield this._change_group_membership (group, is_member);
-        }
-
-      /* The change will be notified when we receive changes from the store. */
-    }
-
-  private async void _change_group_membership (string group,
-      bool is_member) throws Folks.PropertyError
-    {
       try
         {
-          if (is_member)
+          if (is_member && !this._groups.contains (group))
             {
               yield this.contact.add_to_group_async (group);
             }
-          else
+          else if (!is_member && this._groups.contains (group))
             {
               yield this.contact.remove_from_group_async (group);
             }
@@ -502,6 +491,8 @@ public class Tpf.Persona : Folks.Persona,
           throw new PropertyError.UNKNOWN_ERROR (
               _("Failed to change group membership: %s"), e.message);
         }
+
+      /* The change will be notified when we receive changes from the store. */
     }
 
   /* Note: Only ever called as a result of signals from Telepathy. */
@@ -547,16 +538,15 @@ public class Tpf.Persona : Folks.Persona,
    */
   public async void change_groups (Set<string> groups) throws PropertyError
     {
-      foreach (var group1 in groups)
+      try
         {
-          if (this._groups.contains (group1) == false)
-            yield this._change_group_membership (group1, true);
+          yield this.contact.set_contact_groups_async (groups.to_array ());
         }
-
-      foreach (var group2 in this._groups)
+      catch (GLib.Error e)
         {
-          if (groups.contains (group2) == false)
-            yield this._change_group_membership (group2, false);
+          /* Translators: the parameter is an error message. */
+          throw new PropertyError.UNKNOWN_ERROR (
+              _("Failed to change group membership: %s"), e.message);
         }
 
       /* The change will be notified when we receive changes from the store. */



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