Changeset

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
parents 3874:505ae524b635
children 3876:75b330d4fa6f
files mod_rest/jsonmap.lib.lua
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
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;
 	};