changeset 2718:02d688ba7739

mod_mam_muc: Make calculation of max history length more like in mod_muc
author Kim Alvefur <zash@zash.se>
date Fri, 23 Jun 2017 13:51:23 +0200
parents 14f62b971160
children 7568157bf998
files mod_mam_muc/README.markdown mod_mam_muc/mod_mam_muc.lua
diffstat 2 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mod_mam_muc/README.markdown	Thu May 25 16:47:29 2017 +0200
+++ b/mod_mam_muc/README.markdown	Fri Jun 23 13:51:23 2017 +0200
@@ -41,11 +41,8 @@
 
 muc_log_all_rooms = false; -- set to true to force logging of all rooms
 
--- This is the largest number of messages that are allowed to be retrieved in one MAM request.
-max_archive_query_results = 20;
-
 -- This is the largest number of messages that are allowed to be retrieved when joining a room.
-max_history_messages = 1000;
+max_history_messages = 20;
 ```
 
 Compatibility
--- a/mod_mam_muc/mod_mam_muc.lua	Thu May 25 16:47:29 2017 +0200
+++ b/mod_mam_muc/mod_mam_muc.lua	Fri Jun 23 13:51:23 2017 +0200
@@ -40,8 +40,13 @@
 local time_now = os.time;
 local m_min = math.min;
 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse;
-local max_history_length = module:get_option_number("max_history_messages", 1000);
-local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", max_history_length);
+
+local default_history_length = 20;
+local max_history_length = module:get_option_number("max_history_messages", math.huge);
+
+local function get_historylength(room)
+	return math.min(room._data.history_length or default_history_length, max_history_length);
+end
 
 local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false);
 local log_by_default = module:get_option_boolean("muc_log_by_default", true);
@@ -200,7 +205,7 @@
 
 	-- RSM stuff
 	local qset = rsm.get(query);
-	local qmax = m_min(qset and qset.max or default_max_items, max_max_items);
+	local qmax = m_min(qset and qset.max or 20, 20);
 	local reverse = qset and qset.before or false;
 
 	local before, after = qset and qset.before, qset and qset.after;
@@ -285,7 +290,7 @@
 
 	-- Load all the data!
 	local query = {
-		limit = m_min(maxstanzas or 20, max_history_length);
+		limit = math.min(maxstanzas, get_historylength(room));
 		start = since;
 		reverse = true;
 		with = "message<groupchat";