cpw.malu.xmpp.idle: 964c1a52: Support setting offset from <delayed/> e..

malu at pidgin.im malu at pidgin.im
Mon Nov 17 18:20:29 EST 2008


-----------------------------------------------------------------
Revision: 964c1a52f7853fd5b99ca0d000fd0dfb83aca9ac
Ancestor: 18de7ed8a29db51e943c1649ac63b3374a76747d
Author: malu at pidgin.im
Date: 2008-11-17T23:18:12
Branch: im.pidgin.cpw.malu.xmpp.idle
URL: http://d.pidgin.im/viewmtn/revision/info/964c1a52f7853fd5b99ca0d000fd0dfb83aca9ac

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

ChangeLog: 

Support setting offset from <delayed/> element in <presence/> or "stamp"
attribute on an <x/> element (old XEP for delayed messages).
Hopefully this works (I tested the code by "faking" hard-coded "stamp" values

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/presence.c	62a9edbd04fd3676a6b4da48fde40c3ce8ed7a0b
+++ libpurple/protocols/jabber/presence.c	5197a2329712e22ce177710a5e723d32be8b1f32
@@ -475,6 +475,7 @@ void jabber_presence_parse(JabberStream 
 	JabberBuddyResource *jbr = NULL, *found_jbr = NULL;
 	PurpleConvChatBuddyFlags flags = PURPLE_CBFLAGS_NONE;
 	gboolean delayed = FALSE;
+	const gchar *stamp = NULL; /* from <delayed/> element */
 	PurpleBuddy *b = NULL;
 	char *buddy_name;
 	JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN;
@@ -562,6 +563,7 @@ void jabber_presence_parse(JabberStream 
 		} else if(!strcmp(y->name, "delay") && !strcmp(xmlns, "urn:xmpp:delay")) {
 			/* XXX: compare the time.  jabber:x:delay can happen on presence packets that aren't really and truly delayed */
 			delayed = TRUE;
+			stamp = xmlnode_get_attrib(y, "stamp");
 		} else if(!strcmp(y->name, "c") && !strcmp(xmlns, "http://jabber.org/protocol/caps")) {
 			caps = y; /* store for later, when creating buddy resource */
 		} else if(!strcmp(y->name, "x")) {
@@ -569,6 +571,7 @@ void jabber_presence_parse(JabberStream 
 			if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
 				/* XXX: compare the time.  jabber:x:delay can happen on presence packets that aren't really and truly delayed */
 				delayed = TRUE;
+				stamp = xmlnode_get_attrib(y, "stamp");
 			} else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) {
 				xmlnode *z;
 
@@ -630,6 +633,18 @@ void jabber_presence_parse(JabberStream 
 		}
 	}
 
+	purple_debug_info("jabber", "got %d seconds idle from presence\n", idle);
+	
+	if (idle && delayed && stamp) {
+		/* if we have a delayed presence, we need to add the delay to the idle
+		 value */
+		time_t offset = time(NULL) - purple_str_to_time(stamp, TRUE, NULL, NULL,
+			NULL);
+		purple_debug_info("jabber", "got delay %s yielding %ld s offset\n",
+			stamp, offset);
+		idle += offset; 
+	}
+	
 
 	if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) {
 		static int i = 1;


More information about the Commits mailing list