Annotate

plugins/mod_mam/mamprefsxml.lib.lua @ 7839:f3e1925f29c2

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