Software /
code /
prosody
Comparison
plugins/mod_mam/mamprefsxml.lib.lua @ 7836:30fac9154fd4
mod_mam: Import from prosody-modules
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 04 Nov 2016 13:48:21 +0100 |
child | 7839:f3e1925f29c2 |
comparison
equal
deleted
inserted
replaced
7835:a809dcfd0c5b | 7836:30fac9154fd4 |
---|---|
1 -- XEP-0313: Message Archive Management for Prosody | |
2 -- Copyright (C) 2011-2013 Kim Alvefur | |
3 -- | |
4 -- This file is MIT/X11 licensed. | |
5 | |
6 local st = require"util.stanza"; | |
7 local xmlns_mam = "urn:xmpp:mam:0"; | |
8 | |
9 local default_attrs = { | |
10 always = true, [true] = "always", | |
11 never = false, [false] = "never", | |
12 roster = "roster", | |
13 } | |
14 | |
15 local function tostanza(prefs) | |
16 local default = prefs[false]; | |
17 default = default_attrs[default]; | |
18 local prefstanza = st.stanza("prefs", { xmlns = xmlns_mam, default = default }); | |
19 local always = st.stanza("always"); | |
20 local never = st.stanza("never"); | |
21 for jid, choice in pairs(prefs) do | |
22 if jid then | |
23 (choice and always or never):tag("jid"):text(jid):up(); | |
24 end | |
25 end | |
26 prefstanza:add_child(always):add_child(never); | |
27 return prefstanza; | |
28 end | |
29 local function fromstanza(prefstanza) | |
30 local prefs = {}; | |
31 local default = prefstanza.attr.default; | |
32 if default then | |
33 prefs[false] = default_attrs[default]; | |
34 end | |
35 | |
36 local always = prefstanza:get_child("always"); | |
37 if always then | |
38 for rule in always:childtags("jid") do | |
39 local jid = rule:get_text(); | |
40 prefs[jid] = true; | |
41 end | |
42 end | |
43 | |
44 local never = prefstanza:get_child("never"); | |
45 if never then | |
46 for rule in never:childtags("jid") do | |
47 local jid = rule:get_text(); | |
48 prefs[jid] = false; | |
49 end | |
50 end | |
51 | |
52 return prefs; | |
53 end | |
54 | |
55 return { | |
56 tostanza = tostanza; | |
57 fromstanza = fromstanza; | |
58 } |