Changeset

4689:ecfffbbcbf42

mod_debug_omemo: Use archive single message retrieval method Likely more efficient, where implemented.
author Kim Alvefur <zash@zash.se>
date Wed, 15 Sep 2021 17:55:58 +0200
parents 4688:05725276fac0
children 4690:82dabfffaddf
files mod_debug_omemo/mod_debug_omemo.lua
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mod_debug_omemo/mod_debug_omemo.lua	Wed Sep 15 17:39:37 2021 +0200
+++ b/mod_debug_omemo/mod_debug_omemo.lua	Wed Sep 15 17:55:58 2021 +0200
@@ -100,15 +100,24 @@
 	presence = "Contacts only";
 };
 
+local function get_message(username, message_id)
+	if mam.get then
+		return mam:get(username, message_id);
+	end
+	-- COMPAT
+	local message;
+	for _, result in mam:find(username, { key = message_id }) do
+		message = result;
+	end
+	return message;
+end
+
 local function render_message(event, path)
 	local username, message_id = path:match("^([^/]+)/(.+)$");
 	if not username then
 		return 400;
 	end
-	local message;
-	for _, result in mam:find(username, { key = message_id }) do
-		message = result;
-	end
+	local message = get_message(username, message_id);
 	if not message then
 		return 404;
 	end