Comparison

plugins/mod_mam/mod_mam.lua @ 11269:342ac5d806fb

mod_mam: Add support for page flipping This was easy. Needs tests tho, 100% chance of the logic being backwards.
author Kim Alvefur <zash@zash.se>
date Mon, 30 Nov 2020 21:12:01 +0100
parent 11268:e3f6f0b39e7b
child 11270:eaaa8ca742a7
comparison
equal deleted inserted replaced
11268:e3f6f0b39e7b 11269:342ac5d806fb
145 local before, after = qset and qset.before, qset and qset.after; 145 local before, after = qset and qset.before, qset and qset.after;
146 if type(before) ~= "string" then before = nil; end 146 if type(before) ~= "string" then before = nil; end
147 if qset then 147 if qset then
148 module:log("debug", "Archive query id=%s rsm=%q", qid or stanza.attr.id, qset); 148 module:log("debug", "Archive query id=%s rsm=%q", qid or stanza.attr.id, qset);
149 end 149 end
150 -- A reverse query needs to be flipped
151 local flip = reverse;
152 -- A flip-page query needs to be the opposite of that.
153 if query:get_child("flip-page") then flip = not flip end
150 154
151 -- Load all the data! 155 -- Load all the data!
152 local data, err = archive:find(origin.username, { 156 local data, err = archive:find(origin.username, {
153 start = qstart; ["end"] = qend; -- Time range 157 start = qstart; ["end"] = qend; -- Time range
154 with = qwith; 158 with = qwith;
197 fwd_st:add_child(item); 201 fwd_st:add_child(item);
198 202
199 if not first then first = id; end 203 if not first then first = id; end
200 last = id; 204 last = id;
201 205
202 if reverse then 206 if flip then
203 results[count] = fwd_st; 207 results[count] = fwd_st;
204 else 208 else
205 origin.send(fwd_st); 209 origin.send(fwd_st);
206 end 210 end
207 end 211 end
208 212
209 if reverse then 213 if flip then
210 for i = #results, 1, -1 do 214 for i = #results, 1, -1 do
211 origin.send(results[i]); 215 origin.send(results[i]);
212 end 216 end
217 end
218 if reverse then
213 first, last = last, first; 219 first, last = last, first;
214 end 220 end
215 221
216 origin.send(st.reply(stanza) 222 origin.send(st.reply(stanza)
217 :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete }) 223 :tag("fin", { xmlns = xmlns_mam, queryid = qid, complete = complete })
514 module:hook("message/full", message_handler, 0); 520 module:hook("message/full", message_handler, 0);
515 521
516 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); 522 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false);
517 -- TODO before-id, after-id 523 -- TODO before-id, after-id
518 -- TODO ids 524 -- TODO ids
519 -- TODO page flipping
520 -- TODO archive metadata query 525 -- TODO archive metadata query
521 -- TODO delete feature flag option 526 -- TODO delete feature flag option
522 527
523 module:hook("account-disco-info", function(event) 528 module:hook("account-disco-info", function(event)
524 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); 529 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up();