changeset 24701:93f0249b4ff4

merge of '2c63599660bb7ed2aa17389e548fbc0511b797ac' and 'ce75e981fb02f075fc398b19d6ad5d2805046d0c'
author Mark Doliner <mark@kingant.net>
date Fri, 12 Dec 2008 04:02:08 +0000
parents bf2ca2c5ac40 (current diff) 128a77f3b3c4 (diff)
children 19198eac578b
files
diffstat 3 files changed, 35 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Fri Dec 12 00:01:40 2008 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Fri Dec 12 04:02:08 2008 +0000
@@ -980,15 +980,8 @@
 
 	if (!user) {
 		/* User isn't on blist, create a temporary user to store info. */
-		/* TODO: is this legit, or is it somehow responsible for #3444? */
-		PurpleBuddy *buddy;
-
 		user = g_new0(MsimUser, 1);
 		user->temporary_user = TRUE;
-
-		buddy = purple_buddy_new(session->account, username, NULL);
-		user->buddy = buddy;
-		buddy->proto_data = (gpointer)user;
 	}
 
 	/* Update user structure with new information */
@@ -1005,7 +998,6 @@
 	purple_notify_user_info_destroy(user_info);
 
 	if (user->temporary_user) {
-		purple_blist_remove_buddy(user->buddy);
 		g_free(user->client_info);
 		g_free(user->gender);
 		g_free(user->location);
@@ -1026,7 +1018,6 @@
 {
 	MsimSession *session;
 	MsimUser *user;
-	guint uid;
 	gchar *user_to_lookup;
 	MsimMessage *user_msg;
 
@@ -1041,8 +1032,8 @@
 	user = msim_find_user(session, username);
 
 	/* If is on buddy list, lookup by uid since it is faster. */
-	if (user && (uid = purple_blist_node_get_int(&user->buddy->node, "UserID"))) {
-		user_to_lookup = g_strdup_printf("%d", uid);
+	if (user && user->id) {
+		user_to_lookup = g_strdup_printf("%d", user->id);
 	} else {
 		/* Looking up buddy not on blist. Lookup by whatever user entered. */
 		user_to_lookup = g_strdup(username);
@@ -1978,10 +1969,11 @@
 		purple_blist_add_buddy(buddy, NULL, NULL, NULL);
 
 		user = msim_get_user_from_buddy(buddy);
-
-		/* All buddies on list should have a UserID integer associated with them. */
-		purple_blist_node_set_int(&buddy->node, "UserID", msim_msg_get_integer(msg, "f"));
-		
+		user->id = msim_msg_get_integer(msg, "f");
+
+		/* Keep track of the user ID across sessions */
+		purple_blist_node_set_int(&buddy->node, "UserID", user->id);
+
 		msim_store_user_info(session, msg, NULL);
 	} else {
 		purple_debug_info("msim", "msim_status: found buddy %s\n", username);
@@ -2874,7 +2866,8 @@
 	/* 3. Update buddy information */
 	user = msim_get_user_from_buddy(buddy);
 
-	/* All buddies on list should have 'uid' integer associated with them. */
+	user->id = uid;
+	/* Keep track of the user ID across sessions */
 	purple_blist_node_set_int(&buddy->node, "UserID", uid);
 
 	/* Stores a few fields in the MsimUser, relevant to the buddy itself.
--- a/libpurple/protocols/myspace/user.c	Fri Dec 12 00:01:40 2008 +0000
+++ b/libpurple/protocols/myspace/user.c	Fri Dec 12 04:02:08 2008 +0000
@@ -63,6 +63,7 @@
 		/* TODO: where is this freed? */
 		user = g_new0(MsimUser, 1);
 		user->buddy = buddy;
+		user->id = purple_blist_node_get_int(&buddy->node, "UserID");
 		buddy->proto_data = (gpointer)user;
 	} 
 
@@ -96,7 +97,6 @@
 {
 	PurplePresence *presence;
 	gchar *str;
-	guint uid;
 	guint cv;
 
 	/* Useful to identify the account the tooltip refers to. 
@@ -105,8 +105,6 @@
 		purple_notify_user_info_add_pair(user_info, _("User"), user->username);
 	}
 
-	uid = purple_blist_node_get_int(&user->buddy->node, "UserID");
-
 	/* a/s/l...the vitals */
 	if (user->age) {
 		char age[16];
@@ -127,21 +125,23 @@
 		purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline);
 	}
 
-	presence = purple_buddy_get_presence(user->buddy);
+	if (user->buddy != NULL) {
+		presence = purple_buddy_get_presence(user->buddy);
+
+		if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
+			PurpleStatus *status;
+			const char *artist, *title;
 
-	if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
-		PurpleStatus *status;
-		const char *artist, *title;
-		
-		status = purple_presence_get_status(presence, "tune");
-		title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
-		artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
+			status = purple_presence_get_status(presence, "tune");
+			title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
+			artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
 
-		str = msim_format_now_playing(artist, title);
-		if (str && *str) {
-			purple_notify_user_info_add_pair(user_info, _("Song"), str);
+			str = msim_format_now_playing(artist, title);
+			if (str && *str) {
+				purple_notify_user_info_add_pair(user_info, _("Song"), str);
+			}
+			g_free(str);
 		}
-		g_free(str);
 	}
 
 	/* Note: total friends only available if looked up by uid, not username. */
@@ -170,12 +170,12 @@
 		g_free(client);
 	}
 
-	if (full && uid) {
+	if (full && user->id) {
 		/* TODO: link to username, if available */
 		char *profile;
 		purple_notify_user_info_add_section_break(user_info);
 		profile = g_strdup_printf("<a href=\"http://myspace.com/%d\">%s</a>",
-				uid, _("View web profile"));
+				user->id, _("View web profile"));
 		purple_notify_user_info_add_pair(user_info, NULL, profile);
 		g_free(profile);
 	}
@@ -199,12 +199,16 @@
 	PurplePresence *presence;
 	const char *prev_artist, *prev_title;
 
+	if (user->buddy == NULL)
+		/* User not on buddy list so nothing to do */
+		return;
+
 	prev_artist = NULL;
 	prev_title = NULL;
 
-	if (new_artist && !strlen(new_artist))
+	if (new_artist && !*new_artist)
 		new_artist = NULL;
-	if (new_title && !strlen(new_title))
+	if (new_title && !*new_title)
 		new_title = NULL;
 
 	if (!new_artist && !new_title) {
@@ -246,10 +250,11 @@
 {
 	if (g_str_equal(key_str, "UserID") || g_str_equal(key_str, "ContactID")) {
 		/* Save to buddy list, if it exists, for quick cached uid lookup with msim_uid2username_from_blist(). */
+		user->id = atol(value_str);
 		if (user->buddy)
 		{
 			purple_debug_info("msim", "associating uid %s with username %s\n", key_str, user->buddy->name);
-			purple_blist_node_set_int(&user->buddy->node, "UserID", atol(value_str));
+			purple_blist_node_set_int(&user->buddy->node, "UserID", user->id);
 		}
 		/* Need to store in MsimUser, too? What if not on blist? */
 	} else if (g_str_equal(key_str, "Age")) {
--- a/libpurple/protocols/myspace/user.h	Fri Dec 12 00:01:40 2008 +0000
+++ b/libpurple/protocols/myspace/user.h	Fri Dec 12 04:02:08 2008 +0000
@@ -25,6 +25,7 @@
 typedef struct _MsimUser
 {
 	PurpleBuddy *buddy;
+	int id;
 	guint client_cv;
 	gchar *client_info;
 	guint age;