# HG changeset patch # User Kim Alvefur # Date 1526855745 -7200 # Node ID 07197f29e2b8bdc5486db97a06a8eddc45751b52 # Parent 2c55fccb0c0c110631cae283224c9ddd9025afb4 mod_pubsub: Make the 'type' attribute on broadcast messages configurable This adds support for the pubsub#notification_type field in the node config form. diff -r 2c55fccb0c0c -r 07197f29e2b8 plugins/mod_pubsub/mod_pubsub.lua --- a/plugins/mod_pubsub/mod_pubsub.lua Mon May 21 00:35:00 2018 +0200 +++ b/plugins/mod_pubsub/mod_pubsub.lua Mon May 21 00:35:45 2018 +0200 @@ -41,7 +41,7 @@ end -function simple_broadcast(kind, node, jids, item, actor) +function simple_broadcast(kind, node, jids, item, actor, node_obj) if item then item = st.clone(item); item.attr.xmlns = nil; -- Clear the pubsub namespace @@ -51,10 +51,12 @@ end local id = new_id(); - local message = st.message({ from = module.host, type = "headline", id = id }) + local msg_type = node_obj and node_obj.config.message_type or "headline"; + local message = st.message({ from = module.host, type = msg_type, id = id }) :tag("event", { xmlns = xmlns_pubsub_event }) :tag(kind, { node = node }) :add_child(item); + module:broadcast(jids, message, pairs); end diff -r 2c55fccb0c0c -r 07197f29e2b8 plugins/mod_pubsub/pubsub.lib.lua --- a/plugins/mod_pubsub/pubsub.lib.lua Mon May 21 00:35:00 2018 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Mon May 21 00:35:45 2018 +0200 @@ -52,6 +52,14 @@ name = "pubsub#persist_items"; label = "Persist items to storage"; }; + { + type = "list-single"; + name = "pubsub#notification_type"; + label = "Specify the delivery style for notifications"; + options = { + { label = "Messages of type normal", value = "normal" }, + { label = "Messages of type headline", value = "headline", default = true }, + }; }; local service_method_feature_map = { @@ -187,6 +195,7 @@ config = { ["max_items"] = tonumber(form_data["pubsub#max_items"]); ["persist_items"] = form_data["pubsub#persist_items"]; + ["notification_type"] = form_data["pubsub#notification_type"]; }; end if node then @@ -373,7 +382,8 @@ local node_config = node_obj.config; local pubsub_form_data = { ["pubsub#max_items"] = tostring(node_config["max_items"]); - ["pubsub#persist_items"] = node_config["persist_items"] + ["pubsub#persist_items"] = node_config["persist_items"]; + ["pubsub#notification_type"] = node_config["notification_type"]; } local reply = st.reply(stanza) :tag("pubsub", { xmlns = xmlns_pubsub_owner })