# HG changeset patch # User Kim Alvefur # Date 1428423160 -7200 # Node ID 1a6d6221c5f619167a42cb7ec64ec9cde4eaa55c # Parent 1fe899527ee5c66ee474eb7379521ffd48874b32 mod_http_muc_log: Cleanup [luacheck] diff -r 1fe899527ee5 -r 1a6d6221c5f6 mod_http_muc_log/mod_http_muc_log.lua --- a/mod_http_muc_log/mod_http_muc_log.lua Tue Apr 07 17:35:37 2015 +0200 +++ b/mod_http_muc_log/mod_http_muc_log.lua Tue Apr 07 18:12:40 2015 +0200 @@ -72,7 +72,7 @@ end)); end -local template = "Could not load template" +local template; do local template_file = module:get_option_string(module.name .. "_template", module.name .. ".html"); template_file = assert(module:load_resource(template_file)); @@ -80,7 +80,7 @@ template_file:close(); end -local base_url = module:http_url() .. '/'; +-- local base_url = module:http_url() .. '/'; -- TODO: Generate links in a smart way local get_link do local link, path = { path = '/' }, { "", "", is_directory = true }; function get_link(room, date) @@ -109,67 +109,63 @@ return os_time(t) + t_diff; end +local function find_once(room, query, retval) + if query then query.limit = 1; else query = { limit = 1 }; end + local iter, err = archive:find(room, query); + if not iter then return iter, err; end + if retval then + return select(retval, iter()); + end + return iter(); +end + local function years_page(event, path) - local request, response = event.request, event.response; + local response = event.response; local room = nodeprep(path:match("^(.*)/$")); if not room or not public_room(room) then return end local dates = mt.new(); module:log("debug", "Find all dates with messages"); - local next_day, t; + local next_day; repeat - local iter = archive:find(room, { - start = next_day; - limit = 1; - with = "message 1 and tmp.wday == 2 then days = {}; weeks[#weeks+1] = { days = days }; - n = 1; + current_day = 1; end - days[n], n = { wday = tmp.wday, day = i, href = d[i] and datetime.date(d[i]) }, n+1; + days[current_day], current_day = { wday = tmp.wday, day = i, href = days_t[i] and datetime.date(days_t[i]) }, current_day+1; end end table.sort(year, sort_m); @@ -188,7 +184,7 @@ end local function logs_page(event, path) - local request, response = event.request, event.response; + local response = event.response; local room, date = path:match("^(.-)/(%d%d%d%d%-%d%d%-%d%d)$"); room = nodeprep(room); @@ -203,7 +199,10 @@ ["end"] = datetime.parse(date.."T23:59:59Z"); -- with = "message