soc.2009.telepathy: a06152bb: Handle avatar changes via AvatarUpdated ...
sttwister at soc.pidgin.im
sttwister at soc.pidgin.im
Sun Jun 14 07:06:13 EDT 2009
-----------------------------------------------------------------
Revision: a06152bb6b374adcad3d5098a59e7c2924f2f4fa
Ancestor: 4505807a2a42ecf8abafe24c4c064d9232157c8f
Author: sttwister at soc.pidgin.im
Date: 2009-06-14T10:59:41
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/a06152bb6b374adcad3d5098a59e7c2924f2f4fa
Modified files:
libpurple/protocols/telepathy/telepathy.c
ChangeLog:
Handle avatar changes via AvatarUpdated signal
-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c 953919ac26e33fd593bd664492e05ad093426852
+++ libpurple/protocols/telepathy/telepathy.c f0f2944931582e922d924d5ace55955488f3aa52
@@ -504,9 +504,17 @@ avatar_retrieved_cb (TpConnection *proxy
telepathy_connection *data = user_data;
PurpleBuddyIcon *icon;
telepathy_contact *contact_data = g_hash_table_lookup(data->contacts, (gpointer)arg_Contact);
- TpContact *contact = contact_data->contact;
+ TpContact *contact;
gpointer avatar;
+ if (contact_data == NULL)
+ {
+ purple_debug_warning("telepathy", "Updated avatar for handle %u which has no contact_data struct cached!\n", arg_Contact);
+ return;
+ }
+
+ contact = contact_data->contact;
+
if (contact == NULL)
{
purple_debug_warning("telepathy", "Retrieved avatar for handle %u which has no TpContact proxy cached!\n", arg_Contact);
@@ -521,6 +529,65 @@ static void
}
static void
+avatar_updated_cb (TpConnection *proxy,
+ guint arg_Contact,
+ const gchar *arg_New_Avatar_Token,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ telepathy_connection *data = user_data;
+ telepathy_contact *contact_data = g_hash_table_lookup(data->contacts, (gpointer)arg_Contact);
+ TpContact *contact;
+ PurpleBuddy *buddy;
+ PurpleBuddyIcon *icon;
+
+ purple_debug_warning("telepathy", "Avatar token updated for %u: (%s)\n", arg_Contact, arg_New_Avatar_Token);
+
+ if (contact_data == NULL)
+ {
+ purple_debug_warning("telepathy", "Updated avatar for handle %u which has no contact_data struct cached!\n", arg_Contact);
+ return;
+ }
+
+ contact = contact_data->contact;
+
+ if (contact == NULL)
+ {
+ purple_debug_warning("telepathy", "Updated avatar for handle %u which has no TpContact proxy chaced!\n", arg_Contact);
+ return;
+ }
+
+ buddy = purple_find_buddy(data->acct, tp_contact_get_identifier(contact));
+
+ if (buddy == NULL)
+ {
+ purple_debug_warning("telepathy", "AvatarUpdated: There's no buddy named %s\n", tp_contact_get_identifier(contact));
+ return;
+ }
+
+ icon = purple_buddy_get_icon(buddy);
+
+ if (g_strcmp0(purple_buddy_icon_get_checksum(icon), arg_New_Avatar_Token) != 0)
+ {
+ /* updated the buddy avatar */
+ GArray *avatar_handles;
+
+ purple_debug_info("telepathy", "Avatar for %u (%s) has changed! Calling RequestAvatars\n", arg_Contact, tp_contact_get_identifier(contact));
+
+ avatar_handles = g_array_new(FALSE, FALSE, sizeof(guint));
+
+ g_array_append_val(avatar_handles, arg_Contact);
+
+ tp_cli_connection_interface_avatars_call_request_avatars(data->connection, -1,
+ avatar_handles,
+ request_avatars_cb, data,
+ NULL, NULL);
+
+ g_array_free(avatar_handles, TRUE);
+ }
+}
+
+static void
handle_list_channel (TpChannel *channel,
telepathy_connection *data)
{
@@ -1095,6 +1162,17 @@ connection_ready_cb (TpConnection *conne
g_error_free(error);
}
+ tp_cli_connection_interface_avatars_connect_to_avatar_updated(connection,
+ avatar_updated_cb, data,
+ NULL, NULL,
+ &error);
+
+ if (error != NULL)
+ {
+ purple_debug_error("telepathy", "Error connecting to AvatarUpdated signal: %s\n", error->message);
+ g_error_free(error);
+ }
+
}
}
More information about the Commits
mailing list