comparison mod_throttle_presence/mod_throttle_presence.lua @ 1925:552faee596b7

mod_throttle_presence: Switch if-else statement around to improve readability
author Kim Alvefur <zash@zash.se>
date Fri, 23 Oct 2015 16:48:11 +0200
parents 34468d3bfcac
children
comparison
equal deleted inserted replaced
1924:c84cf61ca0f3 1925:552faee596b7
11 stanza._flush = nil; 11 stanza._flush = nil;
12 return stanza; 12 return stanza;
13 end 13 end
14 local buffer = session.presence_buffer; 14 local buffer = session.presence_buffer;
15 local from = stanza.attr.from; 15 local from = stanza.attr.from;
16 if stanza.name ~= "presence" or (stanza.attr.type and stanza.attr.type ~= "unavailable") then 16 if stanza.name == "presence" and (stanza.attr.type == nil or stanza.attr.type == "unavailable") then
17 module:log("debug", "Buffering presence stanza from %s to %s", stanza.attr.from, session.full_jid);
18 buffer[stanza.attr.from] = st.clone(stanza);
19 return nil; -- Drop this stanza (we've stored it for later)
20 else
17 local cached_presence = buffer[stanza.attr.from]; 21 local cached_presence = buffer[stanza.attr.from];
18 if cached_presence then 22 if cached_presence then
19 module:log("debug", "Important stanza for %s from %s, flushing presence", session.full_jid, from); 23 module:log("debug", "Important stanza for %s from %s, flushing presence", session.full_jid, from);
20 stanza._flush = true; 24 stanza._flush = true;
21 cached_presence._flush = true; 25 cached_presence._flush = true;
22 session.send(cached_presence); 26 session.send(cached_presence);
23 buffer[stanza.attr.from] = nil; 27 buffer[stanza.attr.from] = nil;
24 end 28 end
25 else
26 module:log("debug", "Buffering presence stanza from %s to %s", stanza.attr.from, session.full_jid);
27 buffer[stanza.attr.from] = st.clone(stanza);
28 return nil; -- Drop this stanza (we've stored it for later)
29 end 29 end
30 return stanza; 30 return stanza;
31 end 31 end
32 32
33 local function throttle_session(event) 33 local function throttle_session(event)