Software /
code /
prosody-modules
Changeset
4743:0a501df823fd
mod_rest: Add some convenience mapping to make MAM queries easier
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 04 Nov 2021 20:04:13 +0100 |
parents | 4742:b7df2c61a144 |
children | 4744:f478855f4565 |
files | mod_rest/jsonmap.lib.lua |
diffstat | 1 files changed, 34 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_rest/jsonmap.lib.lua Thu Nov 04 20:03:36 2021 +0100 +++ b/mod_rest/jsonmap.lib.lua Thu Nov 04 20:04:13 2021 +0100 @@ -384,6 +384,7 @@ ping = "iq", version = "iq", command = "iq", + archive = "iq", body = "message", html = "message", @@ -496,6 +497,39 @@ t_type = "get"; end + -- XEP-0313 conveninece mapping + if kind == "iq" and t_type == "set" and type(t.archive) == "table" and not t.archive.form then + local archive = t.archive; + if archive["with"] or archive["start"] or archive["end"] or archive["before-id"] or archive["after-id"] + or archive["ids"] then + archive.form = { + type = "submit"; + fields = { + { var = "FORM_TYPE"; values = { "urn:xmpp:mam:2" } }; + { var = "with"; values = { archive["with"] } }; + { var = "start"; values = { archive["start"] } }; + { var = "end"; values = { archive["end"] } }; + { var = "before-id"; values = { archive["before-id"] } }; + { var = "after-id"; values = { archive["after-id"] } }; + { var = "ids"; values = archive["ids"] }; + }; + }; + archive["with"] = nil; + archive["start"] = nil; + archive["end"] = nil; + archive["before-id"] = nil; + archive["after-id"] = nil; + archive["ids"] = nil; + end + + if archive["after"] or archive["before"] or archive["max"] then + archive.page = { after = archive["after"]; before = archive["before"]; max = tonumber(archive["max"]) } + archive["after"] = nil; + archive["before"] = nil; + archive["max"] = nil; + end + end + local s = map.unparse(schema.properties[kind or "message"], t); s.attr.type = t_type;