changeset 16974:810af35c31ce

merge of 'b53a835bb1f153bec412cb4b7b18e9b93829c4d3' and 'ed1533f293d1bf84645df12026613141daf219d0'
author Richard Laager <rlaager@wiktel.com>
date Wed, 09 May 2007 02:57:46 +0000
parents cbe900af96a8 (current diff) abbbc8374c74 (diff)
children 9ded461750a9
files
diffstat 2 files changed, 35 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/prpl.c	Wed May 09 02:57:36 2007 +0000
+++ b/libpurple/prpl.c	Wed May 09 02:57:46 2007 +0000
@@ -128,7 +128,7 @@
 purple_prpl_got_user_status(PurpleAccount *account, const char *name,
 		const char *status_id, ...)
 {
-	GSList *list;
+	GSList *list, *l;
 	PurpleBuddy *buddy;
 	PurplePresence *presence;
 	PurpleStatus *status;
@@ -140,24 +140,30 @@
 	g_return_if_fail(status_id != NULL);
 	g_return_if_fail(purple_account_is_connected(account) || purple_account_is_connecting(account));
 
-	if ((buddy = purple_find_buddy(account, name)) == NULL)
+	if((list = purple_find_buddies(account, name)) == NULL)
 		return;
 
-	presence = purple_buddy_get_presence(buddy);
-	status   = purple_presence_get_status(presence, status_id);
+	for(l = list; l != NULL; l = l->next) {
+		buddy = l->data;
 
-	g_return_if_fail(status != NULL);
+		presence = purple_buddy_get_presence(buddy);
+		status   = purple_presence_get_status(presence, status_id);
 
-	old_status = purple_presence_get_active_status(presence);
+		if(NULL == status)
+			continue;
 
-	va_start(args, status_id);
-	purple_status_set_active_with_attrs(status, TRUE, args);
-	va_end(args);
+		old_status = purple_presence_get_active_status(presence);
 
-	list = purple_find_buddies(account, name);
-	g_slist_foreach(list, (GFunc)purple_blist_update_buddy_status, old_status);
+		va_start(args, status_id);
+		purple_status_set_active_with_attrs(status, TRUE, args);
+		va_end(args);
+
+		purple_blist_update_buddy_status(buddy, old_status);
+	}
+
 	g_slist_free(list);
 
+	/* we get to re-use the last status we found */
 	if (!purple_status_is_online(status))
 		serv_got_typing_stopped(purple_account_get_connection(account), name);
 }
@@ -165,6 +171,7 @@
 void purple_prpl_got_user_status_deactive(PurpleAccount *account, const char *name,
 					const char *status_id)
 {
+	GSList *list, *l;
 	PurpleBuddy *buddy;
 	PurplePresence *presence;
 	PurpleStatus *status;
@@ -174,14 +181,22 @@
 	g_return_if_fail(status_id != NULL);
 	g_return_if_fail(purple_account_is_connected(account) || purple_account_is_connecting(account));
 
-	if ((buddy = purple_find_buddy(account, name)) == NULL)
+	if((list = purple_find_buddies(account, name)) == NULL)
 		return;
 
-	presence = purple_buddy_get_presence(buddy);
-	status   = purple_presence_get_status(presence, status_id);
+	for(l = list; l != NULL; l = l->next) {
+		buddy = l->data;
+
+		presence = purple_buddy_get_presence(buddy);
+		status   = purple_presence_get_status(presence, status_id);
 
-	g_return_if_fail(status != NULL);
-	purple_status_set_active(status, FALSE);
+		if(NULL == status)
+			continue;
+
+		purple_status_set_active(status, FALSE);
+	}
+
+	g_slist_free(list);
 }
 
 static void
--- a/libpurple/status.c	Wed May 09 02:57:36 2007 +0000
+++ b/libpurple/status.c	Wed May 09 02:57:46 2007 +0000
@@ -134,8 +134,6 @@
 	10      /* Offline messageable      */
 };
 
-static GHashTable *buddy_presences = NULL;
-
 #define SCORE_IDLE      8
 #define SCORE_IDLE_TIME 9
 #define SCORE_OFFLINE_MESSAGE 10
@@ -1118,32 +1116,17 @@
 purple_presence_new_for_buddy(PurpleBuddy *buddy)
 {
 	PurplePresence *presence;
-	PurpleStatusBuddyKey *key;
 	PurpleAccount *account;
 
 	g_return_val_if_fail(buddy != NULL, NULL);
 	account = buddy->account;
 
-	key = g_new0(PurpleStatusBuddyKey, 1);
-	key->account = buddy->account;
-	key->name    = g_strdup(buddy->name);
-
-	presence = g_hash_table_lookup(buddy_presences, key);
-	if (presence == NULL)
-	{
-		presence = purple_presence_new(PURPLE_PRESENCE_CONTEXT_BUDDY);
+	presence = purple_presence_new(PURPLE_PRESENCE_CONTEXT_BUDDY);
 
-		presence->u.buddy.name    = g_strdup(buddy->name);
-		presence->u.buddy.account = buddy->account;
-		presence->statuses = purple_prpl_get_statuses(buddy->account, presence);
+	presence->u.buddy.name    = g_strdup(buddy->name);
+	presence->u.buddy.account = buddy->account;
+	presence->statuses = purple_prpl_get_statuses(buddy->account, presence);
 
-		g_hash_table_insert(buddy_presences, key, presence);
-	}
-	else
-	{
-		g_free(key->name);
-		g_free(key);
-	}
 	presence->u.buddy.buddy = buddy;
 
 	return presence;
@@ -1156,13 +1139,6 @@
 
 	if (purple_presence_get_context(presence) == PURPLE_PRESENCE_CONTEXT_BUDDY)
 	{
-		PurpleStatusBuddyKey key;
-
-		key.account = presence->u.buddy.account;
-		key.name    = presence->u.buddy.name;
-
-		g_hash_table_remove(buddy_presences, &key);
-
 		g_free(presence->u.buddy.name);
 	}
 	else if (purple_presence_get_context(presence) == PURPLE_PRESENCE_CONTEXT_CONV)
@@ -1639,41 +1615,6 @@
 	primitive_scores[index] = GPOINTER_TO_INT(value);
 }
 
-static guint
-purple_buddy_presences_hash(gconstpointer key)
-{
-	const PurpleStatusBuddyKey *me = key;
-	guint ret;
-	char *str;
-
-	str = g_strdup_printf("%p%s", me->account, me->name);
-	ret = g_str_hash(str);
-	g_free(str);
-
-	return ret;
-}
-
-static gboolean
-purple_buddy_presences_equal(gconstpointer a, gconstpointer b)
-{
-	PurpleStatusBuddyKey *key_a = (PurpleStatusBuddyKey *)a;
-	PurpleStatusBuddyKey *key_b = (PurpleStatusBuddyKey *)b;
-
-	if(key_a->account == key_b->account &&
-			!strcmp(key_a->name, key_b->name))
-		return TRUE;
-	else
-		return FALSE;
-}
-
-static void
-purple_buddy_presences_key_free(gpointer a)
-{
-	PurpleStatusBuddyKey *key = (PurpleStatusBuddyKey *)a;
-	g_free(key->name);
-	g_free(key);
-}
-
 void *
 purple_status_get_handle(void) {
 	static int handle;
@@ -1725,19 +1666,9 @@
 	purple_prefs_connect_callback(handle, "/purple/status/scores/offline_msg",
 			score_pref_changed_cb,
 			GINT_TO_POINTER(SCORE_OFFLINE_MESSAGE));
-
-	buddy_presences = g_hash_table_new_full(purple_buddy_presences_hash,
-											purple_buddy_presences_equal,
-											purple_buddy_presences_key_free, NULL);
 }
 
 void
 purple_status_uninit(void)
 {
-	if (buddy_presences != NULL)
-	{
-		g_hash_table_destroy(buddy_presences);
-
-		buddy_presences = NULL;
-	}
 }