Commit 834cb05e authored by Philip Withnall's avatar Philip Withnall
Browse files

telepathy: Correctly advertise the writeability of alias and group properties

Previously, Tpf.Personas were always advertising aliases and groups as
being writeable properties, when they're actually not writeable for
Facebook XMPP connections.

Aliases were previously not writeable in the Telepathy fake CM (so the test
was previously in error), but they’re now writeable, so everything’s fine.

Closes: https://bugzilla.gnome.org/show_bug.cgi?id=671662
parent 74bb1d2d
......@@ -3,6 +3,7 @@ Overview of changes from libfolks 0.6.9 to libfolks 0.7.0
Bugs fixed:
• Bug 658576 — Need API to get a FolksIndividual from his ID
• Bug 671662 — Renamed alias of Facebook contact is not saved
API changes:
• Add IndividualAggregator.look_up_individual()
......
......@@ -40,10 +40,7 @@ extern const string BACKEND_NAME;
*/
public class Tpf.PersonaStore : Folks.PersonaStore
{
private const string[] _always_writeable_properties =
{
"is-favourite"
};
private string[] _always_writeable_properties = { "is-favourite" };
/* Sets of Personas exposed by this store.
* This is the roster + self_contact */
......@@ -692,6 +689,9 @@ public class Tpf.PersonaStore : Folks.PersonaStore
if (this._conn.get_group_storage () != ContactMetadataStorageType.NONE)
{
this._can_group_personas = MaybeBool.TRUE;
this._always_writeable_properties += "groups";
this.notify_property ("always-writeable-properties");
}
else
{
......@@ -711,40 +711,45 @@ public class Tpf.PersonaStore : Folks.PersonaStore
}
this.notify_property ("can-add-personas");
this.notify_property ("can-remove-personas");
this.thaw_notify ();
/* Add the local user */
this._conn.notify["self-contact"].connect (this._self_contact_changed_cb);
this._self_contact_changed_cb (this._conn, null);
/* FIXME: TpConnection still does not have high-level API for this.
* See fd.o#14540 */
FolksTpLowlevel.connection_get_alias_flags_async.begin (this._conn, (s2, res) =>
/* We have to do this before emitting the self persona so that code which
* checks the self persona's writeable fields gets correct values. */
var new_can_alias = MaybeBool.FALSE;
try
{
var new_can_alias = MaybeBool.FALSE;
try
{
var flags =
FolksTpLowlevel.connection_get_alias_flags_async.end (res);
if ((flags &
ConnectionAliasFlags.CONNECTION_ALIAS_FLAG_USER_SET) > 0)
{
new_can_alias = MaybeBool.TRUE;
}
}
catch (GLib.Error e)
var flags = yield FolksTpLowlevel.connection_get_alias_flags_async (
this._conn);
if ((flags &
ConnectionAliasFlags.CONNECTION_ALIAS_FLAG_USER_SET) > 0)
{
GLib.warning (
/* Translators: the first parameter is the display name for
* the Telepathy account, and the second is an error
* message. */
_("Failed to determine whether we can set aliases on Telepathy account '%s': %s"),
this.display_name, e.message);
new_can_alias = MaybeBool.TRUE;
this._always_writeable_properties += "alias";
this.notify_property ("always-writeable-properties");
}
}
catch (GLib.Error e)
{
GLib.warning (
/* Translators: the first parameter is the display name for
* the Telepathy account, and the second is an error
* message. */
_("Failed to determine whether we can set aliases on Telepathy account '%s': %s"),
this.display_name, e.message);
}
this._can_alias_personas = new_can_alias;
this.notify_property ("can-alias-personas");
});
this._can_alias_personas = new_can_alias;
this.notify_property ("can-alias-personas");
this.thaw_notify ();
/* Add the local user */
this._conn.notify["self-contact"].connect (this._self_contact_changed_cb);
this._self_contact_changed_cb (this._conn, null);
this._conn.notify["contact-list-state"].connect (this._contact_list_state_changed_cb);
this._contact_list_state_changed_cb (this._conn, null);
......@@ -838,6 +843,9 @@ public class Tpf.PersonaStore : Folks.PersonaStore
this._can_alias_personas = MaybeBool.FALSE;
this._can_group_personas = MaybeBool.FALSE;
this._can_remove_personas = MaybeBool.FALSE;
this._always_writeable_properties = { "is-favourite" };
this.notify_property ("always-writeable-properties");
}
/**
......
......@@ -41,12 +41,6 @@ public class Tpf.Persona : Folks.Persona,
UrlDetails
{
private const string[] _linkable_properties = { "im-addresses" };
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
......@@ -263,13 +257,7 @@ public class Tpf.Persona : Folks.Persona,
*/
public override string[] writeable_properties
{
get
{
if (this.is_user)
return this._writeable_properties;
return this._always_writeable_properties;
}
get { return this._writeable_properties; }
}
private string _alias = ""; /* must never be null */
......@@ -761,15 +749,22 @@ public class Tpf.Persona : Folks.Persona,
});
this._contact_groups_changed (this.contact.get_contact_groups (), {});
var tpf_store = this.store as Tpf.PersonaStore;
if (this.is_user)
{
((Tpf.PersonaStore) this.store).notify["supported-fields"].connect (
(s, p) =>
{
this._store_notify_supported_fields ();
});
this._store_notify_supported_fields ();
tpf_store.notify["supported-fields"].connect ((s, p) =>
{
this._update_writeable_properties ();
});
}
tpf_store.notify["always-writeable-properties"].connect ((s, p) =>
{
this._update_writeable_properties ();
});
this._update_writeable_properties ();
}
/* Called after all construction-time properties have been set. */
......@@ -778,21 +773,24 @@ public class Tpf.Persona : Folks.Persona,
this._is_constructed = true;
}
private void _store_notify_supported_fields ()
private void _update_writeable_properties ()
{
var tpf_store = this.store as Tpf.PersonaStore;
this._writeable_properties = this._always_writeable_properties;
if ("bday" in tpf_store.supported_fields)
this._writeable_properties += "birthday";
if ("email" in tpf_store.supported_fields)
this._writeable_properties += "email-addresses";
if ("fn" in tpf_store.supported_fields)
this._writeable_properties += "full-name";
if ("tel" in tpf_store.supported_fields)
this._writeable_properties += "phone-numbers";
if ("url" in tpf_store.supported_fields)
this._writeable_properties += "urls";
this._writeable_properties = this.store.always_writeable_properties;
if (this.is_user)
{
if ("bday" in tpf_store.supported_fields)
this._writeable_properties += "birthday";
if ("email" in tpf_store.supported_fields)
this._writeable_properties += "email-addresses";
if ("fn" in tpf_store.supported_fields)
this._writeable_properties += "full-name";
if ("tel" in tpf_store.supported_fields)
this._writeable_properties += "phone-numbers";
if ("url" in tpf_store.supported_fields)
this._writeable_properties += "urls";
}
}
private void _contact_notify_contact_info ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment