# HG changeset patch # User Kim Alvefur # Date 1614373525 -3600 # Node ID 3b50a9a75fb65c9f7588e12b24f0dc2e0bcbed06 # Parent f210f242cf17aad71485f1156393aa6be30de226 mod_rest: Roundtrip disco and items when string or boolean is used E.g. {disco:true} turns to and back to {disco:true}, same with {items:true}. Similarily, {disco:"node"}, {items:"node"} turn into and back. diff -r f210f242cf17 -r 3b50a9a75fb6 mod_rest/jsonmap.lib.lua --- a/mod_rest/jsonmap.lib.lua Wed Feb 24 18:46:20 2021 +0100 +++ b/mod_rest/jsonmap.lib.lua Fri Feb 26 22:05:25 2021 +0100 @@ -76,6 +76,9 @@ disco = { type = "func", xmlns = "http://jabber.org/protocol/disco#info", tagname = "query", st2json = function (s) --> array of features + if s.tags[1] == nil then + return s.attr.node or true; + end local identities, features, extensions = array(), array(), {}; for tag in s:childtags() do if tag.name == "identity" and tag.attr.category and tag.attr.type then @@ -115,6 +118,8 @@ end end return disco; + elseif type(s) == "string" then + return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info", node = s }); else return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info", }); end @@ -124,8 +129,8 @@ items = { type = "func", xmlns = "http://jabber.org/protocol/disco#items", tagname = "query", st2json = function (s) --> array of features | map with node - if s.attr.node and s.tags[1] == nil then - return { node = s.attr.node }; + if s.tags[1] == nil then + return s.attr.node or true; end local items = array(); @@ -145,6 +150,8 @@ end end return disco; + elseif type(s) == "string" then + return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", node = s }); else return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", }); end