diff libpurple/protocols/msn/dialog.c @ 19843:60bc06498746

Committing khc's msnp14 changes from Trac Ticket #148. --rlaager committer: Richard Laager <rlaager@wiktel.com>
author Ka-Hing Cheung <khc@hxbc.us>
date Sun, 15 Apr 2007 04:12:27 +0000
parents 32c366eeeb99
children 6f986caeab59
line wrap: on
line diff
--- a/libpurple/protocols/msn/dialog.c	Sun Apr 15 00:32:57 2007 +0000
+++ b/libpurple/protocols/msn/dialog.c	Sun Apr 15 04:12:27 2007 +0000
@@ -34,40 +34,20 @@
 
 } MsnAddRemData;
 
-/* Remove the buddy referenced by the MsnAddRemData before the serverside list is changed.
- * If the buddy will be added, he'll be added back; if he will be removed, he won't be. */
-static void
-msn_complete_sync_issue(MsnAddRemData *data)
-{
-	PurpleBuddy *buddy;
-	PurpleGroup *group = NULL;
-
-	if (data->group != NULL)
-		group = purple_find_group(data->group);
-	
-	if (group != NULL)
-		buddy = purple_find_buddy_in_group(purple_connection_get_account(data->gc), data->who, group);
-	else
-		buddy = purple_find_buddy(purple_connection_get_account(data->gc), data->who);
-	
-	if (buddy != NULL)
-		purple_blist_remove_buddy(buddy);
-}
-
 static void
 msn_add_cb(MsnAddRemData *data)
 {
-	MsnSession *session;
-	MsnUserList *userlist;
-
-	msn_complete_sync_issue(data);
+	if (g_list_find(purple_connections_get_all(), data->gc) != NULL)
+	{
+		MsnSession *session = data->gc->proto_data;
+		MsnUserList *userlist = session->userlist;
 
-	session = data->gc->proto_data;
-	userlist = session->userlist;
+		msn_userlist_add_buddy(userlist, data->who, MSN_LIST_FL, data->group);
+	}
 
-	msn_userlist_add_buddy(userlist, data->who, MSN_LIST_FL, data->group);
+	if (data->group != NULL)
+		g_free(data->group);
 
-	g_free(data->group);
 	g_free(data->who);
 	g_free(data);
 }
@@ -75,17 +55,17 @@
 static void
 msn_rem_cb(MsnAddRemData *data)
 {
-	MsnSession *session;
-	MsnUserList *userlist;
-
-	msn_complete_sync_issue(data);
+	if (g_list_find(purple_connections_get_all(), data->gc) != NULL)
+	{
+		MsnSession *session = data->gc->proto_data;
+		MsnUserList *userlist = session->userlist;
 
-	session = data->gc->proto_data;
-	userlist = session->userlist;
+		msn_userlist_rem_buddy(userlist, data->who, MSN_LIST_FL, data->group);
+	}
 
-	msn_userlist_rem_buddy(userlist, data->who, MSN_LIST_FL, data->group);
+	if (data->group != NULL)
+		g_free(data->group);
 
-	g_free(data->group);
 	g_free(data->who);
 	g_free(data);
 }
@@ -98,6 +78,8 @@
 	PurpleAccount *account;
 	MsnAddRemData *data;
 	char *msg, *reason;
+	PurpleBuddy *buddy;
+	PurpleGroup *group = NULL;
 
 	account = session->account;
 	gc = purple_account_get_connection(account);
@@ -111,16 +93,13 @@
 						  purple_account_get_username(account),
 						  purple_account_get_protocol_name(account));
 
-	if (group_name != NULL)
-	{
+	if (group_name != NULL){
 		reason = g_strdup_printf(_("%s on the local list is "
 								   "inside the group \"%s\" but not on "
 								   "the server list. "
 								   "Do you want this buddy to be added?"),
 								 passport, group_name);
-	}
-	else
-	{
+	}else{
 		reason = g_strdup_printf(_("%s is on the local list but "
 								   "not on the server list. "
 								   "Do you want this buddy to be added?"),
@@ -132,6 +111,18 @@
 						_("Yes"), G_CALLBACK(msn_add_cb),
 						_("No"), G_CALLBACK(msn_rem_cb));
 
+	if (group_name != NULL)
+		group = purple_find_group(group_name);
+
+	if (group != NULL){
+		buddy = purple_find_buddy_in_group(account, passport, group);
+	}else{
+		buddy = purple_find_buddy(account, passport);
+	}
+
+	if (buddy != NULL)
+		purple_blist_remove_buddy(buddy);
+
 	g_free(reason);
 	g_free(msg);
 }