changeset 25426:2d92bbe6807b

Use a JabberStream variable instead of a setting for the initial hash The hash is only used at login to compare with the PEP avatar(s) and vCard and is recalculated at each login, so there's no need to store it as a setting. The variable is eitehr NULL or the hash now, instead of "" or the hash.
author Paul Aurich <paul@darkrain42.org>
date Sat, 14 Feb 2009 18:23:13 +0000
parents 0fa91206cf5a
children 7e020fbe2cdb
files libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/protocols/jabber/useravatar.c
diffstat 4 files changed, 21 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Sat Feb 14 03:57:22 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Sat Feb 14 18:23:13 2009 +0000
@@ -496,11 +496,17 @@
 
 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
 {
+	PurpleAccount *account = purple_connection_get_account(gc);
 	jabber_avatar_set(gc->proto_data, img, NULL);
 	/* vCard avatars do not have an image type requirement so update our
 	 * vCard avatar regardless of image type for those poor older clients
 	 */
-	jabber_set_info(gc, purple_account_get_user_info(gc->account));
+	jabber_set_info(gc, purple_account_get_user_info(account));
+
+	/* TODO: Fake image to ourselves, since a number of servers do not echo
+	 * back our presence to us. To do this without uselessly copying the data
+	 * of the image, we need purple_buddy_icons_set_for_user_image (i.e. takes
+	 * an existing icon/stored image). */
 }
 
 /*
@@ -1044,7 +1050,6 @@
 {
 	xmlnode *vcard, *photo, *binval;
 	char *txt, *vcard_hash = NULL;
-	const char *current_hash;
 
 	if((vcard = xmlnode_get_child(packet, "vCard")) ||
 			(vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp")))
@@ -1072,17 +1077,14 @@
 		}
 	}
 
-	current_hash = purple_account_get_string(js->gc->account,
-	                                         "prpl-jabber_icon_checksum", "");
-
 	/* Republish our vcard if the photo is different than the server's */
-	if ((!vcard_hash && current_hash[0] != '\0') ||
-		 (vcard_hash && strcmp(vcard_hash, current_hash))) {
+	if ((!vcard_hash && js->initial_avatar_hash) ||
+		 (vcard_hash && (!js->initial_avatar_hash || strcmp(vcard_hash, js->initial_avatar_hash)))) {
 		PurpleAccount *account = purple_connection_get_account(js->gc);
 		jabber_set_info(js->gc, purple_account_get_user_info(account));
-	} else if (current_hash != '\0') {
+	} else if (js->initial_avatar_hash) {
 		/* Our photo is in the vcard, so advertise vcard-temp updates */
-		js->avatar_hash = g_strdup(current_hash);
+		js->avatar_hash = g_strdup(js->initial_avatar_hash);
 	}
 
 	g_free(vcard_hash);
--- a/libpurple/protocols/jabber/jabber.c	Sat Feb 14 03:57:22 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Feb 14 18:23:13 2009 +0000
@@ -739,16 +739,15 @@
 		return;
 	}
 
-	/* This account setting is used to determine if we should re-sync our avatar to the
-	 * server at login. */
+	/*
+	 * Calculate the avatar hash for our current image so we know (when we
+	 * fetch our vCard and PEP avatar) if we should send our avatar to the
+	 * server.
+	 */
 	if ((image = purple_buddy_icons_find_account_icon(account))) {
-		char *checksum = jabber_calculate_data_sha1sum(purple_imgstore_get_data(image),
+		js->initial_avatar_hash = jabber_calculate_data_sha1sum(purple_imgstore_get_data(image),
 					purple_imgstore_get_size(image));
-		purple_account_set_string(account, "prpl-jabber_icon_checksum", checksum);
-		g_free(checksum);
 		purple_imgstore_unref(image);
-	} else {
-		purple_account_set_string(account, "prpl-jabber_icon_checksum", "");
 	}
 
 	if((my_jb = jabber_buddy_find(js, purple_account_get_username(account), TRUE)))
@@ -1382,6 +1381,7 @@
 	g_free(js->stream_id);
 	if(js->user)
 		jabber_id_free(js->user);
+	g_free(js->initial_avatar_hash);
 	g_free(js->avatar_hash);
 
 	purple_circ_buffer_destroy(js->write_buffer);
--- a/libpurple/protocols/jabber/jabber.h	Sat Feb 14 03:57:22 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Sat Feb 14 18:23:13 2009 +0000
@@ -161,6 +161,7 @@
 
 	gboolean registration;
 
+	char *initial_avatar_hash;
 	char *avatar_hash;
 	GSList *pending_avatar_requests;
 
--- a/libpurple/protocols/jabber/useravatar.c	Sat Feb 14 03:57:22 2009 +0000
+++ b/libpurple/protocols/jabber/useravatar.c	Sat Feb 14 18:23:13 2009 +0000
@@ -226,7 +226,6 @@
 {
 	xmlnode *item = NULL, *metadata = NULL, *info = NULL;
 	PurpleAccount *account = purple_connection_get_account(js->gc);
-	const char *current_hash = purple_account_get_string(account, "prpl-jabber_icon_checksum", "");
 	const char *server_hash = NULL;
 	const char *ns;
 
@@ -244,8 +243,8 @@
 		return;
 
 	/* Publish ours if it's different than the server's */
-	if ((!server_hash && current_hash[0] != '\0') ||
-		 (server_hash && strcmp(server_hash, current_hash))) {
+	if ((!server_hash && js->initial_avatar_hash) ||
+		 (server_hash && (!js->initial_avatar_hash || strcmp(server_hash, js->initial_avatar_hash)))) {
 		PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account);
 		jabber_avatar_set(js, img, ns);
 		purple_imgstore_unref(img);