pidgin: 96ab2472: jabber: Fix the resource_compare_cb func...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Feb 16 10:23:56 EST 2010


-----------------------------------------------------------------
Revision: 96ab2472dc2e3ada07400297425020b717eec5ce
Ancestor: a84f322aacd39e703e258f6fb74cca0908c4c055
Author: darkrain42 at pidgin.im
Date: 2010-02-15T05:41:15
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/96ab2472dc2e3ada07400297425020b717eec5ce

Modified files:
        libpurple/protocols/jabber/buddy.c

ChangeLog: 

jabber: Fix the resource_compare_cb function after checking how they're used with GSLists

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	f8990d24deb8fd91391eb6010eb432e88e528ca1
+++ libpurple/protocols/jabber/buddy.c	d88210ef5f22ba33b392bc31e79e435eedfda294
@@ -91,6 +91,10 @@ JabberBuddy *jabber_buddy_find(JabberStr
 	return jb;
 }
 
+/* Returns -1 if a is a higher priority resource than b, or is
+ * "more available" than b.  0 if they're the same, and 1 if b is
+ * higher priority/more available than a.
+ */
 static gint resource_compare_cb(gconstpointer a, gconstpointer b)
 {
 	const JabberBuddyResource *jbra = a;
@@ -98,9 +102,10 @@ static gint resource_compare_cb(gconstpo
 	JabberBuddyState state_a, state_b;
 
 	if (jbra->priority != jbrb->priority)
-		return jbra->priority > jbrb->priority ? 1 : -1;
+		return jbra->priority > jbrb->priority ? -1 : 1;
 
 	/* Fold the states for easier comparison */
+	/* TODO: Differentiate online/chat and away/dnd? */
 	switch (jbra->state) {
 		case JABBER_BUDDY_STATE_ONLINE:
 		case JABBER_BUDDY_STATE_CHAT:
@@ -146,27 +151,27 @@ static gint resource_compare_cb(gconstpo
 			return 0;
 		else if ((jbra->idle && !jbrb->idle) ||
 				(jbra->idle && jbrb->idle && jbra->idle < jbrb->idle))
-			return -1;
+			return 1;
 		else
-			return 1;
+			return -1;
 	}
 
 	if (state_a == JABBER_BUDDY_STATE_ONLINE)
-		return 1;
+		return -1;
 	else if (state_a == JABBER_BUDDY_STATE_AWAY &&
 				(state_b == JABBER_BUDDY_STATE_XA ||
 				 state_b == JABBER_BUDDY_STATE_UNAVAILABLE ||
 				 state_b == JABBER_BUDDY_STATE_UNKNOWN))
-		return 1;
+		return -1;
 	else if (state_a == JABBER_BUDDY_STATE_XA &&
 				(state_b == JABBER_BUDDY_STATE_UNAVAILABLE ||
 				 state_b == JABBER_BUDDY_STATE_UNKNOWN))
-		return 1;
+		return -1;
 	else if (state_a == JABBER_BUDDY_STATE_UNAVAILABLE &&
 				state_b == JABBER_BUDDY_STATE_UNKNOWN)
-		return 1;
+		return -1;
 
-	return -1;
+	return 1;
 }
 
 JabberBuddyResource *jabber_buddy_find_resource(JabberBuddy *jb,
@@ -184,7 +189,7 @@ JabberBuddyResource *jabber_buddy_find_r
 		if (!jbr && !resource) {
 			jbr = tmp;
 		} else if (!resource) {
-			if (resource_compare_cb(tmp, jbr) > 0)
+			if (resource_compare_cb(tmp, jbr) < 0)
 				jbr = tmp;
 		} else if(tmp->name) {
 			if(!strcmp(tmp->name, resource)) {


More information about the Commits mailing list