Comparison

plugins/mod_muc_mam.lua @ 12857:cc86d77481fc 0.12

mod_mam,mod_muc_mam: Minimize differences (reorder, copy some comments) Should have no functional difference, but makes it easier keeping mod_mam and mod_muc_mam in sync.
author Kim Alvefur <zash@zash.se>
date Sat, 21 Jan 2023 16:54:43 +0100
parent 11989:871100cdbbad
child 12858:71dc48a89e5a
comparison
equal deleted inserted replaced
12850:101c758428aa 12857:cc86d77481fc
110 }; 110 };
111 111
112 -- Serve form 112 -- Serve form
113 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) 113 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event)
114 local origin, stanza = event.origin, event.stanza; 114 local origin, stanza = event.origin, event.stanza;
115 origin.send(st.reply(stanza):tag("query", { xmlns = xmlns_mam }):add_child(query_form:form())); 115 origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form()));
116 return true; 116 return true;
117 end); 117 end);
118 118
119 -- Handle archive queries 119 -- Handle archive queries
120 module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) 120 module:hook("iq-set/bare/"..xmlns_mam..":query", function(event)
170 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); 170 local qmax = m_min(qset and qset.max or default_max_items, max_max_items);
171 local reverse = qset and qset.before or false; 171 local reverse = qset and qset.before or false;
172 172
173 local before, after = qset and qset.before or qbefore, qset and qset.after or qafter; 173 local before, after = qset and qset.before or qbefore, qset and qset.after or qafter;
174 if type(before) ~= "string" then before = nil; end 174 if type(before) ~= "string" then before = nil; end
175
175 -- A reverse query needs to be flipped 176 -- A reverse query needs to be flipped
176 local flip = reverse; 177 local flip = reverse;
177 -- A flip-page query needs to be the opposite of that. 178 -- A flip-page query needs to be the opposite of that.
178 if query:get_child("flip-page") then flip = not flip end 179 if query:get_child("flip-page") then flip = not flip end
179 180
185 qset); 186 qset);
186 187
187 -- Load all the data! 188 -- Load all the data!
188 local data, err = archive:find(room_node, { 189 local data, err = archive:find(room_node, {
189 start = qstart; ["end"] = qend; -- Time range 190 start = qstart; ["end"] = qend; -- Time range
191 with = "message<groupchat";
190 limit = qmax + 1; 192 limit = qmax + 1;
191 before = before; after = after; 193 before = before; after = after;
192 ids = qids; 194 ids = qids;
193 reverse = reverse; 195 reverse = reverse;
194 with = "message<groupchat"; 196 total = qmax == 0;
195 }); 197 });
196 198
197 if not data then 199 if not data then
198 module:log("debug", "Archive query id=%s failed: %s", qid or stanza.attr.id, err); 200 module:log("debug", "Archive query id=%s failed: %s", qid or stanza.attr.id, err);
199 if err == "item-not-found" then 201 if err == "item-not-found" then
214 local count = 0; 216 local count = 0;
215 local complete = "true"; 217 local complete = "true";
216 for id, item, when in data do 218 for id, item, when in data do
217 count = count + 1; 219 count = count + 1;
218 if count > qmax then 220 if count > qmax then
221 -- We requested qmax+1 items. If that many items are retrieved then
222 -- there are more results to page through, so:
219 complete = nil; 223 complete = nil;
220 break; 224 break;
221 end 225 end
222 local fwd_st = st.message(msg_reply_attr) 226 local fwd_st = st.message(msg_reply_attr)
223 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) 227 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id })
256 end 260 end
257 end 261 end
258 if reverse then 262 if reverse then
259 first, last = last, first; 263 first, last = last, first;
260 end 264 end
261
262 265
263 origin.send(st.reply(stanza) 266 origin.send(st.reply(stanza)
264 :tag("fin", { xmlns = xmlns_mam, complete = complete }) 267 :tag("fin", { xmlns = xmlns_mam, complete = complete })
265 :add_child(rsm.generate { 268 :add_child(rsm.generate {
266 first = first, last = last, count = total })); 269 first = first, last = last, count = total }));