comparison mod_http_muc_log/mod_http_muc_log.lua @ 4676:a2cf3b69a3d6

mod_http_muc_log: Add way to list certain rooms in a specified order
author Kim Alvefur <zash@zash.se>
date Sun, 12 Sep 2021 00:13:32 +0200
parents 38f501dca618
children 823370bc2e4c
comparison
equal deleted inserted replaced
4675:c9397cd5cfe6 4676:a2cf3b69a3d6
432 links = links; 432 links = links;
433 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug 433 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug
434 }); 434 });
435 end 435 end
436 436
437 local room_weights = setmetatable(module:get_option_array(module.name.."_list_order", {}):reverse(), nil);
438 for i = #room_weights, 1, -1 do
439 local room_jid = room_weights[i];
440 room_weights[i] = nil;
441 room_weights[room_jid] = i;
442 end
443
437 local function list_rooms(event) 444 local function list_rooms(event)
438 local request, response = event.request, event.response; 445 local request, response = event.request, event.response;
439 local room_list, i = {}, 1; 446 local room_list, i = {}, 1;
440 for room in each_room() do 447 for room in each_room() do
441 if not (room.get_hidden or room.is_hidden)(room) then 448 if not (room.get_hidden or room.is_hidden)(room) then
445 localpart = localpart; 452 localpart = localpart;
446 href = get_link(localpart, default_view); 453 href = get_link(localpart, default_view);
447 name = room:get_name() or localpart; 454 name = room:get_name() or localpart;
448 lang = room.get_language and room:get_language(); 455 lang = room.get_language and room:get_language();
449 description = room:get_description(); 456 description = room:get_description();
457 priority = room_weights[ room.jid ] or 0;
450 }, i + 1; 458 }, i + 1;
451 end 459 end
452 end 460 end
453 461
454 table.sort(room_list, function (a, b) 462 table.sort(room_list, function (a, b)
463 if a.priority ~= b.priority then return a.priority > b.priority; end
455 return a.jid < b.jid; 464 return a.jid < b.jid;
456 end); 465 end);
457 466
458 response.headers.content_type = "text/html; charset=utf-8"; 467 response.headers.content_type = "text/html; charset=utf-8";
459 return render(template, { 468 return render(template, {