Commit 197cda29 authored by Philip Withnall's avatar Philip Withnall
Browse files

telepathy: Make alias changes truly asynchronous and report errors properly

Take advantage of AliasDetails.change_alias() 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.alias
until Telepathy has notified us of the change. This should prevent aliases
changing in the UI if the underlying operation has actually failed.

Helps: https://bugzilla.gnome.org/show_bug.cgi?id=671662
parent 137a87c3
...@@ -212,26 +212,75 @@ set_contact_alias_cb (TpConnection *conn, ...@@ -212,26 +212,75 @@ set_contact_alias_cb (TpConnection *conn,
gpointer user_data, gpointer user_data,
GObject *weak_object) GObject *weak_object)
{ {
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
if (error != NULL) if (error != NULL)
{ {
/* Translators: the parameter is an error message. */ g_simple_async_result_set_from_error (simple, error);
g_message (_("Failed to change contact's alias: %s"), error->message);
return;
} }
g_simple_async_result_complete (simple);
} }
/**
* folks_tp_lowlevel_connection_set_contact_alias_async:
* @conn: the connection to use
* @handle: handle of the contact whose alias is to be changed
* @alias: new human-readable alias for the contact
* @callback: function to call on completion
* @user_data: user data to pass to @callback
*
* Change the alias of the contact identified by @handle to @alias.
*/
void void
folks_tp_lowlevel_connection_set_contact_alias ( folks_tp_lowlevel_connection_set_contact_alias_async (
TpConnection *conn, TpConnection *conn,
guint handle, guint handle,
const gchar *alias) const gchar *alias,
GAsyncReadyCallback callback,
gpointer user_data)
{ {
GHashTable *ht = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, GSimpleAsyncResult *result;
g_free); GHashTable *ht;
ht = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
g_hash_table_insert (ht, GUINT_TO_POINTER (handle), g_strdup (alias)); g_hash_table_insert (ht, GUINT_TO_POINTER (handle), g_strdup (alias));
result = g_simple_async_result_new (G_OBJECT (conn), callback, user_data,
folks_tp_lowlevel_connection_set_contact_alias_finish);
tp_cli_connection_interface_aliasing_call_set_aliases (conn, -1, tp_cli_connection_interface_aliasing_call_set_aliases (conn, -1,
ht, set_contact_alias_cb, NULL, NULL, NULL); ht, set_contact_alias_cb, g_object_ref (result), g_object_unref,
G_OBJECT (conn));
g_object_unref (result);
g_hash_table_destroy (ht); g_hash_table_destroy (ht);
} }
/**
* folks_tp_lowlevel_connection_set_contact_alias_finish:
* @result: a #GAsyncResult
* @error: return location for a #GError, or %NULL
*
* Finish an asynchronous call to
* folks_tp_lowlevel_connection-set_contact_alias_async().
*/
void
folks_tp_lowlevel_connection_set_contact_alias_finish (
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
TpConnection *conn;
g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
conn = TP_CONNECTION (g_async_result_get_source_object (result));
g_return_if_fail (TP_IS_CONNECTION (conn));
g_return_if_fail (g_simple_async_result_is_valid (result,
G_OBJECT (conn),
folks_tp_lowlevel_connection_set_contact_alias_finish));
g_simple_async_result_propagate_error (simple, error);
}
...@@ -29,10 +29,17 @@ ...@@ -29,10 +29,17 @@
G_BEGIN_DECLS G_BEGIN_DECLS
void void
folks_tp_lowlevel_connection_set_contact_alias ( folks_tp_lowlevel_connection_set_contact_alias_async (
TpConnection *conn, TpConnection *conn,
guint handle, guint handle,
const gchar *alias); const gchar *alias,
GAsyncReadyCallback callback,
gpointer user_data);
void
folks_tp_lowlevel_connection_set_contact_alias_finish (
GAsyncResult *result,
GError **error);
void void
folks_tp_lowlevel_connection_get_alias_flags_async ( folks_tp_lowlevel_connection_get_alias_flags_async (
......
...@@ -1225,6 +1225,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore ...@@ -1225,6 +1225,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
} }
internal async void change_alias (Tpf.Persona persona, string alias) internal async void change_alias (Tpf.Persona persona, string alias)
throws PropertyError
{ {
/* Deal with badly-behaved callers */ /* Deal with badly-behaved callers */
if (alias == null) if (alias == null)
...@@ -1239,12 +1240,20 @@ public class Tpf.PersonaStore : Folks.PersonaStore ...@@ -1239,12 +1240,20 @@ public class Tpf.PersonaStore : Folks.PersonaStore
return; return;
} }
try
{
debug ("Changing alias of persona %s to '%s'.", debug ("Changing alias of persona %s to '%s'.",
persona.contact.get_identifier (), alias); persona.contact.get_identifier (), alias);
yield FolksTpLowlevel.connection_set_contact_alias_async (this._conn,
FolksTpLowlevel.connection_set_contact_alias (this._conn,
(Handle) persona.contact.handle, alias); (Handle) persona.contact.handle, alias);
} }
catch (GLib.Error e1)
{
throw new PropertyError.UNKNOWN_ERROR (
/* Translators: the parameter is an error message. */
_("Failed to change contact's alias: %s"), e1.message);
}
}
internal async void change_user_birthday (Tpf.Persona persona, internal async void change_user_birthday (Tpf.Persona persona,
DateTime? birthday) throws PersonaStoreError DateTime? birthday) throws PersonaStoreError
......
...@@ -303,8 +303,7 @@ public class Tpf.Persona : Folks.Persona, ...@@ -303,8 +303,7 @@ public class Tpf.Persona : Folks.Persona,
yield ((Tpf.PersonaStore) this.store).change_alias (this, alias); yield ((Tpf.PersonaStore) this.store).change_alias (this, alias);
} }
this._alias = alias; /* The change will be notified when we receive changes from the store. */
this.notify_property ("alias");
} }
private bool _is_favourite = false; private bool _is_favourite = false;
......
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