Software /
code /
prosody
Changeset
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 | 11269:342ac5d806fb |
children | 11271:41a962b72a6e |
files | plugins/mod_mam/mod_mam.lua spec/scansion/mam_extended.scs |
diffstat | 2 files changed, 49 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_mam/mod_mam.lua Mon Nov 30 21:12:01 2020 +0100 +++ b/plugins/mod_mam/mod_mam.lua Mon Nov 30 23:42:13 2020 +0100 @@ -229,6 +229,41 @@ return true; end); +module:hook("iq-get/self/"..xmlns_mam..":metadata", function (event) + local origin, stanza = event.origin, event.stanza; + + local reply = st.reply(stanza):tag("metadata", { xmlns = xmlns_mam }); + + do + local first = archive:find(origin.username, { limit = 1 }); + if not first then + origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); + return true; + end + + local id, _, when = first(); + if id then + reply:tag("start", { id = id, timestamp = timestamp(when) }):up(); + end + end + + do + local last = archive:find(origin.username, { limit = 1, reverse = true }); + if not last then + origin.send(st.error_reply(stanza, "cancel", "internal-server-error")); + return true; + end + + local id, _, when = last(); + if id then + reply:tag("end", { id = id, timestamp = timestamp(when) }):up(); + end + end + + origin.send(reply); + return true; +end); + local function has_in_roster(user, who) local roster = rm_load_roster(user, host); module:log("debug", "%s has %s in roster? %s", user, who, roster[who] and "yes" or "no"); @@ -522,7 +557,6 @@ local advertise_extended = module:get_option_boolean("mam_advertise_extend", false); -- TODO before-id, after-id -- TODO ids --- TODO archive metadata query -- TODO delete feature flag option module:hook("account-disco-info", function(event)
--- a/spec/scansion/mam_extended.scs Mon Nov 30 21:12:01 2020 +0100 +++ b/spec/scansion/mam_extended.scs Mon Nov 30 23:42:13 2020 +0100 @@ -36,6 +36,20 @@ <body>U there?</body> </message> +# Metadata +Romeo sends: + <iq type="get" id="mamextmeta"> + <metadata xmlns="urn:xmpp:mam:2"/> + </iq> + +Romeo receives: + <iq type="result" id="mamextmeta"> + <metadata xmlns="urn:xmpp:mam:2"> + <start timestamp="2008-08-22T21:09:04Z" xmlns="urn:xmpp:mam:2" id="{scansion:any}"/> + <end timestamp="2008-08-22T21:09:04Z" xmlns="urn:xmpp:mam:2" id="{scansion:any}"/> + </metadata> + </iq> + Romeo sends: <iq type="set" id="mamquery1"> <query xmlns="urn:xmpp:mam:2" queryid="q1"/>