local st = require "util.stanza"; local datetime = require"util.datetime"; local jid_split = require"util.jid".split; local nodeprep = require"util.encodings".stringprep.nodeprep; local uuid = require"util.uuid".generate; local it = require"util.iterators"; local gettime = require"socket".gettime; local url = require"socket.url"; local xml_escape = st.xml_escape; local t_concat = table.concat; local archive = module:open_store("muc_log", "archive"); -- Support both old and new MUC code local mod_muc = module:depends"muc"; local rooms = rawget(mod_muc, "rooms"); local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end; local new_muc = not rooms; if new_muc then rooms = module:shared"muc/rooms"; end local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or function (jid) return rooms[jid]; end local function get_room(name) local jid = name .. '@' .. module.host; return get_room_from_jid(jid); end module:depends"http"; local function render(template, values) --[[ DOC {name} is substituted for values["name"] and is XML escaped {name!} is substituted without XML escaping {name?} is optional and is replaced with an empty string if no value exists {name# sub-template } renders a sub-template using an array of values ]] return (template:gsub("%b{}", function (block) local name, opt, e = block:sub(2, -2):match("([%a_][%w_]*)(%p?)()"); local value = values[name]; if opt == '#' then if not value or not value[1] then return ""; end local out, subtpl = {}, block:sub(e+1, -2); for i=1, #value do out[i] = render(subtpl, value[i]); end return t_concat(out); end if value ~= nil then if type(value) ~= "string" then value = tostring(value); end if opt ~= '!' then return xml_escape(value); end return value; elseif opt == '?' then return block:sub(e+1, -2); end end)); end -- TODO Move template into a file local template = [=[ {title}

{title}


    {lines#
  1. {nick} {verb?} {body?}
  2. }

]=]; local base_url = module:http_url() .. '/'; local get_link do local link, path = { path = '/' }, { "", "", is_directory = true }; function get_link(room, date) path[1], path[2] = room, date; path.is_directory = not date; link.path = url.build_path(path); return url.build(link); end end local function public_room(room) if type(room) == "string" then room = get_room(room); end return (room and not (room.get_hidden or room.is_hidden)(room) and not (room.get_members_only or room.is_members_only)(room) and room._data.logging == true); end -- FIXME Invent some more efficient API for this local function dates_page(event, path) local request, response = event.request, event.response; local room = nodeprep(path:match("^(.*)/$")); if not room or not public_room(room) then return end local dates, i = {}, 1; module:log("debug", "Find all dates with messages"); local next_day; repeat local iter = archive:find(room, { ["start"] = next_day; limit = 1; with = "message