diff libpurple/protocols/msn/switchboard.c @ 31171:930b267d33c0

Switchboard->users is now a list of MsnUsers which is a lot more useful and it is already allocated.
author masca@cpw.pidgin.im
date Tue, 25 May 2010 22:06:03 +0000
parents 7a26ff6c0044
children 1ba9f3167de0
line wrap: on
line diff
--- a/libpurple/protocols/msn/switchboard.c	Tue May 25 21:17:30 2010 +0000
+++ b/libpurple/protocols/msn/switchboard.c	Tue May 25 22:06:03 2010 +0000
@@ -25,6 +25,7 @@
 #include "prefs.h"
 #include "switchboard.h"
 #include "notification.h"
+#include "userlist.h"
 #include "msnutils.h"
 
 #include "error.h"
@@ -114,7 +115,6 @@
 	g_free(swboard->session_id);
 
 	for (; swboard->users; swboard->users = g_list_delete_link(swboard->users, swboard->users))
-		g_free(swboard->users->data);
 
 	session = swboard->session;
 	session->switches = g_list_remove(session->switches, swboard);
@@ -217,11 +217,23 @@
 	msn_message_destroy(msg);
 }
 
+static int
+user_passport_cmp(MsnUser *user, const char *passport)
+{
+	const char *pass;
+
+	pass = msn_user_get_passport(user);
+
+	return strcmp(pass, passport);
+}
+
 static void
 msn_switchboard_add_user(MsnSwitchBoard *swboard, const char *user)
 {
 	MsnCmdProc *cmdproc;
 	PurpleAccount *account;
+	MsnUserList *userlist;
+	MsnUser *msnuser;
 	char *semicolon;
 	char *passport;
 
@@ -237,8 +249,14 @@
 	else
 		passport = g_strdup(user);
 
+	userlist = swboard->session->userlist;
+	msnuser = msn_userlist_find_user(userlist, passport);
+
+	if (!msnuser)
+		purple_debug_error("msn","User %s is not on our list.\n", passport);
+
 	/* Don't add multiple endpoints to the conversation. */
-	if (g_list_find_custom(swboard->users, passport, (GCompareFunc)strcmp)) {
+	if (g_list_find_custom(swboard->users, passport, (GCompareFunc)user_passport_cmp)) {
 		g_free(passport);
 		return;
 	}
@@ -248,8 +266,10 @@
 		g_free(passport);
 		return;
 	}
+	
+	g_free(passport);
 
-	swboard->users = g_list_prepend(swboard->users, passport);
+	swboard->users = g_list_prepend(swboard->users, msnuser);
 	swboard->current_users++;
 	swboard->empty = FALSE;
 
@@ -267,7 +287,7 @@
 	if ((swboard->conv != NULL) &&
 		(purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
 	{
-		purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv), user, NULL,
+		purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv), msnuser->passport, NULL,
 								PURPLE_CBFLAGS_NONE, TRUE);
 		msn_servconn_set_idle_timeout(swboard->servconn, 0);
 	}
@@ -295,8 +315,9 @@
 			for (l = swboard->users; l != NULL; l = l->next)
 			{
 				const char *tmp_user;
+				user = l->data;
 
-				tmp_user = l->data;
+				tmp_user = msnuser->passport;
 
 				purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv),
 										tmp_user, NULL, PURPLE_CBFLAGS_NONE, TRUE);
@@ -313,7 +334,7 @@
 	else if (swboard->conv == NULL)
 	{
 		swboard->conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
-															user, account);
+															msnuser->passport, account);
 	}
 	else
 	{