annotate mod_http_muc_log/mod_http_muc_log.lua @ 2838:5125e187768f

mod_http_muc_log: Remove this one weird whitespace
author Kim Alvefur <zash@zash.se>
date Sat, 18 Nov 2017 20:42:18 +0100
parents bd5eb429ebab
children 7738d7158dd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
1 local mt = require"util.multitable";
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local datetime = require"util.datetime";
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local jid_split = require"util.jid".split;
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local nodeprep = require"util.encodings".stringprep.nodeprep;
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local it = require"util.iterators";
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
6 local url = require"socket.url";
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
7 local os_time, os_date = os.time, os.date;
1750
3b839db88412 mod_http_muc_log: Template engine thing moved into util.interpolation
Kim Alvefur <zash@zash.se>
parents: 1671
diff changeset
8 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape);
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
1571
eed7db9f3157 mod_mam_muc, mod_http_muc_log: Change store name from 'archive2' to 'muc_log' to distinguish it from personal MAM archives. Old data will require migration.
Kim Alvefur <zash@zash.se>
parents: 1564
diff changeset
10 local archive = module:open_store("muc_log", "archive");
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 -- Support both old and new MUC code
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local mod_muc = module:depends"muc";
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local rooms = rawget(mod_muc, "rooms");
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end;
1554
8059b7cdaf17 mod_http_muc_log: Make MUC local code identical to mod_mam_muc
Kim Alvefur <zash@zash.se>
parents: 1553
diff changeset
16 local new_muc = not rooms;
8059b7cdaf17 mod_http_muc_log: Make MUC local code identical to mod_mam_muc
Kim Alvefur <zash@zash.se>
parents: 1553
diff changeset
17 if new_muc then
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 rooms = module:shared"muc/rooms";
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 function (jid)
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 return rooms[jid];
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 local function get_room(name)
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local jid = name .. '@' .. module.host;
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 return get_room_from_jid(jid);
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 module:depends"http";
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
32 local template;
1582
8e282eb0c70c mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents: 1581
diff changeset
33 do
8e282eb0c70c mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents: 1581
diff changeset
34 local template_file = module:get_option_string(module.name .. "_template", module.name .. ".html");
8e282eb0c70c mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents: 1581
diff changeset
35 template_file = assert(module:load_resource(template_file));
8e282eb0c70c mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents: 1581
diff changeset
36 template = template_file:read("*a");
8e282eb0c70c mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents: 1581
diff changeset
37 template_file:close();
8e282eb0c70c mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents: 1581
diff changeset
38 end
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
40 -- local base_url = module:http_url() .. '/'; -- TODO: Generate links in a smart way
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
41 local get_link do
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
42 local link, path = { path = '/' }, { "", "", is_directory = true };
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
43 function get_link(room, date)
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
44 path[1], path[2] = room, date;
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
45 path.is_directory = not date;
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
46 link.path = url.build_path(path);
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
47 return url.build(link);
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
48 end
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
49 end
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
51 local function public_room(room) -- : boolean
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 if type(room) == "string" then
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 room = get_room(room);
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 end
1575
464ed6bc5a73 mod_http_muc_log: Fix use with old (until 0.10) MUC API
Kim Alvefur <zash@zash.se>
parents: 1571
diff changeset
55 return (room
464ed6bc5a73 mod_http_muc_log: Fix use with old (until 0.10) MUC API
Kim Alvefur <zash@zash.se>
parents: 1571
diff changeset
56 and not (room.get_hidden or room.is_hidden)(room)
2763
a6d19aea9b73 mod_http_muc_log: Ignore 'logging' room option, it's no longer set by mod_mam_muc
Kim Alvefur <zash@zash.se>
parents: 2685
diff changeset
57 and not (room.get_members_only or room.is_members_only)(room))
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
60 local function sort_Y(a,b) return a.year > b.year end
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
61 local function sort_m(a,b) return a.n > b.n end
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
62
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
63 -- Time zone hack?
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
64 local t_diff = os_time(os_date("*t")) - os_time(os_date("!*t"));
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
65 local function time(t)
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
66 return os_time(t) + t_diff;
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
67 end
2836
52a7c0f6aea1 mod_http_muc_log: Add a function for rounding timestamps down to midnight
Kim Alvefur <zash@zash.se>
parents: 2826
diff changeset
68 local function date_floor(t)
52a7c0f6aea1 mod_http_muc_log: Add a function for rounding timestamps down to midnight
Kim Alvefur <zash@zash.se>
parents: 2826
diff changeset
69 return t - t % 86400;
52a7c0f6aea1 mod_http_muc_log: Add a function for rounding timestamps down to midnight
Kim Alvefur <zash@zash.se>
parents: 2826
diff changeset
70 end
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
71
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
72 -- Fetch one item
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
73 local function find_once(room, query, retval)
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
74 if query then query.limit = 1; else query = { limit = 1 }; end
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
75 local iter, err = archive:find(room, query);
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
76 if not iter then return iter, err; end
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
77 if retval then
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
78 return select(retval, iter());
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
79 end
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
80 return iter();
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
81 end
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
82
2826
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
83 local lazy = module:get_option_boolean(module.name .. "_lazy_calendar", true);
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
84
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
85 -- Produce the calendar view
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
86 local function years_page(event, path)
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
87 local response = event.response;
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88
1552
81b3599c02fb mod_http_muc_log: Have URL of date list page end with a slash
Kim Alvefur <zash@zash.se>
parents: 1550
diff changeset
89 local room = nodeprep(path:match("^(.*)/$"));
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 if not room or not public_room(room) then return end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
92 -- Collect each date that has messages
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
93 -- convert it to a year / month / day tree
1832
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
94 local date_list = archive.dates and archive:dates(room);
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
95 local dates = mt.new();
1832
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
96 if date_list then
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
97 for _, date in ipairs(date_list) do
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
98 local when = datetime.parse(date.."T00:00:00Z");
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
99 local t = os_date("!*t", when);
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
100 dates:set(t.year, t.month, t.day, when);
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
101 end
2826
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
102 elseif lazy then
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
103 -- Lazy with many false positives
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
104 local first_day = find_once(room, nil, 3);
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
105 local last_day = find_once(room, { reverse = true }, 3);
2837
bd5eb429ebab mod_http_muc_log: Round down timestamps to midnight in order to fix an off by one issue (thanks asterix)
Kim Alvefur <zash@zash.se>
parents: 2836
diff changeset
106 first_day = date_floor(first_day);
bd5eb429ebab mod_http_muc_log: Round down timestamps to midnight in order to fix an off by one issue (thanks asterix)
Kim Alvefur <zash@zash.se>
parents: 2836
diff changeset
107 last_day = date_floor(last_day);
2826
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
108 for when = first_day, last_day, 86400 do
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
109 local t = os_date("!*t", when);
2838
5125e187768f mod_http_muc_log: Remove this one weird whitespace
Kim Alvefur <zash@zash.se>
parents: 2837
diff changeset
110 dates:set(t.year, t.month, t.day, when);
2826
ed26608920d4 mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents: 2763
diff changeset
111 end
1832
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
112 else
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
113 -- Collect date the hard way
1832
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
114 module:log("debug", "Find all dates with messages");
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
115 local next_day;
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
116 repeat
2235
c5ee48e27d01 mod_http_muc_log: Link to next day with content, regardless of type (simplifes)
Kim Alvefur <zash@zash.se>
parents: 1832
diff changeset
117 local when = find_once(room, { start = next_day; }, 3);
1832
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
118 if not when then break; end
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
119 local t = os_date("!*t", when);
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
120 dates:set(t.year, t.month, t.day, when );
2836
52a7c0f6aea1 mod_http_muc_log: Add a function for rounding timestamps down to midnight
Kim Alvefur <zash@zash.se>
parents: 2826
diff changeset
121 next_day = date_floor(when) + 86400;
1832
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
122 until not next_day;
48125f2c358b mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents: 1750
diff changeset
123 end
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
124
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
125 local years = {};
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
126
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
127 -- Wrangle Y/m/d tree into year / month / week / day tree for calendar view
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
128 for current_year, months_t in pairs(dates.data) do
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
129 local t = { year = current_year, month = 1, day = 1 };
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
130 local months = { };
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
131 local year = { year = current_year, months = months };
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
132 years[#years+1] = year;
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
133 for current_month, days_t in pairs(months_t) do
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
134 t.day = 1;
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
135 t.month = current_month;
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
136 local tmp = os_date("!*t", time(t));
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
137 local days = {};
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
138 local week = { days = days }
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
139 local weeks = { week };
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
140 local month = { year = year.year, month = os_date("!%B", time(t)), n = current_month, weeks = weeks };
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
141 months[#months+1] = month;
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
142 local current_day = 1;
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
143 for _=1, (tmp.wday+5)%7 do
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
144 days[current_day], current_day = {}, current_day+1;
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
145 end
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
146 for i = 1, 31 do
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
147 t.day = i;
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
148 tmp = os_date("!*t", time(t));
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
149 if tmp.month ~= current_month then break end
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
150 if i > 1 and tmp.wday == 2 then
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
151 days = {};
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
152 weeks[#weeks+1] = { days = days };
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
153 current_day = 1;
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
154 end
2685
cd5781ca782d mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents: 2593
diff changeset
155 days[current_day] = {
cd5781ca782d mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents: 2593
diff changeset
156 wday = tmp.wday, day = i, href = days_t[i] and datetime.date(days_t[i])
cd5781ca782d mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents: 2593
diff changeset
157 };
cd5781ca782d mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents: 2593
diff changeset
158 current_day = current_day+1;
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
159 end
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
160 end
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
161 table.sort(year, sort_m);
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
162 end
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
163 table.sort(years, sort_Y);
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
165 -- Phew, all wrangled, all that's left is rendering it with the template
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
166
1579
9e784ddac236 mod_http_muc_log: Include charset in Content-Type header
Kim Alvefur <zash@zash.se>
parents: 1578
diff changeset
167 response.headers.content_type = "text/html; charset=utf-8";
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
168 return render(template, {
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
169 title = get_room(room):get_name();
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
170 jid = get_room(room).jid;
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
171 years = years;
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
172 links = {
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
173 { href = "../", rel = "up", text = "Back to room list" },
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
174 };
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
175 });
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
178 -- Produce the chat log view
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 local function logs_page(event, path)
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
180 local response = event.response;
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181
2590
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
182 -- FIXME In the year, 252525, if MUC is still alive,
63dd3e525f13 mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents: 2236
diff changeset
183 -- if Prosody can survive... Enjoy this Y10k bug
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 local room, date = path:match("^(.-)/(%d%d%d%d%-%d%d%-%d%d)$");
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 room = nodeprep(room);
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 if not room then
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
187 return years_page(event, path);
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
188 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189 if not public_room(room) then return end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191 local logs, i = {}, 1;
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
192 local iter, err = archive:find(room, {
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
193 ["start"] = datetime.parse(date.."T00:00:00Z");
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194 ["end"] = datetime.parse(date.."T23:59:59Z");
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195 });
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
196 if not iter then
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
197 module:log("warn", "Could not search archive: %s", err or "no error");
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
198 return 500;
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
199 end
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200
1577
0a6974f2cb55 mod_http_muc_log: Use archive IDs to find next and previous dates that contain messages
Kim Alvefur <zash@zash.se>
parents: 1576
diff changeset
201 local first, last;
1555
2e51f70cd7ea mod_http_muc_log: Make pretty
Kim Alvefur <zash@zash.se>
parents: 1554
diff changeset
202 for key, item, when in iter do
2591
3e1a85c5194c mod_http_muc_log: Move scope of variables into loop
Kim Alvefur <zash@zash.se>
parents: 2590
diff changeset
203 local body = item:get_child_text("body");
3e1a85c5194c mod_http_muc_log: Move scope of variables into loop
Kim Alvefur <zash@zash.se>
parents: 2590
diff changeset
204 local subject = item:get_child_text("subject");
3e1a85c5194c mod_http_muc_log: Move scope of variables into loop
Kim Alvefur <zash@zash.se>
parents: 2590
diff changeset
205 local verb = nil;
1555
2e51f70cd7ea mod_http_muc_log: Make pretty
Kim Alvefur <zash@zash.se>
parents: 1554
diff changeset
206 if subject then
1578
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
207 verb, body = "set the topic to", subject;
1555
2e51f70cd7ea mod_http_muc_log: Make pretty
Kim Alvefur <zash@zash.se>
parents: 1554
diff changeset
208 elseif body and body:sub(1,4) == "/me " then
2e51f70cd7ea mod_http_muc_log: Make pretty
Kim Alvefur <zash@zash.se>
parents: 1554
diff changeset
209 verb, body = body:sub(5), nil;
2e51f70cd7ea mod_http_muc_log: Make pretty
Kim Alvefur <zash@zash.se>
parents: 1554
diff changeset
210 elseif item.name == "presence" then
2e51f70cd7ea mod_http_muc_log: Make pretty
Kim Alvefur <zash@zash.se>
parents: 1554
diff changeset
211 verb = item.attr.type == "unavailable" and "has left" or "has joined";
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
212 end
1578
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
213 if body or verb then
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
214 logs[i], i = {
1578
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
215 key = key;
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
216 datetime = datetime.datetime(when);
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
217 time = datetime.time(when);
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
218 verb = verb;
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
219 body = body;
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
220 nick = select(3, jid_split(item.attr.from));
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
221 st_name = item.name;
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
222 st_type = item.attr.type;
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
223 }, i + 1;
a68ec7a2dc02 mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents: 1577
diff changeset
224 end
1577
0a6974f2cb55 mod_http_muc_log: Use archive IDs to find next and previous dates that contain messages
Kim Alvefur <zash@zash.se>
parents: 1576
diff changeset
225 first = first or key;
0a6974f2cb55 mod_http_muc_log: Use archive IDs to find next and previous dates that contain messages
Kim Alvefur <zash@zash.se>
parents: 1576
diff changeset
226 last = key;
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
227 end
1577
0a6974f2cb55 mod_http_muc_log: Use archive IDs to find next and previous dates that contain messages
Kim Alvefur <zash@zash.se>
parents: 1576
diff changeset
228 if i == 1 then return end -- No items
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229
2236
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
230 local next_when, prev_when = "", "";
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
231 local date_list = archive.dates and archive:dates(room);
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
232 if date_list then
2592
fb1987d4ac62 mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents: 2591
diff changeset
233 for j = 1, #date_list do
fb1987d4ac62 mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents: 2591
diff changeset
234 if date_list[j] == date then
fb1987d4ac62 mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents: 2591
diff changeset
235 next_when = date_list[j+1] or "";
fb1987d4ac62 mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents: 2591
diff changeset
236 prev_when = date_list[j-1] or "";
2236
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
237 break;
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
238 end
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
239 end
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
240 else
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241
2236
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
242 module:log("debug", "Find next date with messages");
2593
b61b0ff1c0f9 mod_http_muc_log: Fix prev/next date finding
Kim Alvefur <zash@zash.se>
parents: 2592
diff changeset
243 next_when = find_once(room, { after = last }, 3);
2236
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
244 if next_when then
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
245 next_when = datetime.date(next_when);
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
246 module:log("debug", "Next message: %s", next_when);
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
247 else
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
248 next_when = "";
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
249 end
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
250
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
251 module:log("debug", "Find prev date with messages");
2593
b61b0ff1c0f9 mod_http_muc_log: Fix prev/next date finding
Kim Alvefur <zash@zash.se>
parents: 2592
diff changeset
252 prev_when = find_once(room, { before = first, reverse = true }, 3);
2236
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
253 if prev_when then
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
254 prev_when = datetime.date(prev_when);
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
255 module:log("debug", "Previous message: %s", prev_when);
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
256 else
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
257 prev_when = "";
86bc6e1d9d4d mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents: 2235
diff changeset
258 end
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260
1579
9e784ddac236 mod_http_muc_log: Include charset in Content-Type header
Kim Alvefur <zash@zash.se>
parents: 1578
diff changeset
261 response.headers.content_type = "text/html; charset=utf-8";
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
262 return render(template, {
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
263 title = ("%s - %s"):format(get_room(room):get_name(), date);
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
264 jid = get_room(room).jid;
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
265 lines = logs;
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
266 links = {
1606
2c8b985ebde5 mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents: 1605
diff changeset
267 { href = "./", rel = "up", text = "Back to calendar" },
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
268 { href = prev_when, rel = "prev", text = prev_when},
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
269 { href = next_when, rel = "next", text = next_when},
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
270 };
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
271 });
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 local function list_rooms(event)
1654
1a6d6221c5f6 mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1625
diff changeset
275 local response = event.response;
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 local room_list, i = {}, 1;
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 for room in each_room() do
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 if public_room(room) then
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
279 room_list[i], i = {
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
280 href = get_link(jid_split(room.jid), nil);
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281 name = room:get_name();
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 description = room:get_description();
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 }, i + 1;
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 end
1576
91b91052e0e8 mod_http_muc_log: Send a HTML mime type with responses
Kim Alvefur <zash@zash.se>
parents: 1575
diff changeset
286
1581
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
287 response.headers.content_type = "text/html; charset=utf-8";
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
288 return render(template, {
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
289 title = module:get_option_string("name", "Prosody Chatrooms");
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
290 jid = module.host;
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
291 rooms = room_list;
9f6cd252d233 mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents: 1580
diff changeset
292 });
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 end
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295 module:provides("http", {
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296 route = {
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
297 ["GET /"] = list_rooms;
2685
cd5781ca782d mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents: 2593
diff changeset
298 ["GET /*"] = logs_page;
1549
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299 };
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 });
f9f8bf82ece7 mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
301