comparison mod_http_muc_log/mod_http_muc_log.lua @ 1577:0a6974f2cb55

mod_http_muc_log: Use archive IDs to find next and previous dates that contain messages
author Kim Alvefur <zash@zash.se>
date Thu, 20 Nov 2014 19:56:22 +0100
parents 91b91052e0e8
children a68ec7a2dc02
comparison
equal deleted inserted replaced
1576:91b91052e0e8 1577:0a6974f2cb55
262 ["end"] = datetime.parse(date.."T23:59:59Z"); 262 ["end"] = datetime.parse(date.."T23:59:59Z");
263 -- with = "message<groupchat"; 263 -- with = "message<groupchat";
264 }); 264 });
265 if not iter then return 500; end 265 if not iter then return 500; end
266 266
267 local first, last;
267 local verb, subject, body; 268 local verb, subject, body;
268 for key, item, when in iter do 269 for key, item, when in iter do
269 body = item:get_child_text("body"); 270 body = item:get_child_text("body");
270 subject = item:get_child_text("subject"); 271 subject = item:get_child_text("subject");
271 verb = nil; 272 verb = nil;
284 body = subject or body; 285 body = subject or body;
285 nick = select(3, jid_split(item.attr.from)); 286 nick = select(3, jid_split(item.attr.from));
286 st_name = item.name; 287 st_name = item.name;
287 st_type = item.attr.type; 288 st_type = item.attr.type;
288 }, i + 1; 289 }, i + 1;
289 end 290 first = first or key;
291 last = key;
292 end
293 if i == 1 then return end -- No items
290 294
291 local next_when = ""; 295 local next_when = "";
292 local prev_when = ""; 296 local prev_when = "";
293 297
294 module:log("debug", "Find next date with messages"); 298 module:log("debug", "Find next date with messages");
295 for key, message, when in archive:find(room, { 299 for key, message, when in archive:find(room, {
296 ["start"] = datetime.parse(date.."T00:00:00Z") + 86400; 300 after = last;
301 limit = 1;
297 }) do 302 }) do
298 next_when = datetime.date(when); 303 next_when = datetime.date(when);
299 module:log("debug", "Next message: %s", datetime.datetime(when)); 304 module:log("debug", "Next message: %s", datetime.datetime(when));
300 break;
301 end 305 end
302 306
303 module:log("debug", "Find prev date with messages"); 307 module:log("debug", "Find prev date with messages");
304 for key, message, when in archive:find(room, { 308 for key, message, when in archive:find(room, {
305 ["end"] = datetime.parse(date.."T00:00:00Z") - 1; 309 before = first;
310 limit = 1;
306 reverse = true; 311 reverse = true;
307 }) do 312 }) do
308 prev_when = datetime.date(when); 313 prev_when = datetime.date(when);
309 module:log("debug", "Previous message: %s", datetime.datetime(when)); 314 module:log("debug", "Previous message: %s", datetime.datetime(when));
310 break;
311 end 315 end
312 316
313 response.headers.content_type = "text/html"; 317 response.headers.content_type = "text/html";
314 return page_template{ 318 return page_template{
315 canonical = module:http_url() .. "/" .. path; 319 canonical = module:http_url() .. "/" .. path;