Comparison

util/adhoc.lua @ 10667:49312378ba1d

util.adhoc: Allow passing dataforms in initial command This might not be quite legal per XEP-0050, but makes it possible to call simpler commands without keeping state across another roundtrip.
author Kim Alvefur <zash@zash.se>
date Wed, 26 Feb 2020 00:59:35 +0100
parent 8382:e5d00bf4a4d5
child 11352:e10567199f02
comparison
equal deleted inserted replaced
10666:dfc8257d8445 10667:49312378ba1d
1 -- luacheck: ignore 212/self 1 -- luacheck: ignore 212/self
2 2
3 local function new_simple_form(form, result_handler) 3 local function new_simple_form(form, result_handler)
4 return function(self, data, state) 4 return function(self, data, state)
5 if state then 5 if state or data.form then
6 if data.action == "cancel" then 6 if data.action == "cancel" then
7 return { status = "canceled" }; 7 return { status = "canceled" };
8 end 8 end
9 local fields, err = form:data(data.form); 9 local fields, err = form:data(data.form);
10 return result_handler(fields, err, data); 10 return result_handler(fields, err, data);
14 end 14 end
15 end 15 end
16 16
17 local function new_initial_data_form(form, initial_data, result_handler) 17 local function new_initial_data_form(form, initial_data, result_handler)
18 return function(self, data, state) 18 return function(self, data, state)
19 if state then 19 if state or data.form then
20 if data.action == "cancel" then 20 if data.action == "cancel" then
21 return { status = "canceled" }; 21 return { status = "canceled" };
22 end 22 end
23 local fields, err = form:data(data.form); 23 local fields, err = form:data(data.form);
24 return result_handler(fields, err, data); 24 return result_handler(fields, err, data);