telepathy: Only allow is-favourite to be writeable if the logger initialised
authorPhilip Withnall <philip@tecnocode.co.uk>
Mon, 16 Apr 2012 17:11:31 +0000 (18:11 +0100)
committerPhilip Withnall <philip@tecnocode.co.uk>
Tue, 17 Apr 2012 10:59:14 +0000 (11:59 +0100)
This prevents setting favourites falling into a black hole.

backends/telepathy/lib/tpf-persona-store.vala
tests/telepathy/individual-properties.vala

index 80880f0..ded6a73 100644 (file)
@@ -40,7 +40,7 @@ extern const string BACKEND_NAME;
  */
 public class Tpf.PersonaStore : Folks.PersonaStore
 {
-  private string[] _always_writeable_properties = { "is-favourite" };
+  private string[] _always_writeable_properties = {};
 
   /* Sets of Personas exposed by this store.
    * This is the roster + self_contact */
@@ -490,6 +490,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
                     {
                       warning ("Failed to initialise favourite contacts: %s",
                           e.message);
+                      this._logger = null;
                     }
                 });
 
@@ -552,6 +553,9 @@ public class Tpf.PersonaStore : Folks.PersonaStore
 
       var contacts = yield this._logger.get_favourite_contacts ();
       this._favourite_contacts_changed_cb (contacts, {});
+
+      this._always_writeable_properties += "is-favourite";
+      this.notify_property ("always-writeable-properties");
     }
 
   private Persona? _lookup_persona_by_id (string id)
@@ -844,7 +848,15 @@ public class Tpf.PersonaStore : Folks.PersonaStore
       this._can_group_personas = MaybeBool.FALSE;
       this._can_remove_personas = MaybeBool.FALSE;
 
-      this._always_writeable_properties = { "is-favourite" };
+      if (this._logger != null)
+        {
+          this._always_writeable_properties = { "is-favourite" };
+        }
+      else
+        {
+          this._always_writeable_properties = {};
+        }
+
       this.notify_property ("always-writeable-properties");
     }
 
index 12cd3ad..09fabb3 100644 (file)
@@ -104,7 +104,9 @@ public class IndividualPropertiesTests : Folks.TestCase
                     }
                   assert (tpf_persona != null);
                   assert ("alias" in tpf_persona.writeable_properties);
-                  assert ("is-favourite" in tpf_persona.writeable_properties);
+                  /* The logger isn't run in the test suite. */
+                  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);
@@ -149,7 +151,9 @@ public class IndividualPropertiesTests : Folks.TestCase
                     }
                   assert (tpf_persona != null);
                   assert ("alias" in tpf_persona.writeable_properties);
-                  assert ("is-favourite" in tpf_persona.writeable_properties);
+                  /* The logger isn't run in the test suite. */
+                  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);