Comparison

plugins/mod_smacks.lua @ 12063:d308f6901397

mod_smacks: Simplify access to local user sessions Less to type if per chance the next commit also wants to access sessions.
author Kim Alvefur <zash@zash.se>
date Fri, 17 Dec 2021 15:59:06 +0100
parent 12062:4972244fe87b
child 12064:d2380fd5e421
comparison
equal deleted inserted replaced
12062:4972244fe87b 12063:d308f6901397
43 local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0); 43 local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0);
44 local max_inactive_unacked_stanzas = module:get_option_number("smacks_max_inactive_unacked_stanzas", 256); 44 local max_inactive_unacked_stanzas = module:get_option_number("smacks_max_inactive_unacked_stanzas", 256);
45 local delayed_ack_timeout = module:get_option_number("smacks_max_ack_delay", 30); 45 local delayed_ack_timeout = module:get_option_number("smacks_max_ack_delay", 30);
46 46
47 local c2s_sessions = module:shared("/*/c2s/sessions"); 47 local c2s_sessions = module:shared("/*/c2s/sessions");
48 local local_sessions = prosody.hosts[module.host].sessions;
48 49
49 local function format_h(h) if h then return string.format("%d", h) end end 50 local function format_h(h) if h then return string.format("%d", h) end end
50 51
51 local old_session_registry = module:open_store("smacks_h", "map"); 52 local old_session_registry = module:open_store("smacks_h", "map");
52 local session_registry = module:shared "/*/smacks/resumption-tokens"; -- > user@host/resumption-token --> resource 53 local session_registry = module:shared "/*/smacks/resumption-tokens"; -- > user@host/resumption-token --> resource
411 if session.mam_requested and stanza_id ~= nil then 412 if session.mam_requested and stanza_id ~= nil then
412 session.log("debug", "mod_smacks delivery/failure returning true for mam-handled stanza: mam-archive-id=%s", tostring(stanza_id)); 413 session.log("debug", "mod_smacks delivery/failure returning true for mam-handled stanza: mam-archive-id=%s", tostring(stanza_id));
413 return true; -- stanza handled, don't send an error 414 return true; -- stanza handled, don't send an error
414 end 415 end
415 -- store message in offline store, if this client does not use mam *and* was the last client online 416 -- store message in offline store, if this client does not use mam *and* was the last client online
416 local sessions = prosody.hosts[module.host].sessions[session.username] and 417 local sessions = local_sessions[session.username] and local_sessions[session.username].sessions or nil;
417 prosody.hosts[module.host].sessions[session.username].sessions or nil;
418 if sessions and next(sessions) == session.resource and next(sessions, session.resource) == nil then 418 if sessions and next(sessions) == session.resource and next(sessions, session.resource) == nil then
419 local ok = module:fire_event("message/offline/handle", { origin = session, username = session.username, stanza = stanza }); 419 local ok = module:fire_event("message/offline/handle", { origin = session, username = session.username, stanza = stanza });
420 session.log("debug", "mod_smacks delivery/failure returning %s for offline-handled stanza", tostring(ok)); 420 session.log("debug", "mod_smacks delivery/failure returning %s for offline-handled stanza", tostring(ok));
421 return ok; -- if stanza was handled, don't send an error 421 return ok; -- if stanza was handled, don't send an error
422 end 422 end