pidgin: d18a2fb8: Show when a user was last online (as see...

malu at pidgin.im malu at pidgin.im
Thu May 7 15:25:34 EDT 2009


-----------------------------------------------------------------
Revision: d18a2fb889285b2abc7f06a20f700eadb1697001
Ancestor: 0d3e7183f1b6345a8fda3322c688e7e922536162
Author: malu at pidgin.im
Date: 2009-05-07T19:24:02
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d18a2fb889285b2abc7f06a20f700eadb1697001

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

ChangeLog: 

Show when a user was last online (as seen by the server) when doing "Get Info"
by issuing a jabber:iq:last to the bare JID

-------------- next part --------------
============================================================
--- ChangeLog	eca31d69d145410484de05c54bffedb800b8634e
+++ ChangeLog	8178868ecdb8d1c9eb36c7f0f18a1ea0f92e6225
@@ -36,6 +36,8 @@ version 2.6.0 (??/??/2009):
 	* Put section breaks between resources in "Get Info" to improve readability.
 	* XHTML markup is only included in outgoing messages when the message
 	  contains formatting.
+	* Show when the user was last logged in when doing "Get Info" on an offline
+	  buddy, provided the server supports it.
 
 	Yahoo:
 	* P2P file transfers. (Sulabh Mahajan)
============================================================
--- libpurple/protocols/jabber/buddy.c	b707531ebde0a917aca9c10393e4f5ec6ec4b42c
+++ libpurple/protocols/jabber/buddy.c	d9c74e68672d223799c7d27cf3cb38cd5650791f
@@ -50,6 +50,8 @@ typedef struct {
 	int timeout_handle;
 	GSList *vcard_imgids;
 	PurpleNotifyUserInfo *user_info;
+	long last_seconds;
+	gchar *last_message;
 } JabberBuddyInfo;
 
 void jabber_buddy_free(JabberBuddy *jb)
@@ -642,6 +644,7 @@ static void jabber_buddy_info_destroy(Ja
 
 	g_free(jbi->jid);
 	g_hash_table_destroy(jbi->resources);
+	g_free(jbi->last_message);
 	purple_notify_user_info_destroy(jbi->user_info);
 	g_free(jbi);
 }
@@ -1039,6 +1042,24 @@ static void jabber_buddy_info_show_if_re
 		}
 	}
 
+	if (!jbi->jb->resources) {
+		/* the buddy is offline */
+		gchar *status = 
+			g_strdup_printf("%s%s%s",	_("Offline"), 
+				jbi->last_message ? ": " : "",
+				jbi->last_message ? jbi->last_message : "");
+		if (jbi->last_seconds > 0) {
+			char *last = purple_str_seconds_to_string(jbi->last_seconds);
+			gchar *message = g_strdup_printf(_("%s ago"), last);
+			purple_notify_user_info_prepend_pair(user_info, 
+				_("Last logged in"), message);
+			g_free(last);
+			g_free(message);
+		}
+		purple_notify_user_info_prepend_pair(user_info, _("Status"), status);
+		g_free(status);
+	}
+
 	g_free(resource_name);
 
 	purple_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL);
@@ -1491,6 +1512,38 @@ static void jabber_last_parse(JabberStre
 	jabber_buddy_info_show_if_ready(jbi);
 }
 
+static void jabber_last_offline_parse(JabberStream *js, const char *from,
+									  JabberIqType type, const char *id,
+									  xmlnode *packet, gpointer data)
+{
+	JabberBuddyInfo *jbi = data;
+	xmlnode *query;
+	const char *seconds;
+
+	g_return_if_fail(jbi != NULL);
+
+	jabber_buddy_info_remove_id(jbi, id);
+
+	if(!from)
+		return;
+
+	if (type == JABBER_IQ_RESULT) {
+		if((query = xmlnode_get_child(packet, "query"))) {
+			seconds = xmlnode_get_attrib(query, "seconds");
+			if(seconds) {
+				char *end = NULL;
+				long sec = strtol(seconds, &end, 10);
+				if(end != seconds) {
+					jbi->last_seconds = sec;
+				}
+			}
+			jbi->last_message = xmlnode_get_data(query);
+		}
+	}
+
+	jabber_buddy_info_show_if_ready(jbi);
+}
+
 static void jabber_time_parse(JabberStream *js, const char *from,
                               JabberIqType type, const char *id,
                               xmlnode *packet, gpointer data)
@@ -1688,6 +1741,15 @@ static void jabber_buddy_get_info_for_ji
 		g_free(full_jid);
 	}
 
+	if (!jb->resources) {
+		/* user is offline, send a jabber:iq:last to find out last time online */
+		iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
+		xmlnode_set_attrib(iq->node, "to", jid);
+		jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi);
+		jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
+		jabber_iq_send(iq);
+	}
+	
 	js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi);
 	jbi->timeout_handle = purple_timeout_add_seconds(30, jabber_buddy_get_info_timeout, jbi);
 }


More information about the Commits mailing list