Software /
code /
prosody
Comparison
plugins/mod_muc_mam.lua @ 10415:360d574517b6
mod_muc_mam: Copy debug log improvements from mod_mam
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 17 Nov 2019 23:08:45 +0100 |
parent | 10119:29733134c76c |
child | 10558:40c2500208f4 |
comparison
equal
deleted
inserted
replaced
10414:51ebfdeccad7 | 10415:360d574517b6 |
---|---|
164 return true; | 164 return true; |
165 end | 165 end |
166 qstart, qend = vstart, vend; | 166 qstart, qend = vstart, vend; |
167 end | 167 end |
168 | 168 |
169 module:log("debug", "Archive query id %s from %s until %s)", | 169 module:log("debug", "Archive query by %s id=%s when=%s...%s", |
170 tostring(qid), | 170 origin.username, |
171 qstart and timestamp(qstart) or "the dawn of time", | 171 qid or stanza.attr.id, |
172 qend and timestamp(qend) or "now"); | 172 qstart and timestamp(qstart) or "", |
173 qend and timestamp(qend) or ""); | |
173 | 174 |
174 -- RSM stuff | 175 -- RSM stuff |
175 local qset = rsm.get(query); | 176 local qset = rsm.get(query); |
176 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); | 177 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); |
177 local reverse = qset and qset.before or false; | 178 local reverse = qset and qset.before or false; |
178 | 179 |
179 local before, after = qset and qset.before, qset and qset.after; | 180 local before, after = qset and qset.before, qset and qset.after; |
180 if type(before) ~= "string" then before = nil; end | 181 if type(before) ~= "string" then before = nil; end |
182 if qset then | |
183 module:log("debug", "Archive query id=%s rsm=%q", qid or stanza.attr.id, qset); | |
184 end | |
181 | 185 |
182 -- Load all the data! | 186 -- Load all the data! |
183 local data, err = archive:find(room_node, { | 187 local data, err = archive:find(room_node, { |
184 start = qstart; ["end"] = qend; -- Time range | 188 start = qstart; ["end"] = qend; -- Time range |
185 limit = qmax + 1; | 189 limit = qmax + 1; |
187 reverse = reverse; | 191 reverse = reverse; |
188 with = "message<groupchat"; | 192 with = "message<groupchat"; |
189 }); | 193 }); |
190 | 194 |
191 if not data then | 195 if not data then |
196 module:log("debug", "Archive query id=%s failed: %s", qid or stanza.attr.id, err); | |
192 if err == "item-not-found" then | 197 if err == "item-not-found" then |
193 origin.send(st.error_reply(stanza, "modify", "item-not-found")); | 198 origin.send(st.error_reply(stanza, "modify", "item-not-found")); |
194 else | 199 else |
195 origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); | 200 origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); |
196 end | 201 end |
248 origin.send(results[i]); | 253 origin.send(results[i]); |
249 end | 254 end |
250 first, last = last, first; | 255 first, last = last, first; |
251 end | 256 end |
252 | 257 |
253 -- That's all folks! | |
254 module:log("debug", "Archive query %s completed", qid); | |
255 | 258 |
256 origin.send(st.reply(stanza) | 259 origin.send(st.reply(stanza) |
257 :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete }) | 260 :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete }) |
258 :add_child(rsm.generate { | 261 :add_child(rsm.generate { |
259 first = first, last = last, count = total })); | 262 first = first, last = last, count = total })); |
263 | |
264 -- That's all folks! | |
265 module:log("debug", "Archive query id=%s completed, %d items returned", qid or stanza.attr.id, complete and count or count - 1); | |
260 return true; | 266 return true; |
261 end); | 267 end); |
262 | 268 |
263 module:hook("muc-get-history", function (event) | 269 module:hook("muc-get-history", function (event) |
264 local room = event.room; | 270 local room = event.room; |