[folks] Factor in server-side writeability of ContactInfo fields.



commit ec64e78109a90f32703401aa14388a58b25620ca
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Thu Oct 6 11:37:59 2011 -0700

    Factor in server-side writeability of ContactInfo fields.

 backends/telepathy/lib/tpf-persona.vala    |   44 ++++++++++++++++++++++++++-
 tests/telepathy/individual-properties.vala |   40 ++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 3 deletions(-)
---
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 1eb299c..3f2511b 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -44,12 +44,13 @@ public class Tpf.Persona : Folks.Persona,
   private string _full_name; /* must never be null */
   private HashMultiMap<string, ImFieldDetails> _im_addresses;
   private const string[] _linkable_properties = { "im-addresses" };
-  private const string[] _writeable_properties =
+  private const string[] _always_writeable_properties =
     {
       "alias",
       "is-favourite",
       "groups"
     };
+  private string[] _writeable_properties = null;
 
   /* Whether we've finished being constructed; this is used to prevent
    * unnecessary trips to the Telepathy service to tell it about properties
@@ -197,7 +198,46 @@ public class Tpf.Persona : Folks.Persona,
    */
   public override string[] writeable_properties
     {
-      get { return this._writeable_properties; }
+      get
+        {
+          if (this.is_user)
+            {
+              var connection =
+                ((Tpf.PersonaStore) this.store).account.connection;
+              if (connection != null)
+                {
+                  var ci_flags = connection.get_contact_info_flags ();
+                  if ((ci_flags & ContactInfoFlags.CAN_SET) != 0)
+                    {
+                      var field_specs =
+                        connection.get_contact_info_supported_fields ();
+                      var supported_fields = new HashSet<string> ();
+                      foreach (var field_spec in field_specs)
+                        {
+                          /* XXX: we ignore the maximum count for each type of
+                           * field since the common-sense count for each
+                           * corresponding field (eg, full-name max = 1) in
+                           * Folks is already reflected in our API and we have
+                           * no other way to express it; but this seems a very
+                           * minor problem */
+                          supported_fields.add (field_spec.name);
+                        }
+
+                      this._writeable_properties =
+                        this._always_writeable_properties;
+
+                      if ("fn" in supported_fields)
+                        this._writeable_properties += "full-name";
+                      if ("tel" in supported_fields)
+                        this._writeable_properties += "phone-numbers";
+
+                      return this._writeable_properties;
+                    }
+                }
+            }
+
+          return this._always_writeable_properties;
+        }
     }
 
   /**
diff --git a/tests/telepathy/individual-properties.vala b/tests/telepathy/individual-properties.vala
index a06a25f..f0bae52 100644
--- a/tests/telepathy/individual-properties.vala
+++ b/tests/telepathy/individual-properties.vala
@@ -79,9 +79,47 @@ public class IndividualPropertiesTests : Folks.TestCase
             {
               assert (i != null);
 
+              /* Check the user Individual */
+              if (i.is_user)
+                {
+                  /* Check properties */
+                  assert (i.alias == "me example com");
+                  assert (i.presence_message == "");
+                  assert (i.presence_status == "available");
+                  assert (i.presence_type == PresenceType.AVAILABLE);
+                  assert (((PresenceDetails) i).is_online () == true);
+
+                  /* Check groups */
+                  assert (i.groups.size == 0);
+
+                  /* Check writeability of fields */
+                  Tpf.Persona tpf_persona = null;
+                  foreach (var p in i.personas)
+                    {
+                      if (p is Tpf.Persona)
+                        {
+                          tpf_persona = p as Tpf.Persona;
+                          break;
+                        }
+                    }
+                  assert (tpf_persona != null);
+                  assert ("alias" in tpf_persona.writeable_properties);
+                  assert ("is-favourite" in tpf_persona.writeable_properties);
+                  assert ("groups" in tpf_persona.writeable_properties);
+                  /* These are only writeable for the user contact */
+                  assert (tpf_persona.is_user);
+                  assert (("full-name" in tpf_persona.writeable_properties));
+                  assert (
+                      ("phone-numbers" in tpf_persona.writeable_properties));
+
+                  /* Check ContactInfo-provided properties */
+                  assert (i.full_name == "");
+                  assert (i.phone_numbers.size == 0);
+                }
+
               /* Check the Individual containing just
                * Tpf.Persona(olivier example com) */
-              if (i.id == "0e46c5e74f61908f49550d241f2a1651892a1695")
+              else if (i.id == "0e46c5e74f61908f49550d241f2a1651892a1695")
                 {
                   /* Check properties */
                   assert (i.alias == "Olivier");



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