Comparison

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
comparison
equal deleted inserted replaced
3874:505ae524b635 3875:93f71ab6cb00
96 end; 96 end;
97 }; 97 };
98 98
99 items = { 99 items = {
100 "func", "http://jabber.org/protocol/disco#items", "query", 100 "func", "http://jabber.org/protocol/disco#items", "query",
101 function (s) --> array of features 101 function (s) --> array of features | map with node
102 if s.attr.node and s.tags[1] == nil then
103 return { node = s.attr. node };
104 end
105
102 local items = array(); 106 local items = array();
103 for item in s:childtags("item") do 107 for item in s:childtags("item") do
104 items:push({ jid = item.attr.jid, node = item.attr.node, name = item.attr.name }); 108 items:push({ jid = item.attr.jid, node = item.attr.node, name = item.attr.name });
105 end 109 end
106 return items; 110 return items;
107 end; 111 end;
108 function (s) 112 function (s)
109 local disco = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items" });
110 if type(s) == "table" and s ~= json.null then 113 if type(s) == "table" and s ~= json.null then
114 local disco = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", node = s.node });
111 for _, item in ipairs(s) do 115 for _, item in ipairs(s) do
112 if type(item) == "string" then 116 if type(item) == "string" then
113 disco:tag("item", { jid = item }); 117 disco:tag("item", { jid = item });
114 elseif type(item) == "table" then 118 elseif type(item) == "table" then
115 disco:tag("item", { jid = item.jid, node = item.node, name = item.name }); 119 disco:tag("item", { jid = item.jid, node = item.node, name = item.name });
116 end 120 end
117 end 121 end
118 end 122 return disco;
119 return disco; 123 else
124 return st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#items", });
125 end
120 end; 126 end;
121 }; 127 };
122 128
123 -- XEP-0066: Out of Band Data 129 -- XEP-0066: Out of Band Data
124 oob_url = {"func", "jabber:iq:oob", "query", 130 oob_url = {"func", "jabber:iq:oob", "query",