changeset 593:db2a40cbd6ef

Add a <delay> to stanzas that are queued (and don't have one already), so clients can show them with the original timestamp.
author Thijs Alkemade <thijsalkemade@gmail.com>
date Thu, 02 Feb 2012 01:23:43 +0100
parents f9c73c1249cd
children 6da21a0bb018
files mod_smacks/mod_smacks.lua
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua	Thu Feb 02 01:23:00 2012 +0100
+++ b/mod_smacks/mod_smacks.lua	Thu Feb 02 01:23:43 2012 +0100
@@ -7,9 +7,11 @@
 local tonumber, tostring = tonumber, tostring;
 local add_filter = require "util.filters".add_filter;
 local timer = require "util.timer";
+local datetime = require "util.datetime";
 
 local xmlns_sm = "urn:xmpp:sm:3";
 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas";
+local xmlns_delay = "urn:xmpp:delay";
 
 local sm_attr = { xmlns = xmlns_sm };
 
@@ -70,7 +72,13 @@
 	local function new_send(stanza)
 		local attr = stanza.attr;
 		if attr and not attr.xmlns then -- Stanza in default stream namespace
-			queue[#queue+1] = st.clone(stanza);
+			local cached_stanza = st.clone(stanza);
+			
+			if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then
+				cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()});
+			end
+			
+			queue[#queue+1] = cached_stanza;
 		end
 		local ok, err = _send(stanza);
 		if ok and #queue > max_unacked_stanzas and not session.awaiting_ack then