[folks] Add an "is-user" property to Individual and Persona



commit a124e5c7cfffd3896e51f708d52eb0a16f795d7a
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Mon Aug 23 16:11:08 2010 +0100

    Add an "is-user" property to Individual and Persona
    
    This is true iff the Individual or Persona is the owner of the relevant
    accounts. Helps: bgo#627402

 NEWS                  |    2 ++
 folks/individual.vala |   41 +++++++++++++++++++++++++++++++++++++++++
 folks/persona.vala    |   10 ++++++++++
 3 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 6ba87dd..a65a99f 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ API changes:
 * Removed BackendStore constructor
 * Added BackendStore.dup()
 * Added BackendStore::enabled-backends
+* Added Individual::is-user
+* Added Persona::is-user
 
 Bugs fixed:
 * Bug 629452 â?? [Patch] Add missing gio linking for import-tool
diff --git a/folks/individual.vala b/folks/individual.vala
index 3f5b22d..d35696b 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -84,6 +84,9 @@ public class Folks.Individual : Object,
    * in this Individual. There shouldn't be any entries with a number < 1.
    * This is used for working out when to disconnect from store signals. */
   private HashMap<PersonaStore, uint> stores;
+  /* The number of Personas in this Individual which have
+   * Persona.is_user == true. Iff this is > 0, Individual.is_user == true. */
+  private uint persona_user_count = 0;
 
   /**
    * The trust level of the Individual.
@@ -114,6 +117,31 @@ public class Folks.Individual : Object,
   public string presence_message { get; private set; }
 
   /**
+   * Whether the Individual is the user.
+   *
+   * Iff the Individual represents the user â?? the person who owns the account in
+   * the backend for each { link Persona} in the Individual â?? this is `true`.
+   *
+   * It is //not// guaranteed that every { link Persona} in the Individual has
+   * its { link Persona.is_user} set to the same value as the Individual. For
+   * example, the user could own two Telepathy accounts, and have added the
+   * other account as a contact in each account. The accounts will expose a
+   * { link Persona} for the user (which will have { link Persona.is_user} set
+   * to `true`) //and// a { link Persona} for the contact for the other account
+   * (which will have { link Persona.is_user} set to `false`).
+   *
+   * It is guaranteed that iff this property is set to `true` on an Individual,
+   * there will be at least one { link Persona} in the Individual with its
+   * { link Persona.is_user} set to `true`.
+   *
+   * It is guaranteed that there will only ever be one Individual with this
+   * property set to `true`.
+   *
+   * @since 0.3.0
+   */
+  public bool is_user { get; private set; }
+
+  /**
    * A unique identifier for the Individual.
    *
    * This uniquely identifies the Individual, and persists across
@@ -756,6 +784,10 @@ public class Folks.Individual : Object,
         {
           if (!this._persona_set.contains (p))
             {
+              /* Keep track of how many Personas are users */
+              if (p.is_user)
+                this.persona_user_count++;
+
               added.prepend (p);
 
               this._persona_set.add (p);
@@ -786,6 +818,10 @@ public class Folks.Individual : Object,
         {
           if (!persona_set.contains (p))
             {
+              /* Keep track of how many Personas are users */
+              if (p.is_user)
+                this.persona_user_count--;
+
               removed.prepend (p);
 
               /* Decrement the Persona count for this PersonaStore */
@@ -816,6 +852,11 @@ public class Folks.Individual : Object,
 
       this.personas_changed (added, removed);
 
+      /* Update this.is_user */
+      bool new_is_user = (this.persona_user_count > 0) ? true : false;
+      if (new_is_user != this.is_user)
+        this.is_user = new_is_user;
+
       /* If all the Personas have been removed, remove the Individual */
       if (this._persona_set.size < 1)
         {
diff --git a/folks/persona.vala b/folks/persona.vala
index 60038cc..281f257 100644
--- a/folks/persona.vala
+++ b/folks/persona.vala
@@ -83,6 +83,16 @@ public abstract class Folks.Persona : Object
   public string display_id { get; construct; }
 
   /**
+   * Whether the Persona is the user.
+   *
+   * Iff the Persona represents the user â?? the person who owns the account in
+   * the respective backend â?? this is `true`.
+   *
+   * @since 0.3.0
+   */
+  public bool is_user { get; construct; }
+
+  /**
    * The { link PersonaStore} which contains this Persona.
    */
   public weak PersonaStore store { get; construct; }



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