changeset 25797:cac2f6203505

Patch from darkrain42 Use idleness when finding buddy resources (most active) Use resource found using jabber_buddy_find_resource to report idle time (get rid of an extra function to rank on idle time)
author Marcus Lundblad <ml@update.uu.se>
date Tue, 18 Nov 2008 20:24:59 +0000
parents c5c4faef04ff
children 8060be20fa6e
files libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/presence.c
diffstat 2 files changed, 8 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Tue Nov 18 20:22:57 2008 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Tue Nov 18 20:24:59 2008 +0000
@@ -111,20 +111,23 @@
 					case JABBER_BUDDY_STATE_ONLINE:
 					case JABBER_BUDDY_STATE_CHAT:
 						/* This resource is online/chatty. Prefer to one which isn't either. */
-						if ((jbr->state != JABBER_BUDDY_STATE_ONLINE) && (jbr->state != JABBER_BUDDY_STATE_CHAT))
+						if (((jbr->state != JABBER_BUDDY_STATE_ONLINE) && (jbr->state != JABBER_BUDDY_STATE_CHAT)) ||
+							(jbr->idle && !tmp->idle) || (jbr->idle && tmp->idle && tmp->idle > jbr->idle))
 							jbr = tmp;
 						break;
 					case JABBER_BUDDY_STATE_AWAY:
 					case JABBER_BUDDY_STATE_DND:
 					case JABBER_BUDDY_STATE_UNAVAILABLE:
 						/* This resource is away/dnd/unavailable. Prefer to one which is extended away or unknown. */
-						if ((jbr->state == JABBER_BUDDY_STATE_XA) || 
-							(jbr->state == JABBER_BUDDY_STATE_UNKNOWN) || (jbr->state == JABBER_BUDDY_STATE_ERROR))
+						if (((jbr->state == JABBER_BUDDY_STATE_XA) || 
+							(jbr->state == JABBER_BUDDY_STATE_UNKNOWN) || (jbr->state == JABBER_BUDDY_STATE_ERROR)) ||
+							(jbr->idle && !tmp->idle) || (jbr->idle && tmp->idle && tmp->idle > jbr->idle))
 							jbr = tmp;
 						break;
 					case JABBER_BUDDY_STATE_XA:
 						/* This resource is extended away. That's better than unknown. */
-						if ((jbr->state == JABBER_BUDDY_STATE_UNKNOWN) || (jbr->state == JABBER_BUDDY_STATE_ERROR))
+						if (((jbr->state == JABBER_BUDDY_STATE_UNKNOWN) || (jbr->state == JABBER_BUDDY_STATE_ERROR)) ||
+							(jbr->idle && !tmp->idle) || (jbr->idle && tmp->idle && tmp->idle > jbr->idle))
 							jbr = tmp;
 						break;
 					case JABBER_BUDDY_STATE_UNKNOWN:
--- a/libpurple/protocols/jabber/presence.c	Tue Nov 18 20:22:57 2008 +0000
+++ b/libpurple/protocols/jabber/presence.c	Tue Nov 18 20:24:59 2008 +0000
@@ -424,42 +424,6 @@
 	g_free(userdata);
 }
 
-static void
-jabber_presence_update_buddy_idle(PurpleAccount *account, const gchar *who,
-	JabberBuddy *jb)
-{
-	const GList *iter = NULL;
-	gboolean idle = TRUE;
-	time_t last_idle = 0;
-	
-	purple_debug_info("jabber", "updating idle for buddy %s\n", who);
-	
-	if (!jb->resources) {
-		idle = FALSE;
-	}
-		
-	for (iter = jb->resources ; iter ; iter = g_list_next(iter)) {
-		JabberBuddyResource *jbr = (JabberBuddyResource *) iter->data;
-		
-		purple_debug_info("jabber", "resource %s has an idle set to %ld\n",
-			jbr->name, jbr->idle);
-		
-		if (!jbr->idle) {
-			idle = FALSE;
-			break;
-		}
-		if (jbr->idle > last_idle) {
-			last_idle = jbr->idle;
-		}
-	}
-	
-	if (idle) {
-		purple_prpl_got_user_idle(account, who, TRUE, last_idle);
-	} else {
-		purple_prpl_got_user_idle(account, who, FALSE, 0);
-	}
-}
-
 void jabber_presence_parse(JabberStream *js, xmlnode *packet)
 {
 	const char *from = xmlnode_get_attrib(packet, "from");
@@ -843,10 +807,10 @@
 		if((found_jbr = jabber_buddy_find_resource(jb, NULL))) {
 			jabber_google_presence_incoming(js, buddy_name, found_jbr);
 			purple_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(found_jbr->state), "priority", found_jbr->priority, "message", found_jbr->status, NULL);
+			purple_prpl_got_user_idle(js->gc->account, buddy_name, found_jbr->idle, found_jbr->idle);
 		} else {
 			purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL);
 		}
-		jabber_presence_update_buddy_idle(js->gc->account, buddy_name, jb);
 		g_free(buddy_name);
 	}
 	g_free(status);