Diff

mod_rest/jsonmap.lib.lua @ 4473:3b50a9a75fb6

mod_rest: Roundtrip disco and items when string or boolean is used E.g. {disco:true} turns to <query/> and back to {disco:true}, same with {items:true}. Similarily, {disco:"node"}, {items:"node"} turn into <query node="node"/> and back.
author Kim Alvefur <zash@zash.se>
date Fri, 26 Feb 2021 22:05:25 +0100
parent 4372:78de3c7acf58
child 4499:8e644bf36627
line wrap: on
line diff
--- 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