Mercurial > prosody-modules
comparison mod_mam_archive/mod_mam_archive.lua @ 1523:54f6158a4915
Backed out changeset 71af9c272d72
author | syn@syn.im |
---|---|
date | Sun, 12 Oct 2014 17:09:07 +0200 |
parents | 71af9c272d72 |
children | b51e596c5a02 |
comparison
equal
deleted
inserted
replaced
1521:71af9c272d72 | 1523:54f6158a4915 |
---|---|
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 | |
253 -- Load all the data! | 250 -- Load all the data! |
254 local data, err = archive:find(origin.username, { | 251 local data, err = archive:find(origin.username, { |
255 start = qstart; ["end"] = qstart + conversation_interval; | 252 start = qstart; ["end"] = qstart + conversation_interval; |
256 with = qwith; | 253 with = qwith; |
257 limit = qmax; | 254 limit = qmax; |
258 before = before; after = after; | 255 before = before; after = after; |
259 reverse = reverse; | 256 reverse = reverse; |
257 total = true; | |
260 }); | 258 }); |
261 | 259 |
262 if not data then | 260 if not data then |
263 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); | 261 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); |
264 end | 262 end |
265 local count = err; | 263 local count = err; |
266 | 264 |
267 local chat = reply:tag("chat", {xmlns=xmlns_archive, with=qwith, start=date_format(qstart), version=count}); | 265 local chat = reply:tag("chat", {xmlns=xmlns_archive, with=qwith, start=date_format(qstart), version=count}); |
268 local first, last; | 266 local first, last; |
269 local count = 0; | 267 |
268 module:log("debug", "Count "..count); | |
270 for id, item, when in data do | 269 for id, item, when in data do |
271 if not getmetatable(item) == st.stanza_mt then | 270 if not getmetatable(item) == st.stanza_mt then |
272 item = st.deserialize(item); | 271 item = st.deserialize(item); |
273 end | 272 end |
274 module:log("debug", tostring(item)); | 273 module:log("debug", tostring(item)); |
276 local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "to" or "from"; | 275 local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "to" or "from"; |
277 tag = chat:tag(tag, {secs = when - qstart}); | 276 tag = chat:tag(tag, {secs = when - qstart}); |
278 tag:add_child(item:get_child("body")):up(); | 277 tag:add_child(item:get_child("body")):up(); |
279 if not first then first = id; end | 278 if not first then first = id; end |
280 last = id; | 279 last = id; |
281 count = count+1; | 280 end |
282 end | |
283 module:log("debug", "Count ".. count); | |
284 reply:add_child(rsm.generate{ first = first, last = last, count = count }) | 281 reply:add_child(rsm.generate{ first = first, last = last, count = count }) |
285 | 282 |
286 origin.send(reply); | 283 origin.send(reply); |
287 return true; | 284 return true; |
288 end | 285 end |