Comparison

mod_http_admin_api/mod_http_admin_api.lua @ 4366:83370df0ce4a

mod_http_admin_api: do not report OMEMO as ok if no devices exist
author Jonas Schäfer <jonas@wielicki.name>
date Thu, 21 Jan 2021 16:18:14 +0100
parent 4365:f975a4d31f35
child 4368:e0c8d866d58c
comparison
equal deleted inserted replaced
4365:f975a4d31f35 4366:83370df0ce4a
200 return info; 200 return info;
201 end 201 end
202 202
203 local function get_user_omemo_info(username) 203 local function get_user_omemo_info(username)
204 local everything_valid = true; 204 local everything_valid = true;
205 local any_device = false;
205 local omemo_status = {}; 206 local omemo_status = {};
206 local omemo_devices; 207 local omemo_devices;
207 local pep_service = mod_pep.get_pep_service(username); 208 local pep_service = mod_pep.get_pep_service(username);
208 if pep_service and pep_service.nodes then 209 if pep_service and pep_service.nodes then
209 local ok, _, device_list = pep_service:get_last_item("eu.siacs.conversations.axolotl.devicelist", true); 210 local ok, _, device_list = pep_service:get_last_item("eu.siacs.conversations.axolotl.devicelist", true);
211 device_list = device_list:get_child("list", "eu.siacs.conversations.axolotl"); 212 device_list = device_list:get_child("list", "eu.siacs.conversations.axolotl");
212 end 213 end
213 if device_list then 214 if device_list then
214 omemo_devices = {}; 215 omemo_devices = {};
215 for device_entry in device_list:childtags("device") do 216 for device_entry in device_list:childtags("device") do
217 any_device = true;
216 local device_info = {}; 218 local device_info = {};
217 local device_id = tonumber(device_entry.attr.id or ""); 219 local device_id = tonumber(device_entry.attr.id or "");
218 if device_id then 220 if device_id then
219 device_info.id = device_id; 221 device_info.id = device_id;
220 local bundle_id = ("eu.siacs.conversations.axolotl.bundles:%d"):format(device_id); 222 local bundle_id = ("eu.siacs.conversations.axolotl.bundles:%d"):format(device_id);
254 omemo_status.config_valid = false; 256 omemo_status.config_valid = false;
255 everything_valid = false; 257 everything_valid = false;
256 end 258 end
257 end 259 end
258 end 260 end
259 omemo_status.valid = everything_valid; 261 omemo_status.valid = everything_valid and any_device;
260 return { 262 return {
261 status = omemo_status; 263 status = omemo_status;
262 devices = omemo_devices; 264 devices = omemo_devices;
263 }; 265 };
264 end 266 end