Commit 46ca881a authored by Philip Withnall's avatar Philip Withnall
Browse files

telepathy: Make group changes truly asynchronous and report errors properly

Take advantage of GroupDetails.change_group() being async, and wait for the
underlying Telepathy operation to complete before returning from it. This
allows us to propagate errors properly, rather than just printing
them as warnings on the terminal.

This also includes changes to not notify of changes to Tpf.Persona.groups
until Telepathy has notified us of the change. This should prevent groups
changing in the UI if the underlying operation has actually failed.

Helps: https://bugzilla.gnome.org/show_bug.cgi?id=671662
parent 9a7015ca
......@@ -1055,30 +1055,6 @@ public class Tpf.PersonaStore : Folks.PersonaStore
this._emit_personas_changed (personas_added, personas_removed);
}
internal async void _change_group_membership (Folks.Persona persona,
string group, bool is_member) throws Folks.PropertyError
{
var tp_persona = (Tpf.Persona) persona;
try
{
if (is_member)
{
yield tp_persona.contact.add_to_group_async (group);
}
else
{
yield tp_persona.contact.remove_from_group_async (group);
}
}
catch (GLib.Error e)
{
/* Translators: the parameter is an error message. */
throw new PropertyError.UNKNOWN_ERROR (
_("Failed to change group membership: %s"), e.message);
}
}
/**
* Remove a {@link Persona} from the PersonaStore.
*
......
......@@ -416,15 +416,39 @@ public class Tpf.Persona : Folks.Persona,
* See {@link Folks.GroupDetails.change_group}.
*/
public async void change_group (string group, bool is_member)
throws Folks.PropertyError
throws GLib.Error
{
if (this._change_group (group, is_member))
if (this._groups.contains (group) != is_member)
{
Tpf.PersonaStore store = (Tpf.PersonaStore) this.store;
yield store._change_group_membership (this, group, is_member);
yield this._change_group_membership (group, is_member);
}
/* The change will be notified when we receive changes from the store. */
}
private async void _change_group_membership (string group,
bool is_member) throws Folks.PropertyError
{
try
{
if (is_member)
{
yield this.contact.add_to_group_async (group);
}
else
{
yield this.contact.remove_from_group_async (group);
}
}
catch (GLib.Error e)
{
/* Translators: the parameter is an error message. */
throw new PropertyError.UNKNOWN_ERROR (
_("Failed to change group membership: %s"), e.message);
}
}
/* Note: Only ever called as a result of signals from Telepathy. */
private bool _change_group (string group, bool is_member)
{
var changed = false;
......@@ -439,7 +463,10 @@ public class Tpf.Persona : Folks.Persona,
}
if (changed == true)
this.group_changed (group, is_member);
{
this.group_changed (group, is_member);
this.notify_property ("groups");
}
return changed;
}
......@@ -464,21 +491,19 @@ public class Tpf.Persona : Folks.Persona,
*/
public async void change_groups (Set<string> groups) throws PropertyError
{
Tpf.PersonaStore store = (Tpf.PersonaStore) this.store;
foreach (var group1 in groups)
{
if (this._groups.contains (group1) == false)
yield store._change_group_membership (this, group1, true);
yield this._change_group_membership (group1, true);
}
foreach (var group2 in this._groups)
{
if (groups.contains (group2) == false)
yield store._change_group_membership (this, group2, false);
yield this._change_group_membership (group2, false);
}
this.notify_property ("groups");
/* The change will be notified when we receive changes from the store. */
}
/* This has to be weak since, in general, we can't force any TpContacts to
......
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