# HG changeset patch # User Kim Alvefur # Date 1468010430 -7200 # Node ID 86bc6e1d9d4dc5e0d432c6c80d8c665048946de5 # Parent c5ee48e27d01b077aa3cf3a38c8a2f8a548b1ce5 mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver diff -r c5ee48e27d01 -r 86bc6e1d9d4d mod_http_muc_log/mod_http_muc_log.lua --- a/mod_http_muc_log/mod_http_muc_log.lua Fri Jul 08 22:39:41 2016 +0200 +++ b/mod_http_muc_log/mod_http_muc_log.lua Fri Jul 08 22:40:30 2016 +0200 @@ -201,22 +201,35 @@ end if i == 1 then return end -- No items - module:log("debug", "Find next date with messages"); - local next_when = find_once(room, { after = last }, 3); - if next_when then - next_when = datetime.date(next_when); - module:log("debug", "Next message: %s", next_when); + local next_when, prev_when = "", ""; + local date_list = archive.dates and archive:dates(room); + if date_list then + for i = 1, #date_list do + if date_list[i] == date then + next_when = date_list[i+1] or ""; + prev_when = date_list[i-1] or ""; + break; + end + end else - next_when = ""; - end - module:log("debug", "Find prev date with messages"); - local prev_when = find_once(room, { before = first, reverse = true }, 3); - if prev_when then - prev_when = datetime.date(prev_when); - module:log("debug", "Previous message: %s", prev_when); - else - prev_when = ""; + module:log("debug", "Find next date with messages"); + local next_when = find_once(room, { after = last }, 3); + if next_when then + next_when = datetime.date(next_when); + module:log("debug", "Next message: %s", next_when); + else + next_when = ""; + end + + module:log("debug", "Find prev date with messages"); + local prev_when = find_once(room, { before = first, reverse = true }, 3); + if prev_when then + prev_when = datetime.date(prev_when); + module:log("debug", "Previous message: %s", prev_when); + else + prev_when = ""; + end end response.headers.content_type = "text/html; charset=utf-8";