Comparison

plugins/mod_admin_shell.lua @ 12867:2defb0fc2be9

mod_admin_shell: Factor out room retrieval into common function Justification: See diffstat
author Kim Alvefur <zash@zash.se>
date Sun, 29 Jan 2023 17:55:56 +0100
parent 12866:54aea2622459
child 12868:d5cb86b84d12
comparison
equal deleted inserted replaced
12866:54aea2622459 12867:2defb0fc2be9
1347 return nil, "Host '"..host.."' is not a MUC service"; 1347 return nil, "Host '"..host.."' is not a MUC service";
1348 end 1348 end
1349 return room_name, host; 1349 return room_name, host;
1350 end 1350 end
1351 1351
1352 local function get_muc(room_jid)
1353 local room_name, host = check_muc(room_jid);
1354 if not room_name then
1355 return room_name, host;
1356 end
1357 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
1358 if not room_obj then
1359 return nil, "No such room: "..room_jid;
1360 end
1361 return room_obj;
1362 end
1363
1352 function def_env.muc:create(room_jid, config) 1364 function def_env.muc:create(room_jid, config)
1353 local room_name, host = check_muc(room_jid); 1365 local room_name, host = check_muc(room_jid);
1354 if not room_name then 1366 if not room_name then
1355 return room_name, host; 1367 return room_name, host;
1356 end 1368 end
1359 if prosody.hosts[host].modules.muc.get_room_from_jid(room_jid) then return nil, "Room exists already" end 1371 if prosody.hosts[host].modules.muc.get_room_from_jid(room_jid) then return nil, "Room exists already" end
1360 return prosody.hosts[host].modules.muc.create_room(room_jid, config); 1372 return prosody.hosts[host].modules.muc.create_room(room_jid, config);
1361 end 1373 end
1362 1374
1363 function def_env.muc:room(room_jid) 1375 function def_env.muc:room(room_jid)
1364 local room_name, host = check_muc(room_jid); 1376 local room_obj, err = get_muc(room_jid);
1365 if not room_name then
1366 return room_name, host;
1367 end
1368 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
1369 if not room_obj then 1377 if not room_obj then
1370 return nil, "No such room: "..room_jid; 1378 return room_obj, err;
1371 end 1379 end
1372 return setmetatable({ room = room_obj }, console_room_mt); 1380 return setmetatable({ room = room_obj }, console_room_mt);
1373 end 1381 end
1374 1382
1375 function def_env.muc:list(host) 1383 function def_env.muc:list(host)
1385 end 1393 end
1386 return true, c.." rooms"; 1394 return true, c.." rooms";
1387 end 1395 end
1388 1396
1389 function def_env.muc:occupants(room_jid, filter) 1397 function def_env.muc:occupants(room_jid, filter)
1390 local room_name, host = check_muc(room_jid); 1398 local room_obj, err = get_muc(room_jid);
1391 if not room_name then
1392 return room_name, host;
1393 end
1394 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
1395 if not room_obj then 1399 if not room_obj then
1396 return nil, "No such room: " .. room_jid; 1400 return room_obj, err;
1397 end 1401 end
1398 1402
1399 local print = self.session.print; 1403 local print = self.session.print;
1400 local total, displayed = 0, 0; 1404 local total, displayed = 0, 0;
1401 for nick_jid, occupant in room_obj:each_occupant() do 1405 for nick_jid, occupant in room_obj:each_occupant() do
1413 return true, ("%d out of %d occupant%s listed"):format(displayed, total, total ~= 1 and "s" or "") 1417 return true, ("%d out of %d occupant%s listed"):format(displayed, total, total ~= 1 and "s" or "")
1414 end 1418 end
1415 end 1419 end
1416 1420
1417 function def_env.muc:affiliations(room_jid, filter) 1421 function def_env.muc:affiliations(room_jid, filter)
1418 local room_name, host = check_muc(room_jid); 1422 local room_obj, err = get_muc(room_jid);
1419 if not room_name then
1420 return room_name, host;
1421 end
1422 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
1423 if not room_obj then 1423 if not room_obj then
1424 return nil, "No such room: " .. room_jid; 1424 return room_obj, err;
1425 end 1425 end
1426 1426
1427 local print = self.session.print; 1427 local print = self.session.print;
1428 local total, displayed = 0, 0; 1428 local total, displayed = 0, 0;
1429 for affiliated_jid, affiliation, affiliation_data in room_obj:each_affiliation() do 1429 for affiliated_jid, affiliation, affiliation_data in room_obj:each_affiliation() do