changeset 25172:125cac3e24ee

The Add Buddy dialog should not blindly create a duplicate buddy in a group Fix up a subset of the prpls add_buddy functions to properly handle this situation. * Everything that comes before oscar alphabetically should work properly (except Gadu-Gadu and MSN, which need testing/another set of eyes)
author Paul Aurich <paul@darkrain42.org>
date Sat, 29 Nov 2008 18:46:49 +0000
parents 5cd0188892f6
children 401f548e3544
files finch/gntblist.c libpurple/protocols/irc/irc.c libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/user.c libpurple/protocols/myspace/user.h libpurple/protocols/novell/novell.c pidgin/gtkblist.c pidgin/plugins/gevolution/gevo-util.c
diffstat 8 files changed, 43 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntblist.c	Sat Nov 29 18:20:58 2008 +0000
+++ b/finch/gntblist.c	Sat Nov 29 18:46:49 2008 +0000
@@ -643,10 +643,14 @@
 		purple_blist_add_group(grp, NULL);
 	}
 
-	/* XXX: Ask if there's already the same buddy in the same group (#4553) */
-
-	buddy = purple_buddy_new(account, username, alias);
-	purple_blist_add_buddy(buddy, NULL, grp, NULL);
+	/* XXX: Ask to merge if there's already a buddy with the same alias in the same group (#4553) */
+
+	if ((buddy = purple_find_buddy_in_group(account, username, grp)) == NULL)
+	{
+		buddy = purple_buddy_new(account, username, alias);
+		purple_blist_add_buddy(buddy, NULL, grp, NULL);
+	}
+
 	purple_account_add_buddy(account, buddy);
 }
 
--- a/libpurple/protocols/irc/irc.c	Sat Nov 29 18:20:58 2008 +0000
+++ b/libpurple/protocols/irc/irc.c	Sat Nov 29 18:46:49 2008 +0000
@@ -565,7 +565,7 @@
 	struct irc_conn *irc = (struct irc_conn *)gc->proto_data;
 	struct irc_buddy *ib = g_new0(struct irc_buddy, 1);
 	ib->name = g_strdup(buddy->name);
-	g_hash_table_insert(irc->buddies, ib->name, ib);
+	g_hash_table_replace(irc->buddies, ib->name, ib);
 
 	/* if the timer isn't set, this is during signon, so we don't want to flood
 	 * ourself off with ISON's, so we don't, but after that we want to know when
--- a/libpurple/protocols/myspace/myspace.c	Sat Nov 29 18:20:58 2008 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sat Nov 29 18:46:49 2008 +0000
@@ -1984,7 +1984,7 @@
 		buddy = purple_buddy_new(session->account, username, NULL);
 		purple_blist_add_buddy(buddy, NULL, NULL, NULL);
 
-		user = msim_get_user_from_buddy(buddy);
+		user = msim_get_user_from_buddy(buddy, TRUE);
 
 		/* 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"));
@@ -2082,6 +2082,10 @@
 	MsimMessage *body;
 
 	session = (MsimSession *)gc->proto_data;
+
+	if (msim_get_user_from_buddy(buddy, FALSE) != NULL)
+		return;
+
 	purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", 
 			buddy->name, (group && group->name) ? group->name : "(no group)");
 
@@ -2750,7 +2754,7 @@
 
 	g_return_val_if_fail(buddy != NULL, NULL);
 
-	user = msim_get_user_from_buddy(buddy);
+	user = msim_get_user_from_buddy(buddy, TRUE);
 
 	session = (MsimSession *)buddy->account->gc->proto_data;
 	g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL);
@@ -2796,7 +2800,7 @@
 	g_return_if_fail(buddy != NULL);
 	g_return_if_fail(user_info != NULL);
 
-	user = msim_get_user_from_buddy(buddy);
+	user = msim_get_user_from_buddy(buddy, TRUE);
 
 	if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
 		MsimSession *session;
@@ -2879,7 +2883,7 @@
 	purple_blist_add_buddy(buddy, NULL, group, NULL /* insertion point */);
 
 	/* 3. Update buddy information */
-	user = msim_get_user_from_buddy(buddy);
+	user = msim_get_user_from_buddy(buddy, TRUE);
 
 	/* All buddies on list should have 'uid' integer associated with them. */
 	purple_blist_node_set_int(&buddy->node, "UserID", uid);
--- a/libpurple/protocols/myspace/user.c	Sat Nov 29 18:20:58 2008 +0000
+++ b/libpurple/protocols/myspace/user.c	Sat Nov 29 18:46:49 2008 +0000
@@ -47,26 +47,25 @@
 		return NULL;
 	}
 }
-/** Get the MsimUser from a PurpleBuddy, creating it if needed. */
+
+/** Get the MsimUser from a PurpleBuddy, optionally creating it if needed. */
 MsimUser *
-msim_get_user_from_buddy(PurpleBuddy *buddy)
+msim_get_user_from_buddy(PurpleBuddy *buddy, gboolean create)
 {
 	MsimUser *user;
 
-	if (!buddy) {
-		return NULL;
-	}
+	g_return_val_if_fail(buddy != NULL, NULL);
 
-	if (!buddy->proto_data) {
+	if (create && !buddy->proto_data) {
 		/* No MsimUser for this buddy; make one. */
 
 		/* TODO: where is this freed? */
 		user = g_new0(MsimUser, 1);
 		user->buddy = buddy;
 		buddy->proto_data = (gpointer)user;
-	} 
-
-	user = (MsimUser *)(buddy->proto_data);
+	} else {
+		user = (MsimUser *)(buddy->proto_data);
+	}
 
 	return user;
 }
@@ -83,7 +82,7 @@
 		return NULL;
 	}
 
-	user = msim_get_user_from_buddy(buddy);
+	user = msim_get_user_from_buddy(buddy, TRUE);
 
 	return user;
 }
--- a/libpurple/protocols/myspace/user.h	Sat Nov 29 18:20:58 2008 +0000
+++ b/libpurple/protocols/myspace/user.h	Sat Nov 29 18:46:49 2008 +0000
@@ -45,7 +45,7 @@
  * initiated from a user lookup. */
 typedef void (*MSIM_USER_LOOKUP_CB)(MsimSession *session, MsimMessage *userinfo, gpointer data);
 
-MsimUser *msim_get_user_from_buddy(PurpleBuddy *buddy);
+MsimUser *msim_get_user_from_buddy(PurpleBuddy *buddy, gboolean create);
 MsimUser *msim_find_user(MsimSession *session, const gchar *username);
 void msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full);
 gboolean msim_store_user_info(MsimSession *session, MsimMessage *msg, MsimUser *user);
--- a/libpurple/protocols/novell/novell.c	Sat Nov 29 18:20:58 2008 +0000
+++ b/libpurple/protocols/novell/novell.c	Sat Nov 29 18:46:49 2008 +0000
@@ -2553,6 +2553,10 @@
 	if (!user->clist_synched)
 		return;
 
+	/* Don't re-add a buddy that is already on our contact list */
+	if (nm_find_user_record(user, buddy->name) == NULL)
+		return;
+
 	contact = nm_create_contact();
 	nm_contact_set_dn(contact, buddy->name);
 
--- a/pidgin/gtkblist.c	Sat Nov 29 18:20:58 2008 +0000
+++ b/pidgin/gtkblist.c	Sat Nov 29 18:46:49 2008 +0000
@@ -6495,8 +6495,12 @@
 			purple_blist_add_group(g, NULL);
 		}
 
-		b = purple_buddy_new(data->account, who, whoalias);
-		purple_blist_add_buddy(b, NULL, g, NULL);
+		if ((b = purple_find_buddy_in_group(data->account, who, g)) == NULL)
+		{
+			b = purple_buddy_new(data->account, who, whoalias);
+			purple_blist_add_buddy(b, NULL, g, NULL);
+		}
+
 		purple_account_add_buddy(data->account, b);
 
 		/* Offer to merge people with the same alias. */
--- a/pidgin/plugins/gevolution/gevo-util.c	Sat Nov 29 18:20:58 2008 +0000
+++ b/pidgin/plugins/gevolution/gevo-util.c	Sat Nov 29 18:46:49 2008 +0000
@@ -41,8 +41,12 @@
 		purple_blist_add_group(group, NULL);
 	}
 
-	buddy = purple_buddy_new(account, screenname, alias);
-	purple_blist_add_buddy(buddy, NULL, group, NULL);
+	if ((buddy = purple_find_buddy_in_group(account, screenname, group)) == NULL)
+	{
+		buddy = purple_buddy_new(account, screenname, alias);
+		purple_blist_add_buddy(buddy, NULL, group, NULL);
+	}
+
 	purple_account_add_buddy(account, buddy);
 
 	if (conv != NULL)