cpw.malu.xmpp.idle: 2b7644a0: Patch from darkrain42

malu at pidgin.im malu at pidgin.im
Tue Nov 18 15:30:35 EST 2008


-----------------------------------------------------------------
Revision: 2b7644a0be37509450d6d1faf831af6fdcb8c0c2
Ancestor: 434c704edf18753d8e5b5148fdca3e3c83c3f018
Author: malu at pidgin.im
Date: 2008-11-18T20:24:59
Branch: im.pidgin.cpw.malu.xmpp.idle
URL: http://d.pidgin.im/viewmtn/revision/info/2b7644a0be37509450d6d1faf831af6fdcb8c0c2

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

ChangeLog: 

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)

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	c31ae1b757e2fd617a1e8aafd951febd00d71904
+++ libpurple/protocols/jabber/buddy.c	0a458ead9d2cc8ac0c9eaecafd028d3fef0956ef
@@ -111,20 +111,23 @@ JabberBuddyResource *jabber_buddy_find_r
 					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:
============================================================
--- libpurple/protocols/jabber/presence.c	5197a2329712e22ce177710a5e723d32be8b1f32
+++ libpurple/protocols/jabber/presence.c	806be165597dfacfe8e6f835b4819d0f7be08075
@@ -424,42 +424,6 @@ static void jabber_presence_set_capabili
 	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 @@ void jabber_presence_parse(JabberStream 
 		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);


More information about the Commits mailing list