Software /
code /
prosody
Comparison
plugins/mod_admin_shell.lua @ 12868:d5cb86b84d12
mod_admin_shell: Use tables to present MUC users
Tables are awesome!
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 29 Jan 2023 18:31:25 +0100 |
parent | 12867:2defb0fc2be9 |
child | 12869:70ee82579076 |
comparison
equal
deleted
inserted
replaced
12867:2defb0fc2be9 | 12868:d5cb86b84d12 |
---|---|
1399 if not room_obj then | 1399 if not room_obj then |
1400 return room_obj, err; | 1400 return room_obj, err; |
1401 end | 1401 end |
1402 | 1402 |
1403 local print = self.session.print; | 1403 local print = self.session.print; |
1404 local row = format_table({ | |
1405 { title = "Role"; width = #"participant"; key = "role" }; -- longest role name | |
1406 { title = "JID"; width = "75%"; key = "bare_jid" }; | |
1407 { title = "Nickname"; width = "25%"; key = "nick"; mapper = jid_resource }; | |
1408 }, self.session.width); | |
1404 local total, displayed = 0, 0; | 1409 local total, displayed = 0, 0; |
1405 for nick_jid, occupant in room_obj:each_occupant() do | 1410 for nick_jid, occupant in room_obj:each_occupant() do |
1411 if total == 0 then | |
1412 print(row()); | |
1413 end | |
1406 local nick = jid_resource(nick_jid); | 1414 local nick = jid_resource(nick_jid); |
1407 if filter == nil or occupant.role == filter or nick:find(filter, 1, true) then | 1415 if filter == nil or occupant.role == filter or nick:find(filter, 1, true) then |
1408 print(occupant.role, nick); | 1416 print(row(occupant)); |
1409 displayed = displayed + 1; | 1417 displayed = displayed + 1; |
1410 end | 1418 end |
1411 total = total + 1 | 1419 total = total + 1 |
1412 end | 1420 end |
1413 | 1421 |
1423 if not room_obj then | 1431 if not room_obj then |
1424 return room_obj, err; | 1432 return room_obj, err; |
1425 end | 1433 end |
1426 | 1434 |
1427 local print = self.session.print; | 1435 local print = self.session.print; |
1436 local row = format_table({ | |
1437 { title = "Affiliation"; width = #"outcast" }; -- longest affiliation name | |
1438 { title = "JID"; width = "75%" }; | |
1439 { title = "Nickname"; width = "25%"; key = "reserved_nickname" }; | |
1440 }, self.session.width); | |
1428 local total, displayed = 0, 0; | 1441 local total, displayed = 0, 0; |
1429 for affiliated_jid, affiliation, affiliation_data in room_obj:each_affiliation() do | 1442 for affiliated_jid, affiliation, affiliation_data in room_obj:each_affiliation() do |
1443 if total == 0 then | |
1444 print(row()); | |
1445 end | |
1430 if filter == nil or affiliation == filter or affiliated_jid:find(filter, 1, true) then | 1446 if filter == nil or affiliation == filter or affiliated_jid:find(filter, 1, true) then |
1431 print(affiliation, affiliated_jid, affiliation_data and affiliation_data.reserved_nickname or "") | 1447 print(row(setmetatable({ affiliation; affiliated_jid }, { __index = affiliation_data }))) |
1432 displayed = displayed + 1; | 1448 displayed = displayed + 1; |
1433 end | 1449 end |
1434 total = total + 1 | 1450 total = total + 1 |
1435 end | 1451 end |
1436 | 1452 |