diff mod_muc_thread_polyfill/mod_muc_thread_polyfill.lua @ 6351:1a08652c3fea

mod_muc_thread_polyfill: new module to infer threads when possible for clients that do not send them
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Fri, 26 Dec 2025 11:39:34 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_muc_thread_polyfill/mod_muc_thread_polyfill.lua	Fri Dec 26 11:39:34 2025 -0500
@@ -0,0 +1,33 @@
+local st = require "util.stanza";
+local jid = require "util.jid";
+
+local archive = module:open_store("muc_log", "archive");
+
+module:hook("muc-occupant-groupchat", function (event)
+	local stanza = event.stanza;
+	local room   = event.room;
+
+	if stanza:get_child("thread") then
+		return;
+	end
+
+	local reply = stanza:get_child("reply", "urn:xmpp:reply:0");
+	if not reply then
+		return;
+	end
+
+	local reply_id = reply.attr.id;
+	if not reply_id then
+		return;
+	end
+
+	local archived = archive:get(jid.node(room.jid), reply_id);
+	if not archived then
+		return;
+	end
+
+	local parent_thread = archived:get_child("thread");
+	if parent_thread then
+		stanza:add_child(st.clone(parent_thread));
+	end
+end);