Changeset

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 4675:c9397cd5cfe6
children 4677:823370bc2e4c
files mod_http_muc_log/README.markdown mod_http_muc_log/mod_http_muc_log.lua
diffstat 2 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_muc_log/README.markdown	Fri Sep 10 20:15:19 2021 +0200
+++ b/mod_http_muc_log/README.markdown	Sun Sep 12 00:13:32 2021 +0200
@@ -87,6 +87,18 @@
 http_muc_log_lazy_calendar = false
 ```
 
+## Pinned chatrooms
+
+The room list page is normally sorted by address. To override this, or
+pin certain rooms to the top:
+
+``` lua
+http_muc_log_list_order = {
+    "general@channels.example.com",
+    "support@channels.example.com",
+}
+```
+
 Compatibility
 =============
 
--- a/mod_http_muc_log/mod_http_muc_log.lua	Fri Sep 10 20:15:19 2021 +0200
+++ b/mod_http_muc_log/mod_http_muc_log.lua	Sun Sep 12 00:13:32 2021 +0200
@@ -434,6 +434,13 @@
 	});
 end
 
+local room_weights = setmetatable(module:get_option_array(module.name.."_list_order", {}):reverse(), nil);
+for i = #room_weights, 1, -1 do
+	local room_jid = room_weights[i];
+	room_weights[i] = nil;
+	room_weights[room_jid] = i;
+end
+
 local function list_rooms(event)
 	local request, response = event.request, event.response;
 	local room_list, i = {}, 1;
@@ -447,11 +454,13 @@
 				name = room:get_name() or localpart;
 				lang = room.get_language and room:get_language();
 				description = room:get_description();
+				priority = room_weights[ room.jid ] or 0;
 			}, i + 1;
 		end
 	end
 
 	table.sort(room_list, function (a, b)
+		if a.priority ~= b.priority then return a.priority > b.priority; end
 		return a.jid < b.jid;
 	end);