changeset 31308:f178a7df417a

jabber: Support for requesting limited history when joining a MUC. Patch from xnyhps, with some minor corrections by me. Fixes #10986. Refs #a14219.
author Paul Aurich <paul@darkrain42.org>
date Sun, 06 Mar 2011 23:03:47 +0000
parents 9d8a47ca14a1
children 356adba49dae
files ChangeLog ChangeLog.API libpurple/protocols/jabber/chat.c
diffstat 3 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Mar 06 22:53:15 2011 +0000
+++ b/ChangeLog	Sun Mar 06 23:03:47 2011 +0000
@@ -30,6 +30,9 @@
 	  Alkemade) (#a14527)
 	* Extend the /join command to support room JIDs, enabling you to join
 	  a room on any server.  (Solarius, Matěj Cepl, wyuka) (#4526)
+	* Add support for receiving a limited amount of history when joining a
+	  room (not currently supported by Pidgin and Finch).  (Thijs Alkemade)
+	  (#10986, #a14219)
 
 version 2.7.10 (02/06/2011):
 	General:
--- a/ChangeLog.API	Sun Mar 06 22:53:15 2011 +0000
+++ b/ChangeLog.API	Sun Mar 06 23:03:47 2011 +0000
@@ -1,6 +1,15 @@
 Pidgin and Finch: The Pimpin' Penguin IM Clients That're Good for the Soul
 
 version 2.7.11 (??/??/????):
+	* libpurple:
+		Added:
+		* Four entries in the GHashTable passed when joining
+		  an XMPP chat room which allow the UI to request a limited
+		  amount of history.  See XEP-0045 7.1.16 for details; the
+		  entries are named history_maxchars, history_maxstanzas,
+		  history_seconds, and history_since.  history_since must be
+		  interpretable by purple_str_to_time, and the prpl takes care
+		  of formatting the time properly.
 	* Perl:
 		Added:
 		* Purple::find_conversation_with_account
--- a/libpurple/protocols/jabber/chat.c	Sun Mar 06 22:53:15 2011 +0000
+++ b/libpurple/protocols/jabber/chat.c	Sun Mar 06 23:03:47 2011 +0000
@@ -281,6 +281,14 @@
 
 	char *jid;
 
+	char *history_maxchars;
+	char *history_maxstanzas;
+	char *history_seconds;
+	char *history_since;
+
+	struct tm history_since_datetime;
+	const char *history_since_string = NULL;
+
 	chat = jabber_chat_new(js, room, server, handle, password, data);
 	if (chat == NULL)
 		return NULL;
@@ -297,6 +305,22 @@
 	xmlnode_set_attrib(presence, "to", jid);
 	g_free(jid);
 
+	history_maxchars   = g_hash_table_lookup(data, "history_maxchars");
+	history_maxstanzas = g_hash_table_lookup(data, "history_maxstanzas");
+	history_seconds    = g_hash_table_lookup(data, "history_seconds");
+	history_since      = g_hash_table_lookup(data, "history_since");
+
+	if (history_since) {
+		if (purple_str_to_time(history_since, TRUE, &history_since_datetime, NULL, NULL) != 0) {
+			history_since_string = purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", &history_since_datetime);
+		} else {
+			history_since_string = NULL;
+
+			purple_debug_error("jabber", "Invalid date format for history_since"
+			                             " while requesting history: %s", history_since);
+		}
+	}
+
 	x = xmlnode_new_child(presence, "x");
 	xmlnode_set_namespace(x, "http://jabber.org/protocol/muc");
 
@@ -305,6 +329,27 @@
 		xmlnode_insert_data(p, password, -1);
 	}
 
+	if ((history_maxchars && *history_maxchars)
+	    || (history_maxstanzas && *history_maxstanzas)
+	    || (history_seconds && *history_seconds)
+	    || (history_since_string && *history_since_string)) {
+
+		xmlnode *history = xmlnode_new_child(x, "history");
+
+		if (history_maxchars && *history_maxchars) {
+			xmlnode_set_attrib(history, "maxchars", history_maxchars);
+		}
+		if (history_maxstanzas && *history_maxstanzas) {
+			xmlnode_set_attrib(history, "maxstanzas", history_maxstanzas);
+		}
+		if (history_seconds && *history_seconds) {
+			xmlnode_set_attrib(history, "seconds", history_seconds);
+		}
+		if (history_since_string && *history_since_string) {
+			xmlnode_set_attrib(history, "since", history_since_string);
+		}
+	}
+
 	jabber_send(js, presence);
 	xmlnode_free(presence);