[folks] Add a "user" property to the IndividualAggregator



commit 24732788143198877b528dcf06f147a77ee2b7e7
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Mon Aug 23 16:31:49 2010 +0100

    Add a "user" property to the IndividualAggregator
    
    This contains the Individual representing the user who owns all the relevant
    accounts in each backend. This also changes the linking code so that Personas
    with is_user == true are always linked, and only ever linked to other Personas
    with is_user == true (i.e. Personas are always linked to Personas with like
    is_user values). This ensures that there's only ever one Individual with
    is_user == true. Helps: bgo#627402

 NEWS                                          |    1 +
 backends/telepathy/lib/tpf-persona-store.vala |   10 ++++++-
 folks/individual-aggregator.vala              |   34 +++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index a65a99f..64709a4 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ API changes:
 * Added BackendStore::enabled-backends
 * Added Individual::is-user
 * Added Persona::is-user
+* Added IndividualAggregator::user
 
 Bugs fixed:
 * Bug 629452 â?? [Patch] Add missing gio linking for import-tool
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index c8cb1c9..99d3690 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -279,8 +279,14 @@ public class Tpf.PersonaStore : Folks.PersonaStore
            * likely because the account hasn't connected yet (and we haven't
            * received the roster). If there are already entries in
            * handle_persona_map, the account *is* connected and we should
-           * warn about the unknown persona. */
-          if (p == null && this.handle_persona_map.size > 0)
+           * warn about the unknown persona.
+           * We have to take into account that this.self_contact may be
+           * retrieved before or after the rest of the account's contact list,
+           * affecting the size of this.handle_persona_map. */
+          if (p == null &&
+              ((this.self_contact == null &&
+                this.handle_persona_map.size > 0) ||
+               (this.self_contact != null && this.handle_persona_map.size > 1)))
             {
               warning ("unknown persona '%s' in favourites list", ids[i]);
               continue;
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 9a7745c..6191a54 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -72,6 +72,17 @@ public class Folks.IndividualAggregator : Object
   public HashTable<string, Individual> individuals { get; private set; }
 
   /**
+   * The { link Individual} representing the user.
+   *
+   * If it exists, this holds the { link Individual} who is the user â?? the
+   * { link Individual} containing the { link Persona}s who are the owners of
+   * the accounts for their respective backends.
+   *
+   * @since 0.3.0
+   */
+  public Individual user { get; private set; }
+
+  /**
    * Emitted when one or more { link Individual}s are added to or removed from
    * the aggregator.
    *
@@ -251,6 +262,16 @@ public class Folks.IndividualAggregator : Object
 
           debug ("Aggregating persona '%s' on '%s'.", persona.uid, persona.iid);
 
+          /* If the Persona is the user, we *always* want to link it to the
+           * existing this.user. */
+          if (persona.is_user == true && this.user != null)
+            {
+              debug ("    Found candidate individual '%s' as user.",
+                  this.user.id);
+              candidate_inds.prepend (this.user);
+              candidate_ind_set.add (this.user);
+            }
+
           /* If we don't trust the PersonaStore at all, we can't link the
            * Persona to any existing Individual */
           if (trust_level != PersonaStoreTrust.NONE)
@@ -397,6 +418,13 @@ public class Folks.IndividualAggregator : Object
               ((Individual) i).replace (final_individual);
             });
 
+          /* If the final Individual is the user, set them as such. */
+          if (final_individual.is_user == true)
+            {
+              assert (this.user == null);
+              this.user = final_individual;
+            }
+
           /* Add the new Individual to the aggregator */
           final_individual.removed.connect (this.individual_removed_cb);
           added_individuals.prepend (final_individual);
@@ -497,6 +525,9 @@ public class Folks.IndividualAggregator : Object
                 relinked_personas.prepend (p);
             }
 
+          if (this.user == individual)
+            this.user = null;
+
           this.individuals.remove (individual.id);
           individual.personas = null;
         }
@@ -543,6 +574,9 @@ public class Folks.IndividualAggregator : Object
       if (this.individuals.lookup (i.id) == null)
         return;
 
+      if (this.user == i)
+        this.user = null;
+
       var i_list = new GLib.List<Individual> ();
       i_list.append (i);
 



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