Changeset

5171:1682166171ff

Strip images from XHTML-IM as well
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Mon, 20 Feb 2023 13:41:46 -0500
parents 5170:4d6af8950016
children 5172:dc6a10629670
files mod_muc_restrict_media/mod_muc_restrict_media.lua
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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