Comparison

plugins/mod_pubsub/mod_pubsub.lua @ 9045:4336a2b97aba

mod_pubsub: Make generation of notification body into an event to allow extensibility
author Kim Alvefur <zash@zash.se>
date Sat, 14 Jul 2018 21:34:22 +0200
parent 9044:18cd5102253c
child 9100:e01c7d0cbbf4
comparison
equal deleted inserted replaced
9044:18cd5102253c 9045:4336a2b97aba
53 53
54 local summary; 54 local summary;
55 -- Compose a sensible textual representation of at least Atom payloads 55 -- Compose a sensible textual representation of at least Atom payloads
56 if item and item.tags[1] then 56 if item and item.tags[1] then
57 local payload = item.tags[1]; 57 local payload = item.tags[1];
58 if payload.attr.xmlns == "http://www.w3.org/2005/Atom" then 58 summary = module:fire_event("pubsub-summary/"..payload.attr.xmlns, {
59 local title = payload:get_child_text("title"); 59 kind = kind, node = node, jids = jids, actor = actor, item = item, payload = payload,
60 summary = payload:get_child_text("summary"); 60 });
61 if not summary and title then
62 local author = payload:find("author/name#");
63 summary = title;
64 if author then
65 summary = author .. " posted " .. summary;
66 end
67 end
68 end
69 end 61 end
70 62
71 for jid, options in pairs(jids) do 63 for jid, options in pairs(jids) do
72 local new_stanza = st.clone(message); 64 local new_stanza = st.clone(message);
73 if summary and type(options) == "table" and options["pubsub#include_body"] then 65 if summary and type(options) == "table" and options["pubsub#include_body"] then
79 end 71 end
80 72
81 function is_item_stanza(item) 73 function is_item_stanza(item)
82 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item"; 74 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item";
83 end 75 end
76
77 module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event)
78 local payload = event.item;
79 local title = payload:get_child_text("title");
80 local summary = payload:get_child_text("summary");
81 if not summary and title then
82 local author = payload:find("author/name#");
83 summary = title;
84 if author then
85 summary = author .. " posted " .. summary;
86 end
87 end
88 return summary;
89 end);
84 90
85 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); 91 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
86 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); 92 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
87 93
88 local function add_disco_features_from_service(service) --luacheck: ignore 431/service 94 local function add_disco_features_from_service(service) --luacheck: ignore 431/service