Software /
code /
prosody-modules
Comparison
mod_presence_cache/mod_presence_cache.lua @ 2152:bb4a2e4b7ba7
mod_presence_cache: Forget about cached presence when receiving unavailable
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 03 Apr 2016 00:37:11 +0200 |
parent | 2147:ed2bb50d4f91 |
child | 2153:aa24d49c47ef |
comparison
equal
deleted
inserted
replaced
2151:96aca307964b | 2152:bb4a2e4b7ba7 |
---|---|
20 if next(jids) == nil then | 20 if next(jids) == nil then |
21 bare_cache[bare_cache_key] = nil; | 21 bare_cache[bare_cache_key] = nil; |
22 end | 22 end |
23 end | 23 end |
24 | 24 |
25 -- used indirectly for the on_evict callback | |
25 local presence_cache = cache.new(cache_size, on_evict); | 26 local presence_cache = cache.new(cache_size, on_evict); |
26 | 27 |
27 local function cache_hook(event) | 28 local function cache_hook(event) |
28 local origin, stanza = event.origin, event.stanza; | 29 local origin, stanza = event.origin, event.stanza; |
29 local typ = stanza.attr.type; | 30 local typ = stanza.attr.type; |
39 return; | 40 return; |
40 end | 41 end |
41 | 42 |
42 local cache_key = username .. "\0" .. contact_full; | 43 local cache_key = username .. "\0" .. contact_full; |
43 local bare_cache_key = username .. "\0" .. contact_bare; | 44 local bare_cache_key = username .. "\0" .. contact_bare; |
45 | |
46 local jids = bare_cache[bare_cache_key]; | |
47 | |
48 if typ == "unavailable" then -- remove from cache | |
49 presence_cache:set(cache_key, nil); | |
50 on_evict(cache_key); | |
51 return; | |
52 end | |
53 | |
44 local stamp = datetime.datetime(); | 54 local stamp = datetime.datetime(); |
45 local jids = bare_cache[bare_cache_key]; | |
46 if jids then | 55 if jids then |
47 jids[contact_full] = stamp; | 56 jids[contact_full] = stamp; |
48 else | 57 else |
49 jids = { [contact_full] = stamp }; | 58 jids = { [contact_full] = stamp }; |
50 bare_cache[bare_cache_key] = jids; | 59 bare_cache[bare_cache_key] = jids; |