comparison mod_http_admin_api/mod_http_admin_api.lua @ 4390:17d44ba8fde2

mod_http_admin_api: support for creating groups with MUCs
author Jonas Schäfer <jonas@wielicki.name>
date Tue, 26 Jan 2021 15:37:28 +0100
parents 0d6b69777bc1
children ae1d1e352504
comparison
equal deleted inserted replaced
4389:6cfa313cd524 4390:17d44ba8fde2
401 for group_id in mod_groups.groups() do 401 for group_id in mod_groups.groups() do
402 local group_info = mod_groups.get_info(group_id); 402 local group_info = mod_groups.get_info(group_id);
403 table.insert(group_list, { 403 table.insert(group_list, {
404 id = group_id; 404 id = group_id;
405 name = group_info.name; 405 name = group_info.name;
406 muc_jid = group_info.muc_jid;
406 members = mod_groups.get_members(group_id); 407 members = mod_groups.get_members(group_id);
407 }); 408 });
408 end 409 end
409 410
410 event.response.headers["Content-Type"] = json_content_type; 411 event.response.headers["Content-Type"] = json_content_type;
420 event.response.headers["Content-Type"] = json_content_type; 421 event.response.headers["Content-Type"] = json_content_type;
421 422
422 return json.encode({ 423 return json.encode({
423 id = group_id; 424 id = group_id;
424 name = group.name; 425 name = group.name;
426 muc_jid = group.muc_jid;
425 members = mod_groups.get_members(group_id); 427 members = mod_groups.get_members(group_id);
426 }); 428 });
427 end 429 end
428 430
429 function create_group(event) 431 function create_group(event)
440 if not group.name then 442 if not group.name then
441 module:log("warn", "Group missing name property"); 443 module:log("warn", "Group missing name property");
442 return 400; 444 return 400;
443 end 445 end
444 446
445 local group_id = mod_groups.create({ 447 local create_muc = group.create_muc and true or false;
446 name = group.name; 448
447 }); 449 local group_id = mod_groups.create(
450 {
451 name = group.name;
452 },
453 create_muc
454 );
448 if not group_id then 455 if not group_id then
449 return 500; 456 return 500;
450 end 457 end
451 458
452 event.response.headers["Content-Type"] = json_content_type; 459 event.response.headers["Content-Type"] = json_content_type;
460
461 local info = mod_groups.get_info(group_id);
453 return json.encode({ 462 return json.encode({
454 id = group_id; 463 id = group_id;
455 name = group.name; 464 name = info.name;
465 muc_jid = info.muc_jid or nil;
456 members = {}; 466 members = {};
457 }); 467 });
458 end 468 end
459 469
460 function update_group(event, group) --luacheck: ignore 212/event 470 function update_group(event, group) --luacheck: ignore 212/event