Changeset

5683:bebb10fa5787

mod_push2: Add back body truncation logic
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Tue, 19 Sep 2023 21:33:40 -0500
parents 5682:4d1a3de56c3d
children 5684:13c9ed6844ff
files mod_push2/mod_push2.lua
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_push2/mod_push2.lua	Tue Sep 19 21:21:17 2023 -0500
+++ b/mod_push2/mod_push2.lua	Tue Sep 19 21:33:40 2023 -0500
@@ -201,6 +201,22 @@
 		envelope_bytes = tostring(envelope)
 	end
 	if string.len(envelope_bytes) > max_data_size then
+		local body = stanza:get_child_text("body")
+		if string.len(body) > 50 then
+			stanza_clone:maptags(function(el)
+				if el.name == "body" then
+					return nil
+				else
+					return el
+				end
+			end)
+
+			body = string.gsub(string.gsub("\n" .. body, "\n>[^\n]*", ""), "^%s", "")
+			stanza_clone:body(body:sub(1, utf8.offset(body, 50)) .. "…")
+			envelope_bytes = tostring(envelope)
+		end
+	end
+	if string.len(envelope_bytes) > max_data_size then
 		-- If still too big, get aggressive
 		stanza_clone:maptags(function(el)
 			if el.name == "body" or