Software /
code /
prosody-modules
Comparison
mod_mam/mod_mam.lua @ 1111:bdbf76730f49
mod_mam: Split out preference functions into a lib for easy reuse
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Jul 2013 22:46:15 +0200 |
parent | 1094:158680bff642 |
child | 1112:1dc07833355e |
comparison
equal
deleted
inserted
replaced
1110:97e238ce37ce | 1111:bdbf76730f49 |
---|---|
7 local xmlns_delay = "urn:xmpp:delay"; | 7 local xmlns_delay = "urn:xmpp:delay"; |
8 local xmlns_forward = "urn:xmpp:forward:0"; | 8 local xmlns_forward = "urn:xmpp:forward:0"; |
9 | 9 |
10 local st = require "util.stanza"; | 10 local st = require "util.stanza"; |
11 local rsm = module:require "rsm"; | 11 local rsm = module:require "rsm"; |
12 local prefs = module:require"mamprefs"; | |
13 local set_prefs, get_prefs = prefs.set, prefs.get; | |
12 local jid_bare = require "util.jid".bare; | 14 local jid_bare = require "util.jid".bare; |
13 local jid_split = require "util.jid".split; | 15 local jid_split = require "util.jid".split; |
14 local jid_prep = require "util.jid".prep; | 16 local jid_prep = require "util.jid".prep; |
15 local host = module.host; | 17 local host = module.host; |
16 | 18 |
17 local dm_load = require "util.datamanager".load; | |
18 local dm_store = require "util.datamanager".store; | |
19 local dm_list_load = require "util.datamanager".list_load; | 19 local dm_list_load = require "util.datamanager".list_load; |
20 local dm_list_append = require "util.datamanager".list_append; | 20 local dm_list_append = require "util.datamanager".list_append; |
21 local rm_load_roster = require "core.rostermanager".load_roster; | 21 local rm_load_roster = require "core.rostermanager".load_roster; |
22 | 22 |
23 local tostring = tostring; | 23 local tostring = tostring; |
36 always = true, [true] = "always", | 36 always = true, [true] = "always", |
37 never = false, [false] = "never", | 37 never = false, [false] = "never", |
38 roster = "roster", | 38 roster = "roster", |
39 } | 39 } |
40 | 40 |
41 do | |
42 local prefs_format = { | |
43 [false] = "roster", | |
44 -- default ::= true | false | "roster" | |
45 -- true = always, false = never, nil = global default | |
46 ["romeo@montague.net"] = true, -- always | |
47 ["montague@montague.net"] = false, -- newer | |
48 }; | |
49 end | |
50 | |
51 local archive_store = "archive2"; | 41 local archive_store = "archive2"; |
52 local prefs_store = archive_store .. "_prefs"; | |
53 local function get_prefs(user) | |
54 return dm_load(user, host, prefs_store) or | |
55 { [false] = global_default_policy }; | |
56 end | |
57 local function set_prefs(user, prefs) | |
58 return dm_store(user, host, prefs_store, prefs); | |
59 end | |
60 | |
61 | 42 |
62 -- Handle prefs. | 43 -- Handle prefs. |
63 module:hook("iq/self/"..xmlns_mam..":prefs", function(event) | 44 module:hook("iq/self/"..xmlns_mam..":prefs", function(event) |
64 local origin, stanza = event.origin, event.stanza; | 45 local origin, stanza = event.origin, event.stanza; |
65 local user = origin.username; | 46 local user = origin.username; |