Strip images from XHTML-IM as well
authorStephen Paul Weber <singpolyma@singpolyma.net>
Mon, 20 Feb 2023 13:41:46 -0500
changeset 5175 1682166171ff
parent 5174 4d6af8950016
child 5176 dc6a10629670
Strip images from XHTML-IM as well
mod_muc_restrict_media/mod_muc_restrict_media.lua
--- a/mod_muc_restrict_media/mod_muc_restrict_media.lua	Sun Feb 19 18:17:37 2023 +0100
+++ b/mod_muc_restrict_media/mod_muc_restrict_media.lua	Mon Feb 20 13:41:46 2023 -0500
@@ -48,6 +48,19 @@
 	formdata["{xmpp:prosody.im}muc#roomconfig_unaffiliated_media"] = allow_unaffiliated_media;
 end);
 
+local function strip_xhtml_img(tag)
+	if tag.attr.xmlns == "http://www.w3.org/1999/xhtml" and tag.name == "img" then
+		tag.name = "i";
+		tag:text(tag.attr.alt or "<image blocked>");
+		tag.attr = { xmlns = tag.attr.xmlns, title = tag.attr.title };
+		tag:maptags(strip_xhtml_img);
+	else
+		tag:maptags(strip_xhtml_img);
+	end
+
+	return tag;
+end
+
 local function filter_media_tags(tag)
 	local xmlns = tag.attr.xmlns;
 	if xmlns == "jabber:x:oob" then
@@ -56,6 +69,8 @@
 		if tag:get_child("media-sharing", "urn:xmpp:sims:1") then
 			return nil;
 		end
+	elseif xmlns == "http://jabber.org/protocol/xhtml-im" then
+		return strip_xhtml_img(tag);
 	end
 	return tag;
 end