# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1689842247 -7200
# Node ID 06fad22672e15d7854d0d7e615f26bd772b4144c
# Parent  67f7df9892bb4c1328ffd9fb43a1467355a2076c
mod_muc_moderation: Copy XEP-0421 occupant-id from retracted message

Lets clients correlate the sender of whatever was retracted by
moderators. Behavior limited to Prosody 0.12, otherwise there are no
assurances of the origin of the occupant-id tag.

Ref #1816

diff -r 67f7df9892bb -r 06fad22672e1 mod_muc_moderation/mod_muc_moderation.lua
--- a/mod_muc_moderation/mod_muc_moderation.lua	Wed Jul 19 17:01:40 2023 +0200
+++ b/mod_muc_moderation/mod_muc_moderation.lua	Thu Jul 20 10:37:27 2023 +0200
@@ -27,6 +27,7 @@
 -- Namespaces
 local xmlns_fasten = "urn:xmpp:fasten:0";
 local xmlns_moderate = "urn:xmpp:message-moderate:0";
+local xmlns_occupant_id = "urn:xmpp:occupant-id:0";
 local xmlns_retract = "urn:xmpp:message-retract:0";
 
 -- Discovering support
@@ -95,11 +96,21 @@
 		announcement:text_tag("reason", reason);
 	end
 
+	local moderated_occupant_id = original:get_child("occupant-id", xmlns_occupant_id);
+	if room.get_occupant_id and moderated_occupant_id then
+		announcement:add_direct_child(moderated_occupant_id);
+	end
+
 	if muc_log_archive.set and retract then
 		local 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();
 
+		if room.get_occupant_id and moderated_occupant_id then
+			-- Copy occupant id from moderated message
+			tombstone:add_child(moderated_occupant_id);
+		end
+
 		if reason then
 			tombstone:text_tag("reason", reason);
 		end