comparison mod_http_muc_log/mod_http_muc_log.lua @ 1605:c8a51d1bc96d

mod_http_muc_log: Sort date list in reverse
author Kim Alvefur <zash@zash.se>
date Mon, 09 Feb 2015 00:47:38 +0100
parents 8e282eb0c70c
children 2c8b985ebde5
comparison
equal deleted inserted replaced
1604:53052a610c67 1605:c8a51d1bc96d
99 local room = nodeprep(path:match("^(.*)/$")); 99 local room = nodeprep(path:match("^(.*)/$"));
100 if not room or not public_room(room) then return end 100 if not room or not public_room(room) then return end
101 101
102 local dates, i = {}, 1; 102 local dates, i = {}, 1;
103 module:log("debug", "Find all dates with messages"); 103 module:log("debug", "Find all dates with messages");
104 local next_day; 104 local prev_day;
105 repeat 105 repeat
106 local iter = archive:find(room, { 106 local iter = archive:find(room, {
107 ["start"] = next_day; 107 ["end"] = prev_day;
108 limit = 1; 108 limit = 1;
109 with = "message<groupchat"; 109 with = "message<groupchat";
110 reverse = true;
110 }) 111 })
111 if not iter then break end 112 if not iter then break end
112 next_day = nil; 113 prev_day = nil;
113 for key, message, when in iter do 114 for key, message, when in iter do
114 next_day = datetime.date(when); 115 prev_day = datetime.date(when);
115 dates[i], i = { 116 dates[i], i = {
116 date = next_day; 117 date = prev_day;
117 }, i + 1; 118 }, i + 1;
118 next_day = datetime.parse(next_day .. "T23:59:59Z") + 1; 119 prev_day = datetime.parse(prev_day .. "T00:00:00Z") - 1;
119 break; 120 break;
120 end 121 end
121 until not next_day; 122 until not prev_day;
122 123
123 response.headers.content_type = "text/html; charset=utf-8"; 124 response.headers.content_type = "text/html; charset=utf-8";
124 return render(template, { 125 return render(template, {
125 title = get_room(room):get_name(); 126 title = get_room(room):get_name();
126 jid = get_room(room).jid; 127 jid = get_room(room).jid;