soc.2009.telepathy: 53d475c7: Only request avatar if it has really cha...

sttwister at soc.pidgin.im sttwister at soc.pidgin.im
Thu Jun 25 18:15:44 EDT 2009


-----------------------------------------------------------------
Revision: 53d475c7fea63c48aaf6f411e45df6a1f7b60f80
Ancestor: eb94b9c86c2d90a79a4083bf6685def4f54cd247
Author: sttwister at soc.pidgin.im
Date: 2009-06-25T22:05:05
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/53d475c7fea63c48aaf6f411e45df6a1f7b60f80

Modified files:
        libpurple/protocols/telepathy/telepathy_avatar.c
        libpurple/protocols/telepathy/telepathy_contact.c

ChangeLog: 

Only request avatar if it has really changed

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy_avatar.c	c1b0faf8ee52fa1cc73740f7397a048c2aa52829
+++ libpurple/protocols/telepathy/telepathy_avatar.c	f3119de41d699e0ddb8878ed4df74d0b0d3eb055
@@ -46,23 +46,73 @@ get_known_avatar_tokens_cb (TpConnection
                             gpointer user_data,
                             GObject *weak_object)
 {
+	telepathy_connection *data = user_data;
+	GHashTableIter iter;
+	guint handle;
+	gchar *token;
+
 	if (error != NULL)
 	{
 		purple_debug_error("telepathy", "GetAvatarTokens error: %s\n", error->message);
+		return;
 	}
-	else
+
+	g_hash_table_iter_init(&iter, out_Tokens);
+
+	/* got throught all known tokens */
+	while (g_hash_table_iter_next(&iter, (gpointer)&handle, (gpointer)&token))
 	{
-		GHashTableIter iter;
-		guint key;
-		gpointer value;
+		telepathy_contact *contact_data = g_hash_table_lookup(
+				data->contacts, (gpointer)handle);
 
-		g_hash_table_iter_init(&iter, out_Tokens);
+		purple_debug_info("telepathy", "Known token: %u -> (%s)\n", handle, (gchar *)token);	
 
-		while (g_hash_table_iter_next(&iter, (gpointer)&key, &value))
+		/* make sure there's enough information available about the contact */
+		if (contact_data && contact_data->contact)
 		{
-			purple_debug_info("telepathy", "Known token: %u -> (%s)\n", key, (gchar *)value);	
+			TpContact *contact = contact_data->contact;
+
+			PurpleBuddy* buddy = purple_find_buddy(data->acct,
+					tp_contact_get_identifier(contact));
+
+			PurpleBuddyIcon *icon;
+
+			/* clear the avatar in case of an empty token */
+			if (*token == 0)
+			{
+				purple_buddy_icons_set_for_user(data->acct,
+			    			tp_contact_get_identifier(contact),
+						NULL, 0, "");
+				continue;
+			}
+
+			icon = purple_buddy_get_icon(buddy);
+
+			/* is the cached avatar the same with this one? */
+			if (g_strcmp0(purple_buddy_icon_get_checksum(icon), token) != 0)
+			{
+				/* request a new avatar */
+				GArray *avatar_handles;
+
+				avatar_handles = g_array_new(FALSE, FALSE, sizeof(guint));
+
+				g_array_append_val(avatar_handles, handle);
+
+				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);
+			}
+
 		}
 	}
+
+
+
+	
 }
 
 void
============================================================
--- libpurple/protocols/telepathy/telepathy_contact.c	f775f56da55200410c0bf68b29706b414a799991
+++ libpurple/protocols/telepathy/telepathy_contact.c	4ecf3928a47e1b53930f4c1777710c8337e82370
@@ -135,7 +135,6 @@ handle_contacts (telepathy_connection *c
 		 PurpleGroup *group)
 {
 	int i;
-	GArray *avatar_handles = g_array_new(FALSE, FALSE, sizeof(guint));
 
 	purple_debug_info("telepathy", "Contacts ready: %u (%u failed)\n", n_contacts, n_failed);
 
@@ -203,20 +202,7 @@ handle_contacts (telepathy_connection *c
 			g_signal_connect(contact, "notify", G_CALLBACK (contact_notify_cb), connection_data);
 			contact_notify_cb (contact, NULL, connection_data);
 		}
-
-		if (!contact_data->requested_avatar)
-		{
-			g_array_append_val(avatar_handles, handle);
-			contact_data->requested_avatar = TRUE;
-		}
 	}
-
-	tp_cli_connection_interface_avatars_call_request_avatars(connection_data->connection, -1,
-			avatar_handles,
-			request_avatars_cb, connection_data,
-			NULL, NULL);
-
-	g_array_free(avatar_handles, TRUE);
 }
 
 /* this the ContactsReady callback for group channels */


More information about the Commits mailing list