changeset 12176:6f41d8d33989

[gaim-migrate @ 14478] Iterating over all buddies for a presence when a presence is common to all those buddies is dumb, not to mention buggy. I introduced this (these?) bug back in January and told ChipX86 I'd revert it "soon" in March. 8 months is soon, right? This fixes the online counts being wrong when you have a buddy in multiple groups. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Mon, 21 Nov 2005 01:56:13 +0000
parents a655bdeb561d
children 6ecd4f75cc9d
files src/prpl.c
diffstat 1 files changed, 45 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/prpl.c	Mon Nov 21 00:43:20 2005 +0000
+++ b/src/prpl.c	Mon Nov 21 01:56:13 2005 +0000
@@ -188,52 +188,40 @@
 gaim_prpl_got_user_idle(GaimAccount *account, const char *name,
 		gboolean idle, time_t idle_time)
 {
-	GSList *list, *iter;
+	GaimBuddy *buddy;
+	GaimPresence *presence;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(name    != NULL);
 	g_return_if_fail(gaim_account_is_connected(account));
 
-	list = gaim_find_buddies(account, name);
-	for (iter = list; iter != NULL; iter = iter->next)
-	{
-		GaimBuddy *buddy;
-		GaimPresence *presence;
+	if ((buddy = gaim_find_buddy(account, name)) == NULL)
+		return;
 
-		buddy = (GaimBuddy *)iter->data;
-
-		presence = gaim_buddy_get_presence(buddy);
+	presence = gaim_buddy_get_presence(buddy);
 
-		gaim_presence_set_idle(presence, idle, idle_time);
-	}
-	g_slist_free(list);
+	gaim_presence_set_idle(presence, idle, idle_time);
 }
 
 void
 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name,
 		time_t login_time)
 {
-	GSList *list, *iter;
+	GaimBuddy *buddy;
+	GaimPresence *presence;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(name    != NULL);
 
-	list = gaim_find_buddies(account, name);
-	for (iter = list; iter != NULL; iter = iter->next)
-	{
-		GaimBuddy *buddy;
-		GaimPresence *presence;
-
-		buddy = (GaimBuddy *)iter->data;
+	if ((buddy = gaim_find_buddy(account, name)) == NULL)
+		return;
 
-		if (login_time == 0)
-			login_time = time(NULL);
+	if (login_time == 0)
+		login_time = time(NULL);
 
-		presence = gaim_buddy_get_presence(buddy);
+	presence = gaim_buddy_get_presence(buddy);
 
-		gaim_presence_set_login_time(presence, login_time);
-	}
-	g_slist_free(list);
+	gaim_presence_set_login_time(presence, login_time);
 }
 
 void
@@ -241,44 +229,47 @@
 		const char *status_id, const char *attr_id, ...)
 {
 	GSList *list, *iter;
+	GaimBuddy *buddy;
+	GaimPresence *presence;
+	GaimStatus *status;
+	GaimStatus *old_status;
 
 	g_return_if_fail(account   != NULL);
 	g_return_if_fail(name      != NULL);
 	g_return_if_fail(status_id != NULL);
 	g_return_if_fail(gaim_account_is_connected(account));
 
+	if ((buddy = gaim_find_buddy(account, name)) == NULL)
+		return;
+
+	presence = gaim_buddy_get_presence(buddy);
+	status   = gaim_presence_get_status(presence, status_id);
+
+	g_return_if_fail(status != NULL);
+
+	if (attr_id != NULL)
+	{
+		va_list args;
+
+		va_start(args, attr_id);
+
+		while (attr_id != NULL)
+		{
+			set_value_from_arg(status, attr_id, &args);
+
+			attr_id = va_arg(args, char *);
+		}
+
+		va_end(args);
+	}
+
+	old_status = gaim_presence_get_active_status(presence);
+	gaim_presence_set_status_active(presence, status_id, TRUE);
+
 	list = gaim_find_buddies(account, name);
 	for (iter = list; iter != NULL; iter = iter->next)
 	{
-		GaimBuddy *buddy;
-		GaimPresence *presence;
-		GaimStatus *status;
-		GaimStatus *old_status;
-
 		buddy = (GaimBuddy *)iter->data;
-		presence = gaim_buddy_get_presence(buddy);
-		status   = gaim_presence_get_status(presence, status_id);
-
-		g_return_if_fail(status != NULL);
-
-		if (attr_id != NULL)
-		{
-			va_list args;
-
-			va_start(args, attr_id);
-
-			while (attr_id != NULL)
-			{
-				set_value_from_arg(status, attr_id, &args);
-
-				attr_id = va_arg(args, char *);
-			}
-
-			va_end(args);
-		}
-
-		old_status = gaim_presence_get_active_status(presence);
-		gaim_presence_set_status_active(presence, status_id, TRUE);
 		gaim_blist_update_buddy_status(buddy, old_status);
 	}
 	g_slist_free(list);