comparison mod_presence_cache/mod_presence_cache.lua @ 2146:39d958f4a0c3

mod_presence_cache: Remove caching of full presence
author Kim Alvefur <zash@zash.se>
date Fri, 01 Apr 2016 15:15:56 +0200
parents f965f86a5cad
children ed2bb50d4f91
comparison
equal deleted inserted replaced
2145:f965f86a5cad 2146:39d958f4a0c3
3 local jid_bare = require"util.jid".bare; 3 local jid_bare = require"util.jid".bare;
4 local st = require"util.stanza"; 4 local st = require"util.stanza";
5 local datetime = require"util.datetime"; 5 local datetime = require"util.datetime";
6 6
7 local presence_cache = {}; -- Reload to empty 7 local presence_cache = {}; -- Reload to empty
8
9 local cache_full = module:get_option_boolean(module.name.."_full", false);
10 8
11 local function cache_hook(event) 9 local function cache_hook(event)
12 local origin, stanza = event.origin, event.stanza; 10 local origin, stanza = event.origin, event.stanza;
13 local typ = stanza.attr.type; 11 local typ = stanza.attr.type;
14 module:log("debug", "Cache hook, got %s from a %s", stanza:top_tag(), origin.type); 12 module:log("debug", "Cache hook, got %s from a %s", stanza:top_tag(), origin.type);
40 user_presence_cache[from_bare] = nil; 38 user_presence_cache[from_bare] = nil;
41 if next(user_presence_cache) == nil then 39 if next(user_presence_cache) == nil then
42 presence_cache[username] = nil; 40 presence_cache[username] = nil;
43 end 41 end
44 end 42 end
45 elseif cache_full then
46 stanza = st.clone(stanza);
47 stanza:tag("delay", { xmlns = "urn:xmpp:delay", from = module.host, stamp = datetime.datetime() }):up();
48 contact_presence_cache[from_jid] = stanza;
49 else -- only cache binary state 43 else -- only cache binary state
50 contact_presence_cache[from_jid] = datetime.datetime(); 44 contact_presence_cache[from_jid] = datetime.datetime();
51 end 45 end
52 end 46 end
53 end 47 end
75 presence = st.presence({ from = user_jid, from = jid }) 69 presence = st.presence({ from = user_jid, from = jid })
76 :tag("delay", { xmlns = "urn:xmpp:delay", from = module.host, stamp = presence }):up(); 70 :tag("delay", { xmlns = "urn:xmpp:delay", from = module.host, stamp = presence }):up();
77 end 71 end
78 origin.send(presence); 72 origin.send(presence);
79 end 73 end
80 if cache_full then
81 return true;
82 end
83 end 74 end
84 75
85 module:hook("pre-presence/bare", answer_probe_from_cache, 10); 76 module:hook("pre-presence/bare", answer_probe_from_cache, 10);
86 77
87 module:add_timer(3600, function (now) 78 module:add_timer(3600, function (now)