comparison mod_http_muc_log/mod_http_muc_log.lua @ 2236:86bc6e1d9d4d

mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
author Kim Alvefur <zash@zash.se>
date Fri, 08 Jul 2016 22:40:30 +0200
parents c5ee48e27d01
children 63dd3e525f13
comparison
equal deleted inserted replaced
2235:c5ee48e27d01 2236:86bc6e1d9d4d
199 first = first or key; 199 first = first or key;
200 last = key; 200 last = key;
201 end 201 end
202 if i == 1 then return end -- No items 202 if i == 1 then return end -- No items
203 203
204 module:log("debug", "Find next date with messages"); 204 local next_when, prev_when = "", "";
205 local next_when = find_once(room, { after = last }, 3); 205 local date_list = archive.dates and archive:dates(room);
206 if next_when then 206 if date_list then
207 next_when = datetime.date(next_when); 207 for i = 1, #date_list do
208 module:log("debug", "Next message: %s", next_when); 208 if date_list[i] == date then
209 next_when = date_list[i+1] or "";
210 prev_when = date_list[i-1] or "";
211 break;
212 end
213 end
209 else 214 else
210 next_when = ""; 215
211 end 216 module:log("debug", "Find next date with messages");
212 217 local next_when = find_once(room, { after = last }, 3);
213 module:log("debug", "Find prev date with messages"); 218 if next_when then
214 local prev_when = find_once(room, { before = first, reverse = true }, 3); 219 next_when = datetime.date(next_when);
215 if prev_when then 220 module:log("debug", "Next message: %s", next_when);
216 prev_when = datetime.date(prev_when); 221 else
217 module:log("debug", "Previous message: %s", prev_when); 222 next_when = "";
218 else 223 end
219 prev_when = ""; 224
225 module:log("debug", "Find prev date with messages");
226 local prev_when = find_once(room, { before = first, reverse = true }, 3);
227 if prev_when then
228 prev_when = datetime.date(prev_when);
229 module:log("debug", "Previous message: %s", prev_when);
230 else
231 prev_when = "";
232 end
220 end 233 end
221 234
222 response.headers.content_type = "text/html; charset=utf-8"; 235 response.headers.content_type = "text/html; charset=utf-8";
223 return render(template, { 236 return render(template, {
224 title = ("%s - %s"):format(get_room(room):get_name(), date); 237 title = ("%s - %s"):format(get_room(room):get_name(), date);