Mercurial > prosody-modules
comparison mod_mam_muc/mod_mam_muc.lua @ 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 | 02a7f9fe44fa |
children | 7568157bf998 |
comparison
equal
deleted
inserted
replaced
2717:14f62b971160 | 2718:02d688ba7739 |
---|---|
38 local is_stanza = st.is_stanza; | 38 local is_stanza = st.is_stanza; |
39 local tostring = tostring; | 39 local tostring = tostring; |
40 local time_now = os.time; | 40 local time_now = os.time; |
41 local m_min = math.min; | 41 local m_min = math.min; |
42 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; | 42 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; |
43 local max_history_length = module:get_option_number("max_history_messages", 1000); | 43 |
44 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", max_history_length); | 44 local default_history_length = 20; |
45 local max_history_length = module:get_option_number("max_history_messages", math.huge); | |
46 | |
47 local function get_historylength(room) | |
48 return math.min(room._data.history_length or default_history_length, max_history_length); | |
49 end | |
45 | 50 |
46 local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false); | 51 local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false); |
47 local log_by_default = module:get_option_boolean("muc_log_by_default", true); | 52 local log_by_default = module:get_option_boolean("muc_log_by_default", true); |
48 | 53 |
49 local archive_store = "muc_log"; | 54 local archive_store = "muc_log"; |
198 qstart, qend = vstart, vend; | 203 qstart, qend = vstart, vend; |
199 end | 204 end |
200 | 205 |
201 -- RSM stuff | 206 -- RSM stuff |
202 local qset = rsm.get(query); | 207 local qset = rsm.get(query); |
203 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); | 208 local qmax = m_min(qset and qset.max or 20, 20); |
204 local reverse = qset and qset.before or false; | 209 local reverse = qset and qset.before or false; |
205 | 210 |
206 local before, after = qset and qset.before, qset and qset.after; | 211 local before, after = qset and qset.before, qset and qset.after; |
207 if type(before) ~= "string" then before = nil; end | 212 if type(before) ~= "string" then before = nil; end |
208 | 213 |
283 local since = event.since; | 288 local since = event.since; |
284 local to = event.to; | 289 local to = event.to; |
285 | 290 |
286 -- Load all the data! | 291 -- Load all the data! |
287 local query = { | 292 local query = { |
288 limit = m_min(maxstanzas or 20, max_history_length); | 293 limit = math.min(maxstanzas, get_historylength(room)); |
289 start = since; | 294 start = since; |
290 reverse = true; | 295 reverse = true; |
291 with = "message<groupchat"; | 296 with = "message<groupchat"; |
292 } | 297 } |
293 local data, err = archive:find(jid_split(room_jid), query); | 298 local data, err = archive:find(jid_split(room_jid), query); |