Comparison

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
comparison
equal deleted inserted replaced
8814:07197f29e2b8 8815:5974c9da1391
54 local msg_type = node_obj and node_obj.config.message_type or "headline"; 54 local msg_type = node_obj and node_obj.config.message_type or "headline";
55 local message = st.message({ from = module.host, type = msg_type, id = id }) 55 local message = st.message({ from = module.host, type = msg_type, id = id })
56 :tag("event", { xmlns = xmlns_pubsub_event }) 56 :tag("event", { xmlns = xmlns_pubsub_event })
57 :tag(kind, { node = node }) 57 :tag(kind, { node = node })
58 :add_child(item); 58 :add_child(item);
59
60 -- Compose a sensible textual representation of at least Atom payloads
61 if node_obj and node_obj.config.include_body and item.tags[1] then
62 local payload = item.tags[1];
63 if payload.attr.xmlns == "http://www.w3.org/2005/Atom" then
64 message:reset();
65 local title = payload:get_child_text("title");
66 local summary = payload:get_child_text("summary");
67 if not summary and title then
68 local author = payload:find("author/name#");
69 summary = title;
70 if author then
71 summary = author .. " posted " .. summary;
72 end
73 end
74 if summary then
75 message:body(summary);
76 end
77 end
78 end
59 79
60 module:broadcast(jids, message, pairs); 80 module:broadcast(jids, message, pairs);
61 end 81 end
62 82
63 function is_item_stanza(item) 83 function is_item_stanza(item)