comparison mod_mam_archive/mod_mam_archive.lua @ 1521:71af9c272d72

mod_mam_archive: Stopped lying in RSM counts
author syn@syn.im
date Sun, 12 Oct 2014 16:05:48 +0200
parents e82592ed744b
children 54f6158a4915
comparison
equal deleted inserted replaced
1520:2881d532f385 1521:71af9c272d72
245 local qmax = math.min(qset and qset.max or default_max_items, max_max_items); 245 local qmax = math.min(qset and qset.max or default_max_items, max_max_items);
246 local reverse = qset and qset.before or false; 246 local reverse = qset and qset.before or false;
247 local before, after = qset and qset.before, qset and qset.after; 247 local before, after = qset and qset.before, qset and qset.after;
248 if type(before) ~= "string" then before = nil; end 248 if type(before) ~= "string" then before = nil; end
249 249
250 module:log("debug", "RSM: start=%s, max=%s, before=%s, after=%s",
251 qstart or 'nostart', qmax or 'nomax', before or 'nobefore', after or 'noafter');
252
250 -- Load all the data! 253 -- Load all the data!
251 local data, err = archive:find(origin.username, { 254 local data, err = archive:find(origin.username, {
252 start = qstart; ["end"] = qstart + conversation_interval; 255 start = qstart; ["end"] = qstart + conversation_interval;
253 with = qwith; 256 with = qwith;
254 limit = qmax; 257 limit = qmax;
255 before = before; after = after; 258 before = before; after = after;
256 reverse = reverse; 259 reverse = reverse;
257 total = true;
258 }); 260 });
259 261
260 if not data then 262 if not data then
261 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); 263 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
262 end 264 end
263 local count = err; 265 local count = err;
264 266
265 local chat = reply:tag("chat", {xmlns=xmlns_archive, with=qwith, start=date_format(qstart), version=count}); 267 local chat = reply:tag("chat", {xmlns=xmlns_archive, with=qwith, start=date_format(qstart), version=count});
266 local first, last; 268 local first, last;
267 269 local count = 0;
268 module:log("debug", "Count "..count);
269 for id, item, when in data do 270 for id, item, when in data do
270 if not getmetatable(item) == st.stanza_mt then 271 if not getmetatable(item) == st.stanza_mt then
271 item = st.deserialize(item); 272 item = st.deserialize(item);
272 end 273 end
273 module:log("debug", tostring(item)); 274 module:log("debug", tostring(item));
275 local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "to" or "from"; 276 local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "to" or "from";
276 tag = chat:tag(tag, {secs = when - qstart}); 277 tag = chat:tag(tag, {secs = when - qstart});
277 tag:add_child(item:get_child("body")):up(); 278 tag:add_child(item:get_child("body")):up();
278 if not first then first = id; end 279 if not first then first = id; end
279 last = id; 280 last = id;
280 end 281 count = count+1;
282 end
283 module:log("debug", "Count ".. count);
281 reply:add_child(rsm.generate{ first = first, last = last, count = count }) 284 reply:add_child(rsm.generate{ first = first, last = last, count = count })
282 285
283 origin.send(reply); 286 origin.send(reply);
284 return true; 287 return true;
285 end 288 end