[folks] Bug 640901 — Allow to determine whether a Tpf.Persona's in the contact list



commit 05cca833976054240e62b4d0df00954059440580
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Fri Dec 17 18:36:45 2010 +0000

    Bug 640901 â?? Allow to determine whether a Tpf.Persona's in the contact list
    
    Add Tpf.Persona.is-in-contact-list, which is true iff the persona's in the
    user's contact list. Closes: bgo#640901

 NEWS                                          |    3 +
 backends/telepathy/lib/tpf-persona-store.vala |   66 +++++++++++++++++++++----
 backends/telepathy/lib/tpf-persona.vala       |   12 +++++
 3 files changed, 71 insertions(+), 10 deletions(-)
---
diff --git a/NEWS b/NEWS
index dfc4995..28863d9 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ API changes:
 * IMable.im_addresses is now a mapping of string to LinkedHashSet.
 * Rename the HasAvatar interface to AvatarOwner
 * Rename the HasPresence interface to PresenceOwner
+* Add Tpf.Persona.is_in_contact_list
 
 Bugs fixed:
 * Bug 637240 â?? libfolks-telepathy.so exports private symbols
@@ -25,6 +26,8 @@ Bugs fixed:
 * Bug 639742 â?? Logger service unavailable in make check
 * Bug 640213 â?? Add tests for LinkedHashSet
 * Bug 627397 â?? Use better interface names
+* Bug 640901 â?? Allow it to be determined whether a user Tpf.Persona is in the
+  contact list
 
 Overview of changes from libfolks 0.3.2 to libfolks 0.3.3
 =========================================================
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index 0a95cd5..8fcda26 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -606,9 +606,11 @@ public class Tpf.PersonaStore : Folks.PersonaStore
                   return;
                 }
 
+              debug ("Creating persona from self-handle");
+
               /* Add the local user */
               Contact contact = contacts[0];
-              Persona persona = this._add_persona_from_contact (contact);
+              Persona persona = this._add_persona_from_contact (contact, false);
 
               GLib.List<Persona> personas = new GLib.List<Persona> ();
               personas.prepend (persona);
@@ -972,7 +974,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
     {
       var tp_persona = (Tpf.Persona) persona;
 
-      if (tp_persona.contact == this._self_contact)
+      if (tp_persona.contact == this._self_contact &&
+          tp_persona.is_in_contact_list == false)
         {
           throw new PersonaStoreError.UNSUPPORTED_ON_USER (
               _("Personas representing the local user may not be removed."));
@@ -1209,9 +1212,24 @@ public class Tpf.PersonaStore : Folks.PersonaStore
         {
           var channel_handle = (Handle) channel_handles.index (i);
           var contact_handle = channel.group_get_handle_owner (channel_handle);
+          Persona? persona = this._handle_persona_map[contact_handle];
 
-          if (this._handle_persona_map[contact_handle] == null)
-            contact_handles += contact_handle;
+          if (persona == null)
+            {
+              contact_handles += contact_handle;
+            }
+          else
+            {
+              /* Mark the persona as having been seen in the contact list.
+               * The persona might have originally been discovered by querying
+               * the Telepathy connection's self-handle; in this case, its
+               * is-in-contact-list property will originally be false, as a
+               * contact could be exposed as the self-handle, but not actually
+               * be in the user's contact list. */
+              debug ("Setting is-in-contact-list for '%s' to true",
+                  persona.uid);
+              persona.is_in_contact_list = true;
+            }
         }
 
       try
@@ -1266,7 +1284,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
 
               debug ("Creating persona from contact '%s'", contact.identifier);
 
-              var persona = this._add_persona_from_contact (contact);
+              var persona = this._add_persona_from_contact (contact, true);
               if (persona != null)
                 personas.prepend (persona);
             }
@@ -1292,15 +1310,18 @@ public class Tpf.PersonaStore : Folks.PersonaStore
       return null;
     }
 
-  private Tpf.Persona? _add_persona_from_contact (Contact contact)
+  private Tpf.Persona? _add_persona_from_contact (Contact contact,
+      bool from_contact_list)
     {
       var h = contact.get_handle ();
+      Persona? persona = null;
 
       debug ("Adding persona from contact '%s'", contact.identifier);
 
-      if (this._handle_persona_map[h] == null)
+      persona = this._handle_persona_map[h];
+      if (persona == null)
         {
-          var persona = new Tpf.Persona (contact, this);
+          persona = new Tpf.Persona (contact, this);
 
           this._personas.insert (persona.iid, persona);
           this._handle_persona_map[h] = persona;
@@ -1311,10 +1332,35 @@ public class Tpf.PersonaStore : Folks.PersonaStore
            * favourite. */
           persona.is_favourite = this._favourite_handles.contains (h);
 
+          /* Only emit this debug message in the false case to reduce debug
+           * spam (see https://bugzilla.gnome.org/show_bug.cgi?id=640901#c2). */
+          if (from_contact_list == false)
+            {
+              debug ("    Setting is-in-contact-list to false");
+            }
+
+          persona.is_in_contact_list = from_contact_list;
+
           return persona;
         }
+      else
+        {
+           debug ("    ...already exists.");
+
+          /* Mark the persona as having been seen in the contact list.
+           * The persona might have originally been discovered by querying
+           * the Telepathy connection's self-handle; in this case, its
+           * is-in-contact-list property will originally be false, as a
+           * contact could be exposed as the self-handle, but not actually
+           * be in the user's contact list. */
+          if (persona.is_in_contact_list == false && from_contact_list == true)
+            {
+              debug ("    Setting is-in-contact-list to true");
+              persona.is_in_contact_list = true;
+            }
 
-      return null;
+          return null;
+        }
     }
 
   private void _add_new_personas_from_contacts (Contact[] contacts)
@@ -1322,7 +1368,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
       GLib.List<Persona> personas = new GLib.List<Persona> ();
       foreach (Contact contact in contacts)
         {
-          var persona = this._add_persona_from_contact (contact);
+          var persona = this._add_persona_from_contact (contact, true);
           if (persona != null)
             personas.prepend (persona);
         }
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 4666842..6b8151d 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -48,6 +48,18 @@ public class Tpf.Persona : Folks.Persona,
   private bool _is_constructed = false;
 
   /**
+   * Whether the Persona is in the user's contact list.
+   *
+   * This will be true for most { link Folks.Persona}s, but may not be true for
+   * personas where { link Folks.Persona.is_user} is true. If it's false in
+   * this case, it means that the persona has been retrieved from the Telepathy
+   * connection, but has not been added to the user's contact list.
+   *
+   * @since 0.3.UNRELEASED
+   */
+  public bool is_in_contact_list { get; set; }
+
+  /**
    * An avatar for the Persona.
    *
    * See { link Folks.AvatarOwner.avatar}.



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