Mercurial > prosody-hg
comparison plugins/mod_mam/mamprefs.lib.lua @ 8538:3eb4cafb3b64
mod_mam: Implement option to enable MAM implicitly when client support is detected (#867)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 21 Feb 2018 21:02:16 +0100 |
| parents | aa6497031924 |
| children | 173038306750 |
comparison
equal
deleted
inserted
replaced
| 8517:980d2daf3ed4 | 8538:3eb4cafb3b64 |
|---|---|
| 12 | 12 |
| 13 local global_default_policy = module:get_option_string("default_archive_policy", true); | 13 local global_default_policy = module:get_option_string("default_archive_policy", true); |
| 14 if global_default_policy ~= "roster" then | 14 if global_default_policy ~= "roster" then |
| 15 global_default_policy = module:get_option_boolean("default_archive_policy", global_default_policy); | 15 global_default_policy = module:get_option_boolean("default_archive_policy", global_default_policy); |
| 16 end | 16 end |
| 17 local smart_enable = module:get_option_boolean("mam_smart_enable", false); | |
| 17 | 18 |
| 18 do | 19 do |
| 19 -- luacheck: ignore 211/prefs_format | 20 -- luacheck: ignore 211/prefs_format |
| 20 local prefs_format = { | 21 local prefs_format = { |
| 21 [false] = "roster", | 22 [false] = "roster", |
| 28 | 29 |
| 29 local sessions = prosody.hosts[module.host].sessions; | 30 local sessions = prosody.hosts[module.host].sessions; |
| 30 local archive_store = module:get_option_string("archive_store", "archive"); | 31 local archive_store = module:get_option_string("archive_store", "archive"); |
| 31 local prefs = module:open_store(archive_store .. "_prefs"); | 32 local prefs = module:open_store(archive_store .. "_prefs"); |
| 32 | 33 |
| 33 local function get_prefs(user) | 34 local function get_prefs(user, explicit) |
| 34 local user_sessions = sessions[user]; | 35 local user_sessions = sessions[user]; |
| 35 local user_prefs = user_sessions and user_sessions.archive_prefs | 36 local user_prefs = user_sessions and user_sessions.archive_prefs |
| 36 if not user_prefs then | 37 if not user_prefs then |
| 38 -- prefs not cached | |
| 37 user_prefs = prefs:get(user); | 39 user_prefs = prefs:get(user); |
| 40 if not user_prefs then | |
| 41 -- prefs not set | |
| 42 if smart_enable and explicit then | |
| 43 -- a mam-capable client was involved in this action, set defaults | |
| 44 user_prefs = { [false] = global_default_policy }; | |
| 45 prefs:set(user, user_prefs); | |
| 46 end | |
| 47 end | |
| 38 if user_sessions then | 48 if user_sessions then |
| 49 -- cache settings if they originate from user action | |
| 39 user_sessions.archive_prefs = user_prefs; | 50 user_sessions.archive_prefs = user_prefs; |
| 40 end | 51 end |
| 52 if not user_prefs then | |
| 53 if smart_enable then | |
| 54 -- not yet enabled, either explicitly or "smart" | |
| 55 user_prefs = { [false] = false }; | |
| 56 else | |
| 57 -- no explicit settings, return defaults | |
| 58 user_prefs = { [false] = global_default_policy }; | |
| 59 end | |
| 60 end | |
| 41 end | 61 end |
| 42 return user_prefs or { [false] = global_default_policy }; | 62 return user_prefs; |
| 43 end | 63 end |
| 64 | |
| 44 local function set_prefs(user, user_prefs) | 65 local function set_prefs(user, user_prefs) |
| 45 local user_sessions = sessions[user]; | 66 local user_sessions = sessions[user]; |
| 46 if user_sessions then | 67 if user_sessions then |
| 47 user_sessions.archive_prefs = user_prefs; | 68 user_sessions.archive_prefs = user_prefs; |
| 48 end | 69 end |
