comparison mod_smacks/mod_smacks.lua @ 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
comparison
equal deleted inserted replaced
592:f9c73c1249cd 593:db2a40cbd6ef
5 local math_min = math.min; 5 local math_min = math.min;
6 local os_time = os.time; 6 local os_time = os.time;
7 local tonumber, tostring = tonumber, tostring; 7 local tonumber, tostring = tonumber, tostring;
8 local add_filter = require "util.filters".add_filter; 8 local add_filter = require "util.filters".add_filter;
9 local timer = require "util.timer"; 9 local timer = require "util.timer";
10 local datetime = require "util.datetime";
10 11
11 local xmlns_sm = "urn:xmpp:sm:3"; 12 local xmlns_sm = "urn:xmpp:sm:3";
12 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; 13 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas";
14 local xmlns_delay = "urn:xmpp:delay";
13 15
14 local sm_attr = { xmlns = xmlns_sm }; 16 local sm_attr = { xmlns = xmlns_sm };
15 17
16 local resume_timeout = module:get_option("smacks_hibernation_time", 300); 18 local resume_timeout = module:get_option("smacks_hibernation_time", 300);
17 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); 19 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false);
68 70
69 local _send = session.sends2s or session.send; 71 local _send = session.sends2s or session.send;
70 local function new_send(stanza) 72 local function new_send(stanza)
71 local attr = stanza.attr; 73 local attr = stanza.attr;
72 if attr and not attr.xmlns then -- Stanza in default stream namespace 74 if attr and not attr.xmlns then -- Stanza in default stream namespace
73 queue[#queue+1] = st.clone(stanza); 75 local cached_stanza = st.clone(stanza);
76
77 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then
78 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()});
79 end
80
81 queue[#queue+1] = cached_stanza;
74 end 82 end
75 local ok, err = _send(stanza); 83 local ok, err = _send(stanza);
76 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack then 84 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack then
77 session.awaiting_ack = true; 85 session.awaiting_ack = true;
78 return _send(st.stanza("r", sm_attr)); 86 return _send(st.stanza("r", sm_attr));