changeset 5944:4b677e445b8a

mod_muc_moderation: adding a new hook that can be used to cancel the moderation, or modify resulting stanzas.
author John Livingston <git@john-livingston.fr>
date Mon, 29 Jul 2024 13:08:43 +0200 (4 months ago)
parents 5076b78c95ef
children a316fee71bed
files mod_muc_moderation/mod_muc_moderation.lua
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_moderation/mod_muc_moderation.lua	Mon Jul 29 12:35:19 2024 +0200
+++ b/mod_muc_moderation/mod_muc_moderation.lua	Mon Jul 29 13:08:43 2024 +0200
@@ -109,8 +109,9 @@
 
 	announcement:reset();
 
+	local tombstone = nil;
 	if muc_log_archive.set and retract then
-		local tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id })
+		tombstone = st.message({ from = original.attr.from, type = "groupchat", id = original.attr.id })
 			:tag("moderated", { xmlns = xmlns_moderate, by = actor_nick })
 				:tag("retracted", { xmlns = xmlns_retract, stamp = dt.datetime() }):up();
 
@@ -129,7 +130,25 @@
 			end
 		end
 		tombstone:reset();
+	end
 
+	-- fire an event, that can be used to cancel the moderation, or modify stanzas.
+	local event = {
+		room = room;
+		announcement = announcement;
+		tombstone = tombstone;
+		stanza_id = stanza_id;
+		retract = retract;
+		reason = reason;
+		actor = actor;
+		actor_nick = actor_nick;
+	};
+	if module:fire_event("muc-moderate-message", event) then
+		-- TODO: allow to change the error message?
+		return false, "wait", "internal-server-error";
+	end
+
+	if tombstone then
 		local was_replaced = muc_log_archive:set(room_node, stanza_id, tombstone);
 		if not was_replaced then
 			return false, "wait", "internal-server-error";