Commit dcf663dd authored by Philip Withnall's avatar Philip Withnall
Browse files

eds: Tie favourite status to “Starred in Android” group for Google Contacts

Link is-favourite to whether a “Starred in Android” group exists on a contact
(and vice-versa) if the contact is from a Google Contacts address book.

Closes: https://bugzilla.gnome.org/show_bug.cgi?id=661490
parent 01c0fd63
......@@ -7,6 +7,8 @@ Bugs fixed:
* Bug 672381 — invalid uninstantiatable type `<invalid>' in cast to
`FolksIndividual'
* Bug 670347 — Check for null birthday strings
* Bug 661490 — Should mark contacts from the "Starred in Android" group as
Favorites
Overview of changes from libfolks 0.6.6 to libfolks 0.6.7
=============================================================
......
......@@ -48,6 +48,12 @@ public class Edsf.PersonaStore : Folks.PersonaStore
* haven't received a property change notification for it. */
private const uint _property_change_timeout = 30; /* seconds */
/* Translators: This should be translated to the name of the “Starred in
* Android” group in Google Contacts for your language. If Google have not
* localised the group for your language, or Google Contacts isn't available
* in your language, please *do not* translate this string. */
internal const string android_favourite_group_name = N_("Starred in Android");
/**
* The type of persona store this is.
*
......@@ -1442,6 +1448,23 @@ public class Edsf.PersonaStore : Folks.PersonaStore
yield this._set_contact_is_favourite (persona.contact, is_favourite);
yield this._commit_modified_property (persona, "is-favourite");
/* If this is a Google Contacts address book, change the user's membership
* of the “Starred in Android” group accordingly. See: bgo#661490. */
if (this._is_google_contacts_address_book ())
{
try
{
yield persona.change_group (this.android_favourite_group_name,
is_favourite);
}
catch (GLib.Error e1)
{
/* We know this will always be a PropertyError. */
assert (e1 is PropertyError);
throw (PropertyError) e1;
}
}
}
private async void _set_contact_is_favourite (E.Contact contact,
......@@ -1923,6 +1946,15 @@ public class Edsf.PersonaStore : Folks.PersonaStore
yield this._set_contact_groups (persona.contact, groups);
yield this._commit_modified_property (persona, "groups");
/* If this is a Google Contacts address book and the user's changing
* membership of the “Starred in Android” group, change our favourite
* status accordingly. See: bgo#661490. */
if (this._is_google_contacts_address_book ())
{
yield persona.change_is_favourite (
this.android_favourite_group_name in groups);
}
}
private async void _set_contact_groups (E.Contact contact, Set<string> groups)
......@@ -2136,6 +2168,24 @@ public class Edsf.PersonaStore : Folks.PersonaStore
error_in.message);
}
/* Try and work out whether this address book is Google Contacts. If so, we
* can enable things like setting favourite status based on Android groups. */
internal bool _is_google_contacts_address_book ()
{
unowned SourceGroup? group = (SourceGroup?) this.source.peek_group ();
if (group != null)
{
var base_uri = ((!) group).peek_base_uri ();
/* base_uri should be google:// for Google Contacts address books */
if (base_uri.has_prefix ("google:"))
{
return true;
}
}
return false;
}
private bool _is_in_source_list ()
{
/* Should only ever be called from a callback from the source list itself,
......
......@@ -1445,24 +1445,49 @@ public class Edsf.Persona : Folks.Persona,
}
}
var old_is_favourite = this._is_favourite;
var store = (Edsf.PersonaStore) this.store;
/* Make the changes to this._groups and emit signals. */
foreach (var category_name in removed_categories)
{
/* We link the “Starred in Android” group to Google Contacts address
* books. See: bgo#661490. */
if (store._is_google_contacts_address_book () &&
category_name == Edsf.PersonaStore.android_favourite_group_name)
{
this._is_favourite = false;
}
this.group_changed (category_name, false);
this._groups.remove (category_name);
}
foreach (var category_name in added_categories)
{
if (store._is_google_contacts_address_book () &&
category_name == Edsf.PersonaStore.android_favourite_group_name)
{
this._is_favourite = true;
}
this._groups.add (category_name);
this.group_changed (category_name, true);
}
/* Notify if anything's changed. */
this.freeze_notify ();
if (added_categories.size != 0 || removed_categories.size != 0)
{
this.notify_property ("groups");
}
if (this._is_favourite != old_is_favourite)
{
this.notify_property ("is-favourite");
}
this.thaw_notify ();
}
/**
......@@ -1656,10 +1681,39 @@ public class Edsf.Persona : Folks.Persona,
}
}
var store = (Edsf.PersonaStore) this.store;
if (store._is_google_contacts_address_book ())
{
is_fav = is_fav ||
(Edsf.PersonaStore.android_favourite_group_name in this._groups);
}
if (is_fav != this._is_favourite)
{
this._is_favourite = is_fav;
var groups_changed = false;
if (store._is_google_contacts_address_book () &&
!(Edsf.PersonaStore.android_favourite_group_name in this._groups))
{
this._groups.add (Edsf.PersonaStore.android_favourite_group_name);
this.group_changed (
Edsf.PersonaStore.android_favourite_group_name, true);
groups_changed = true;
}
this.freeze_notify ();
if (groups_changed == true)
{
this.notify_property ("groups");
}
this.notify_property ("is-favourite");
this.thaw_notify ();
}
}
......
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