From cc6d427f216a5ebe16c8c87d60b91d3b0de29949 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 21 May 2018 00:44:37 +0200 Subject: mod_pubsub: Add support for generation of a plain text from Atom payloads See https://xmpp.org/extensions/xep-0060.html#impl-body --- plugins/mod_pubsub/mod_pubsub.lua | 20 ++++++++++++++++++++ plugins/mod_pubsub/pubsub.lib.lua | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua index 74995a2b..707f2f8e 100644 --- a/plugins/mod_pubsub/mod_pubsub.lua +++ b/plugins/mod_pubsub/mod_pubsub.lua @@ -57,6 +57,26 @@ function simple_broadcast(kind, node, jids, item, actor, node_obj) :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 diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua index 423abd86..aabfaad6 100644 --- a/plugins/mod_pubsub/pubsub.lib.lua +++ b/plugins/mod_pubsub/pubsub.lib.lua @@ -52,6 +52,11 @@ local node_config_form = dataform { name = "pubsub#persist_items"; label = "Persist items to storage"; }; + { + type = "boolean"; + name = "pubsub#include_body"; + label = "Receive message body in addition to payload?"; + }; { type = "list-single"; name = "pubsub#notification_type"; @@ -196,6 +201,7 @@ function handlers.set_create(origin, stanza, create, service) ["max_items"] = tonumber(form_data["pubsub#max_items"]); ["persist_items"] = form_data["pubsub#persist_items"]; ["notification_type"] = form_data["pubsub#notification_type"]; + ["include_body"] = form_data["pubsub#include_body"]; }; end if node then @@ -384,6 +390,7 @@ function handlers.owner_get_configure(origin, stanza, config, service) ["pubsub#max_items"] = tostring(node_config["max_items"]); ["pubsub#persist_items"] = node_config["persist_items"]; ["pubsub#notification_type"] = node_config["notification_type"]; + ["pubsub#include_body"] = node_config["include_body"]; } local reply = st.reply(stanza) :tag("pubsub", { xmlns = xmlns_pubsub_owner }) -- cgit v1.2.3