Mercurial > prosody-modules
changeset 4021:1925d63eec6b
mod_rest/jsonmap: Derive stanza @type from certain payloads
Because I forget type=set every single time with ad-hoc commands.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 16 May 2020 18:30:01 +0200 |
parents | 4b47c8eeca22 |
children | 3ac31ddab7eb |
files | mod_rest/jsonmap.lib.lua |
diffstat | 1 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_rest/jsonmap.lib.lua Thu May 14 17:28:38 2020 +0200 +++ b/mod_rest/jsonmap.lib.lua Sat May 16 18:30:01 2020 +0200 @@ -425,6 +425,10 @@ status = "presence", } +local implied_types = { + command = "set", +} + local kind_by_type = { get = "iq", set = "iq", result = "iq", normal = "message", chat = "message", headline = "message", groupchat = "message", @@ -507,7 +511,15 @@ if type(t) ~= "table" or not str(next(t)) then return nil, "invalid-json"; end - local kind = str(t.kind) or kind_by_type[str(t.type)]; + local t_type = str(t.type); + if t_type == nil then + for k, implied in pairs(implied_types) do + if t[k] then + t_type = implied; + end + end + end + local kind = str(t.kind) or kind_by_type[t_type]; if not kind then for k, implied in pairs(implied_kinds) do if t[k] then @@ -517,8 +529,12 @@ end end + if t_type == "available" then + t_type = nil; + end + local s = st.stanza(kind or "message", { - type = t.type ~= "available" and str(t.type) or nil, + type = t_type; to = str(t.to) and jid.prep(t.to); from = str(t.to) and jid.prep(t.from); id = str(t.id),