changeset 5758:666b04f93c55

[gaim-migrate @ 6183] Now buddies who are in two groups on your list will have their statuses updated for both. gaim_find_buddy can be used in a loop to find all buddies with the specified name on an account. As such, gaim_find_buddy is somewhat slower, but considering that people tend to have far fewer groups than buddies the performance isn't hurt that much. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 05 Jun 2003 15:37:35 +0000
parents f5773332fbed
children 49afd939e443
files src/blist.c src/blist.h src/server.c
diffstat 3 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Thu Jun 05 10:22:02 2003 +0000
+++ b/src/blist.c	Thu Jun 05 15:37:35 2003 +0000
@@ -70,6 +70,7 @@
 struct _gaim_hbuddy {
 	char *name;
 	GaimAccount *account;
+	GaimBlistNode *group;
 };
 
 static guint _gaim_blist_hbuddy_hash (struct _gaim_hbuddy *hb)
@@ -79,7 +80,7 @@
 
 static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2)
 {
-	return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account);
+	return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group);
 }
 
 /*****************************************************************************
@@ -506,6 +507,7 @@
 	hb = g_malloc(sizeof(struct _gaim_hbuddy));
 	hb->name = g_strdup(normalize(buddy->name));
 	hb->account = buddy->account;
+	hb->group = ((GaimBlistNode*)buddy)->parent;
 
 	if (g_hash_table_lookup(gaimbuddylist->buddies, (gpointer)hb)) {
 		/* This guy already exists */
@@ -628,6 +630,7 @@
 
 	hb.name = normalize(buddy->name);
 	hb.account = buddy->account;
+	hb.group = ((GaimBlistNode*)buddy)->parent;
 	if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) {
 		g_hash_table_remove(gaimbuddylist->buddies, &hb);
 		g_free(key->name);
@@ -736,17 +739,33 @@
 
 struct buddy *gaim_find_buddy(GaimAccount *account, const char *name)
 {
-	struct buddy *buddy;
+	static struct buddy *buddy = NULL;
 	struct _gaim_hbuddy hb;
+	GaimBlistNode *group;
+	const char *n = NULL;
 
 	if (!gaimbuddylist)
 		return NULL;
+	
+	if (!name && !buddy);
 
-	hb.name = normalize(name);
-	hb.account = account;
-	buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb);
+	if (name) {
+		group = gaimbuddylist->root;
+		n = name;
+	} else {
+		group = ((GaimBlistNode*)buddy)->parent->next;
+		n = buddy->name;
+	}
 
-	return buddy;
+	while (group) {
+		hb.name = normalize(n);
+		hb.account = account;
+		hb.group = group;
+		if (buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb))
+			return buddy;
+		group = ((GaimBlistNode*)group)->next;
+	}
+	return NULL;
 }
 
 struct group *gaim_find_group(const char *name)
--- a/src/blist.h	Thu Jun 05 10:22:02 2003 +0000
+++ b/src/blist.h	Thu Jun 05 15:37:35 2003 +0000
@@ -384,7 +384,8 @@
 /**
  * Finds the buddy struct given a screenname and an account
  *
- * @param name    The buddy's screenname
+ * @param name    The buddy's screenname or NULL to search for more buddies with the same screenname
+ *                as the previous search
  * @param account The account this buddy belongs to
  * @return        The buddy or NULL if the buddy does not exist
  */
--- a/src/server.c	Thu Jun 05 10:22:02 2003 +0000
+++ b/src/server.c	Thu Jun 05 15:37:35 2003 +0000
@@ -1148,6 +1148,13 @@
 	
 	gaim_blist_update_buddy_presence(b, loggedin);
 
+	/* Now, update the rest of the buddies in the list */
+	while (b = gaim_find_buddy(gc->account, NULL)) {
+		gaim_blist_update_buddy_presence(b, loggedin);
+		gaim_blist_update_buddy_idle(b, idle);
+		gaim_blist_update_buddy_evil(b, evil);
+		gaim_blist_update_buddy_status(b, type);
+	}
 }