cpw.darkrain42.buddy-add: 68318089: The Add Buddy dialog should not blindly ...

paul at darkrain42.org paul at darkrain42.org
Sat Jan 17 17:57:19 EST 2009


-----------------------------------------------------------------
Revision: 6831808999a270f8c1a128c7430a73d3dc0bfae2
Ancestor: 11ea1799b1892059650fa7dcf6e848a020045e50
Author: paul at darkrain42.org
Date: 2008-11-29T18:46:49
Branch: im.pidgin.cpw.darkrain42.buddy-add
URL: http://d.pidgin.im/viewmtn/revision/info/6831808999a270f8c1a128c7430a73d3dc0bfae2

Modified 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

ChangeLog: 

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)
   

-------------- next part --------------
============================================================
--- finch/gntblist.c	08ff46b3e194a312827fc8f098af34641f9377f8
+++ finch/gntblist.c	85ffc4dd04afbb5becb277217086630d157f121b
@@ -643,10 +643,14 @@ add_buddy_cb(void *data, PurpleRequestFi
 		purple_blist_add_group(grp, NULL);
 	}
 
-	/* XXX: Ask if there's already the same buddy in the same group (#4553) */
+	/* XXX: Ask to merge if there's already a buddy with the same alias in the same group (#4553) */
 
-	buddy = purple_buddy_new(account, username, alias);
-	purple_blist_add_buddy(buddy, NULL, grp, NULL);
+	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);
 }
 
============================================================
--- libpurple/protocols/irc/irc.c	0f7775728546224559660329274987e0a6b1aaf4
+++ libpurple/protocols/irc/irc.c	a3de7ac091439a95772a4b6ecf2b4a7e73ca747e
@@ -565,7 +565,7 @@ static void irc_add_buddy(PurpleConnecti
 	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
============================================================
--- libpurple/protocols/myspace/myspace.c	2c366e3edc4f6c56a00b1574ca991dbab42b7336
+++ libpurple/protocols/myspace/myspace.c	33b56e69becdeaef40aa75f8ec2b24eb952ea5b6
@@ -1984,7 +1984,7 @@ msim_incoming_status(MsimSession *sessio
 		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 @@ msim_add_buddy(PurpleConnection *gc, Pur
 	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 @@ msim_status_text(PurpleBuddy *buddy)
 
 	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 @@ msim_tooltip_text(PurpleBuddy *buddy, Pu
 	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 @@ msim_add_contact_from_server_cb(MsimSess
 	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);
============================================================
--- libpurple/protocols/myspace/user.c	7d4e32a3eea84ba8adaf25b7df39ecd355a5aa12
+++ libpurple/protocols/myspace/user.c	09da4646f55f89272c5d7f563b9dd871c802a77c
@@ -47,27 +47,26 @@ msim_format_now_playing(const gchar *ban
 		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;
-	} 
+	} else {
+		user = (MsimUser *)(buddy->proto_data);
+	}
 
-	user = (MsimUser *)(buddy->proto_data);
-
 	return user;
 }
 
@@ -83,7 +82,7 @@ msim_find_user(MsimSession *session, con
 		return NULL;
 	}
 
-	user = msim_get_user_from_buddy(buddy);
+	user = msim_get_user_from_buddy(buddy, TRUE);
 
 	return user;
 }
============================================================
--- libpurple/protocols/myspace/user.h	e630e48e95179f76d169f70dc8ceb53c8c8b7994
+++ libpurple/protocols/myspace/user.h	08909798738da475eceefd5f0f82207b39a6dbca
@@ -45,7 +45,7 @@ typedef void (*MSIM_USER_LOOKUP_CB)(Msim
  * 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);
============================================================
--- libpurple/protocols/novell/novell.c	da346110e69c3d85d19e4f619edb0fd47035d321
+++ libpurple/protocols/novell/novell.c	ef6fec546c3a85b7ee2f05ca15a8f370d40e1dab
@@ -2553,6 +2553,10 @@ novell_add_buddy(PurpleConnection * gc, 
 	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);
 
============================================================
--- pidgin/gtkblist.c	9705d34cddb465d11c8fbc646906741c4779628a
+++ pidgin/gtkblist.c	b3bcdc65b722535312aae88a3a68c1340c1db80a
@@ -6495,8 +6495,12 @@ add_buddy_cb(GtkWidget *w, int resp, Pid
 			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. */
============================================================
--- pidgin/plugins/gevolution/gevo-util.c	e3ed813920d7d205f9660ab312e7a3ed78254e9e
+++ pidgin/plugins/gevolution/gevo-util.c	79a2ccaeadc97fe0b2473e58cf392820f5c2ccef
@@ -41,8 +41,12 @@ gevo_add_buddy(PurpleAccount *account, c
 		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)


More information about the Commits mailing list