Mercurial > prosody-hg
comparison plugins/mod_mam/mod_mam.lua @ 11270:eaaa8ca742a7
mod_mam: Implement extended MAM metadata query
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 30 Nov 2020 23:42:13 +0100 |
| parents | 342ac5d806fb |
| children | 44c9cb4094bb |
comparison
equal
deleted
inserted
replaced
| 11269:342ac5d806fb | 11270:eaaa8ca742a7 |
|---|---|
| 224 :add_child(rsm.generate { | 224 :add_child(rsm.generate { |
| 225 first = first, last = last, count = total })); | 225 first = first, last = last, count = total })); |
| 226 | 226 |
| 227 -- That's all folks! | 227 -- That's all folks! |
| 228 module:log("debug", "Archive query id=%s completed, %d items returned", qid or stanza.attr.id, complete and count or count - 1); | 228 module:log("debug", "Archive query id=%s completed, %d items returned", qid or stanza.attr.id, complete and count or count - 1); |
| 229 return true; | |
| 230 end); | |
| 231 | |
| 232 module:hook("iq-get/self/"..xmlns_mam..":metadata", function (event) | |
| 233 local origin, stanza = event.origin, event.stanza; | |
| 234 | |
| 235 local reply = st.reply(stanza):tag("metadata", { xmlns = xmlns_mam }); | |
| 236 | |
| 237 do | |
| 238 local first = archive:find(origin.username, { limit = 1 }); | |
| 239 if not first then | |
| 240 origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); | |
| 241 return true; | |
| 242 end | |
| 243 | |
| 244 local id, _, when = first(); | |
| 245 if id then | |
| 246 reply:tag("start", { id = id, timestamp = timestamp(when) }):up(); | |
| 247 end | |
| 248 end | |
| 249 | |
| 250 do | |
| 251 local last = archive:find(origin.username, { limit = 1, reverse = true }); | |
| 252 if not last then | |
| 253 origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); | |
| 254 return true; | |
| 255 end | |
| 256 | |
| 257 local id, _, when = last(); | |
| 258 if id then | |
| 259 reply:tag("end", { id = id, timestamp = timestamp(when) }):up(); | |
| 260 end | |
| 261 end | |
| 262 | |
| 263 origin.send(reply); | |
| 229 return true; | 264 return true; |
| 230 end); | 265 end); |
| 231 | 266 |
| 232 local function has_in_roster(user, who) | 267 local function has_in_roster(user, who) |
| 233 local roster = rm_load_roster(user, host); | 268 local roster = rm_load_roster(user, host); |
| 520 module:hook("message/full", message_handler, 0); | 555 module:hook("message/full", message_handler, 0); |
| 521 | 556 |
| 522 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); | 557 local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); |
| 523 -- TODO before-id, after-id | 558 -- TODO before-id, after-id |
| 524 -- TODO ids | 559 -- TODO ids |
| 525 -- TODO archive metadata query | |
| 526 -- TODO delete feature flag option | 560 -- TODO delete feature flag option |
| 527 | 561 |
| 528 module:hook("account-disco-info", function(event) | 562 module:hook("account-disco-info", function(event) |
| 529 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); | 563 (event.reply or event.stanza):tag("feature", {var=xmlns_mam}):up(); |
| 530 if advertise_extended then | 564 if advertise_extended then |
