Mercurial > prosody-hg
comparison plugins/mod_muc_mam.lua @ 12860:38b3cd292ee5
Merge 0.12->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 21 Jan 2023 17:18:16 +0100 |
| parents | cd738fb8c754 |
| children | 57e86d537ffe 7ae000fc8c07 |
comparison
equal
deleted
inserted
replaced
| 12856:89bc598c7051 | 12860:38b3cd292ee5 |
|---|---|
| 65 module:log("error", "Attempt to open archive storage returned null driver"); | 65 module:log("error", "Attempt to open archive storage returned null driver"); |
| 66 end | 66 end |
| 67 module:log("info", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); | 67 module:log("info", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); |
| 68 return false; | 68 return false; |
| 69 end | 69 end |
| 70 local use_total = module:get_option_boolean("muc_log_include_total", true); | |
| 70 | 71 |
| 71 local function archiving_enabled(room) | 72 local function archiving_enabled(room) |
| 72 if log_all_rooms then | 73 if log_all_rooms then |
| 73 module:log("debug", "Archiving all rooms"); | 74 module:log("debug", "Archiving all rooms"); |
| 74 return true; | 75 return true; |
| 107 { name = "with"; type = "jid-single" }; | 108 { name = "with"; type = "jid-single" }; |
| 108 { name = "start"; type = "text-single"; datatype = "xs:dateTime" }; | 109 { name = "start"; type = "text-single"; datatype = "xs:dateTime" }; |
| 109 { name = "end"; type = "text-single"; datatype = "xs:dateTime" }; | 110 { name = "end"; type = "text-single"; datatype = "xs:dateTime" }; |
| 110 }; | 111 }; |
| 111 | 112 |
| 113 if archive.caps and archive.caps.full_id_range then | |
| 114 table.insert(query_form, { name = "before-id"; type = "text-single"; }); | |
| 115 table.insert(query_form, { name = "after-id"; type = "text-single"; }); | |
| 116 end | |
| 117 | |
| 118 if archive.caps and archive.caps.ids then | |
| 119 table.insert(query_form, { name = "ids"; type = "list-multi"; }); | |
| 120 end | |
| 121 | |
| 122 | |
| 112 -- Serve form | 123 -- Serve form |
| 113 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) | 124 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) |
| 114 local origin, stanza = event.origin, event.stanza; | 125 local origin, stanza = event.origin, event.stanza; |
| 115 origin.send(st.reply(stanza):tag("query", { xmlns = xmlns_mam }):add_child(query_form:form())); | 126 origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form())); |
| 116 return true; | 127 return true; |
| 117 end); | 128 end); |
| 118 | 129 |
| 119 -- Handle archive queries | 130 -- Handle archive queries |
| 120 module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) | 131 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); | 181 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); |
| 171 local reverse = qset and qset.before or false; | 182 local reverse = qset and qset.before or false; |
| 172 | 183 |
| 173 local before, after = qset and qset.before or qbefore, qset and qset.after or qafter; | 184 local before, after = qset and qset.before or qbefore, qset and qset.after or qafter; |
| 174 if type(before) ~= "string" then before = nil; end | 185 if type(before) ~= "string" then before = nil; end |
| 186 | |
| 175 -- A reverse query needs to be flipped | 187 -- A reverse query needs to be flipped |
| 176 local flip = reverse; | 188 local flip = reverse; |
| 177 -- A flip-page query needs to be the opposite of that. | 189 -- A flip-page query needs to be the opposite of that. |
| 178 if query:get_child("flip-page") then flip = not flip end | 190 if query:get_child("flip-page") then flip = not flip end |
| 179 | 191 |
| 185 qset); | 197 qset); |
| 186 | 198 |
| 187 -- Load all the data! | 199 -- Load all the data! |
| 188 local data, err = archive:find(room_node, { | 200 local data, err = archive:find(room_node, { |
| 189 start = qstart; ["end"] = qend; -- Time range | 201 start = qstart; ["end"] = qend; -- Time range |
| 202 with = "message<groupchat"; | |
| 190 limit = qmax + 1; | 203 limit = qmax + 1; |
| 191 before = before; after = after; | 204 before = before; after = after; |
| 192 ids = qids; | 205 ids = qids; |
| 193 reverse = reverse; | 206 reverse = reverse; |
| 194 with = "message<groupchat"; | 207 total = use_total or qmax == 0; |
| 195 }); | 208 }); |
| 196 | 209 |
| 197 if not data then | 210 if not data then |
| 198 module:log("debug", "Archive query id=%s failed: %s", qid or stanza.attr.id, err); | 211 module:log("debug", "Archive query id=%s failed: %s", qid or stanza.attr.id, err); |
| 199 if err == "item-not-found" then | 212 if err == "item-not-found" then |
| 214 local count = 0; | 227 local count = 0; |
| 215 local complete = "true"; | 228 local complete = "true"; |
| 216 for id, item, when in data do | 229 for id, item, when in data do |
| 217 count = count + 1; | 230 count = count + 1; |
| 218 if count > qmax then | 231 if count > qmax then |
| 232 -- We requested qmax+1 items. If that many items are retrieved then | |
| 233 -- there are more results to page through, so: | |
| 219 complete = nil; | 234 complete = nil; |
| 220 break; | 235 break; |
| 221 end | 236 end |
| 222 local fwd_st = st.message(msg_reply_attr) | 237 local fwd_st = st.message(msg_reply_attr) |
| 223 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) | 238 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }) |
| 256 end | 271 end |
| 257 end | 272 end |
| 258 if reverse then | 273 if reverse then |
| 259 first, last = last, first; | 274 first, last = last, first; |
| 260 end | 275 end |
| 261 | |
| 262 | 276 |
| 263 origin.send(st.reply(stanza) | 277 origin.send(st.reply(stanza) |
| 264 :tag("fin", { xmlns = xmlns_mam, complete = complete }) | 278 :tag("fin", { xmlns = xmlns_mam, complete = complete }) |
| 265 :add_child(rsm.generate { | 279 :add_child(rsm.generate { |
| 266 first = first, last = last, count = total })); | 280 first = first, last = last, count = total })); |
| 549 cleanup_done(); | 563 cleanup_done(); |
| 550 end); | 564 end); |
| 551 | 565 |
| 552 else | 566 else |
| 553 module:log("debug", "Archive expiry disabled"); | 567 module:log("debug", "Archive expiry disabled"); |
| 554 end | 568 -- Don't ask the backend to count the potentially unbounded number of items, |
| 569 -- it'll get slow. | |
| 570 use_total = module:get_option_boolean("mam_include_total", false); | |
| 571 end |
