aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_mam/mod_mam.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-11-30 23:42:13 +0100
committerKim Alvefur <zash@zash.se>2020-11-30 23:42:13 +0100
commit8236720cdbd28a6d679d9a9311889425d222c979 (patch)
treedd0287ecd90f5259c46619b11862fb9f669e9ff2 /plugins/mod_mam/mod_mam.lua
parent968fd6eb62bf2f9b3527fc4f2fa751dfb36c3bf5 (diff)
downloadprosody-8236720cdbd28a6d679d9a9311889425d222c979.tar.gz
prosody-8236720cdbd28a6d679d9a9311889425d222c979.zip
mod_mam: Implement extended MAM metadata query
Diffstat (limited to 'plugins/mod_mam/mod_mam.lua')
-rw-r--r--plugins/mod_mam/mod_mam.lua36
1 files changed, 35 insertions, 1 deletions
diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua
index f252d179..423a68ca 100644
--- a/plugins/mod_mam/mod_mam.lua
+++ b/plugins/mod_mam/mod_mam.lua
@@ -229,6 +229,41 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event)
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 @@ module:hook("message/full", message_handler, 0);
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)