Diff

plugins/mod_pubsub/mod_pubsub.lua @ 8815:5974c9da1391

mod_pubsub: Add support for generation of a plain text <body> from Atom payloads See https://xmpp.org/extensions/xep-0060.html#impl-body
author Kim Alvefur <zash@zash.se>
date Mon, 21 May 2018 00:44:37 +0200
parent 8814:07197f29e2b8
child 8946:3a095233e178
line wrap: on
line diff
--- a/plugins/mod_pubsub/mod_pubsub.lua	Mon May 21 00:35:45 2018 +0200
+++ b/plugins/mod_pubsub/mod_pubsub.lua	Mon May 21 00:44:37 2018 +0200
@@ -57,6 +57,26 @@
 			:tag(kind, { node = node })
 				:add_child(item);
 
+	-- Compose a sensible textual representation of at least Atom payloads
+	if node_obj and node_obj.config.include_body and item.tags[1] then
+		local payload = item.tags[1];
+		if payload.attr.xmlns == "http://www.w3.org/2005/Atom" then
+			message:reset();
+			local title = payload:get_child_text("title");
+			local summary = payload:get_child_text("summary");
+			if not summary and title then
+				local author = payload:find("author/name#");
+				summary = title;
+				if author then
+					summary = author .. " posted " .. summary;
+				end
+			end
+			if summary then
+				message:body(summary);
+			end
+		end
+	end
+
 	module:broadcast(jids, message, pairs);
 end