comparison mod_throttle_presence/mod_throttle_presence.lua @ 1504:b8164f18142a

mod_throttle_presence: Make sure flushed stanzas get through the filter
author Kim Alvefur <zash@zash.se>
date Tue, 16 Sep 2014 16:44:32 +0200
parents 95f10fb7f60e
children 34468d3bfcac
comparison
equal deleted inserted replaced
1503:c4c9ccc6e6c9 1504:b8164f18142a
2 local st = require "util.stanza"; 2 local st = require "util.stanza";
3 3
4 module:depends("csi"); 4 module:depends("csi");
5 5
6 local function presence_filter(stanza, session) 6 local function presence_filter(stanza, session)
7 if stanza._flush then
8 stanza._flush = nil;
9 return stanza;
10 end
7 local buffer = session.presence_buffer; 11 local buffer = session.presence_buffer;
8 local from = stanza.attr.from; 12 local from = stanza.attr.from;
9 if stanza.name ~= "presence" or (stanza.attr.type and stanza.attr.type ~= "unavailable") then 13 if stanza.name ~= "presence" or (stanza.attr.type and stanza.attr.type ~= "unavailable") then
10 local cached_presence = buffer[stanza.attr.from]; 14 local cached_presence = buffer[stanza.attr.from];
11 if cached_presence then 15 if cached_presence then
12 module:log("debug", "Important stanza for %s from %s, flushing presence", session.full_jid, from); 16 module:log("debug", "Important stanza for %s from %s, flushing presence", session.full_jid, from);
17 stanza._flush = true;
18 cached_presence._flush = true;
13 session.send(cached_presence); 19 session.send(cached_presence);
14 buffer[stanza.attr.from] = nil; 20 buffer[stanza.attr.from] = nil;
15 end 21 end
16 else 22 else
17 module:log("debug", "Buffering presence stanza from %s to %s", stanza.attr.from, session.full_jid); 23 module:log("debug", "Buffering presence stanza from %s to %s", stanza.attr.from, session.full_jid);