Diff

mod_rest/jsonmap.lib.lua @ 3875:93f71ab6cb00

mod_rest: Support passing 'node' attr in disco#items queries But only in queries. Should be fine if you can't include it in responses since the requester should remember what node they asked for.
author Kim Alvefur <zash@zash.se>
date Tue, 04 Feb 2020 21:04:02 +0100
parent 3871:e5d08bb58155
child 3877:562b34050561
line wrap: on
line diff
--- a/mod_rest/jsonmap.lib.lua	Tue Feb 04 20:20:08 2020 +0100
+++ b/mod_rest/jsonmap.lib.lua	Tue Feb 04 21:04:02 2020 +0100
@@ -98,7 +98,11 @@
 
 	items = {
 		"func", "http://jabber.org/protocol/disco#items", "query",
-		function (s) --> array of features
+		function (s) --> array of features | map with node
+			if s.attr.node and s.tags[1] == nil then
+				return { node = s.attr. node };
+			end
+
 			local items = array();
 			for item in s:childtags("item") do
 				items:push({ jid = item.attr.jid, node = item.attr.node, name = item.attr.name });
@@ -106,8 +110,8 @@
 			return items;
 		end;
 		function  (s)
-			local disco = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items" });
 			if type(s) == "table" and s ~= json.null then
+				local disco = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", node = s.node });
 				for _, item in ipairs(s) do
 					if type(item) == "string" then
 						disco:tag("item", { jid = item });
@@ -115,8 +119,10 @@
 						disco:tag("item", { jid = item.jid, node = item.node, name = item.name });
 					end
 				end
+				return disco;
+			else
+				return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", });
 			end
-			return disco;
 		end;
 	};