From 0ff95b16160d80de3a43be87353ce30e58c86ec1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 4 Nov 2016 13:48:21 +0100 Subject: mod_mam: Import from prosody-modules --- plugins/mod_mam/mamprefsxml.lib.lua | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 plugins/mod_mam/mamprefsxml.lib.lua (limited to 'plugins/mod_mam/mamprefsxml.lib.lua') diff --git a/plugins/mod_mam/mamprefsxml.lib.lua b/plugins/mod_mam/mamprefsxml.lib.lua new file mode 100644 index 00000000..a0d46245 --- /dev/null +++ b/plugins/mod_mam/mamprefsxml.lib.lua @@ -0,0 +1,58 @@ +-- XEP-0313: Message Archive Management for Prosody +-- Copyright (C) 2011-2013 Kim Alvefur +-- +-- This file is MIT/X11 licensed. + +local st = require"util.stanza"; +local xmlns_mam = "urn:xmpp:mam:0"; + +local default_attrs = { + always = true, [true] = "always", + never = false, [false] = "never", + roster = "roster", +} + +local function tostanza(prefs) + local default = prefs[false]; + default = default_attrs[default]; + local prefstanza = st.stanza("prefs", { xmlns = xmlns_mam, default = default }); + local always = st.stanza("always"); + local never = st.stanza("never"); + for jid, choice in pairs(prefs) do + if jid then + (choice and always or never):tag("jid"):text(jid):up(); + end + end + prefstanza:add_child(always):add_child(never); + return prefstanza; +end +local function fromstanza(prefstanza) + local prefs = {}; + local default = prefstanza.attr.default; + if default then + prefs[false] = default_attrs[default]; + end + + local always = prefstanza:get_child("always"); + if always then + for rule in always:childtags("jid") do + local jid = rule:get_text(); + prefs[jid] = true; + end + end + + local never = prefstanza:get_child("never"); + if never then + for rule in never:childtags("jid") do + local jid = rule:get_text(); + prefs[jid] = false; + end + end + + return prefs; +end + +return { + tostanza = tostanza; + fromstanza = fromstanza; +} -- cgit v1.2.3 From 58cc91cd454783208c1b3a4b73d9f54808b4aef6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 4 Nov 2016 13:59:49 +0100 Subject: mod_mam: Update to XEP-0313 v0.5.1 --- plugins/mod_mam/mamprefsxml.lib.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_mam/mamprefsxml.lib.lua') diff --git a/plugins/mod_mam/mamprefsxml.lib.lua b/plugins/mod_mam/mamprefsxml.lib.lua index a0d46245..ec728e55 100644 --- a/plugins/mod_mam/mamprefsxml.lib.lua +++ b/plugins/mod_mam/mamprefsxml.lib.lua @@ -4,7 +4,7 @@ -- This file is MIT/X11 licensed. local st = require"util.stanza"; -local xmlns_mam = "urn:xmpp:mam:0"; +local xmlns_mam = "urn:xmpp:mam:1"; local default_attrs = { always = true, [true] = "always", -- cgit v1.2.3 From fcd827853a8dcda866ce6fda71424582238fd57f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 23 Jan 2017 19:18:15 +0100 Subject: mod_mam: Normalize copyright headers --- plugins/mod_mam/mamprefsxml.lib.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'plugins/mod_mam/mamprefsxml.lib.lua') diff --git a/plugins/mod_mam/mamprefsxml.lib.lua b/plugins/mod_mam/mamprefsxml.lib.lua index ec728e55..0598bbcd 100644 --- a/plugins/mod_mam/mamprefsxml.lib.lua +++ b/plugins/mod_mam/mamprefsxml.lib.lua @@ -1,7 +1,13 @@ +-- Prosody IM +-- Copyright (C) 2008-2017 Matthew Wild +-- Copyright (C) 2008-2017 Waqas Hussain +-- Copyright (C) 2011-2017 Kim Alvefur +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- -- XEP-0313: Message Archive Management for Prosody --- Copyright (C) 2011-2013 Kim Alvefur -- --- This file is MIT/X11 licensed. local st = require"util.stanza"; local xmlns_mam = "urn:xmpp:mam:1"; -- cgit v1.2.3