2 -- Copyright (C) 2008-2017 Matthew Wild
3 -- Copyright (C) 2008-2017 Waqas Hussain
4 -- Copyright (C) 2011-2017 Kim Alvefur
5 -- Copyright (C) 2018 Emmanuel Gil Peyrot
7 -- This project is MIT/X11 licensed. Please see the
8 -- COPYING file in the source package for more information.
10 -- XEP-0313: Message Archive Management for Prosody
13 local st
= require
"util.stanza";
14 local jid_prep
= require
"util.jid".prep
;
15 local xmlns_mam
= "urn:xmpp:mam:2";
17 local default_attrs
= {
18 always
= true, [true] = "always",
19 never
= false, [false] = "never",
23 local function tostanza(prefs
)
24 local default
= prefs
[false];
25 default
= default_attrs
[default
];
26 local prefstanza
= st
.stanza("prefs", { xmlns
= xmlns_mam
, default
= default
});
27 local always
= st
.stanza("always");
28 local never
= st
.stanza("never");
29 for jid
, choice
in pairs(prefs
) do
31 (choice
and always
or never
):tag("jid"):text(jid
):up();
34 prefstanza
:add_child(always
):add_child(never
);
37 local function fromstanza(prefstanza
)
39 local default
= prefstanza
.attr
.default
;
41 prefs
[false] = default_attrs
[default
];
44 local always
= prefstanza
:get_child("always");
46 for rule
in always
:childtags("jid") do
47 local jid
= jid_prep(rule
:get_text());
54 local never
= prefstanza
:get_child("never");
56 for rule
in never
:childtags("jid") do
57 local jid
= jid_prep(rule
:get_text());
69 fromstanza
= fromstanza
;