comparison mod_cloud_notify/mod_cloud_notify.lua @ 1909:c7389fe74de7

mod_cloud_notify: Make inclusion of message sender and body optional via config option
author Kim Alvefur <zash@zash.se>
date Wed, 14 Oct 2015 14:07:57 +0200
parents eba279ddc050
children e170b11b60b8
comparison
equal deleted inserted replaced
1908:eba279ddc050 1909:c7389fe74de7
6 local st = require"util.stanza"; 6 local st = require"util.stanza";
7 local jid = require"util.jid"; 7 local jid = require"util.jid";
8 local dataform = require"util.dataforms".new; 8 local dataform = require"util.dataforms".new;
9 9
10 local xmlns_push = "urn:xmpp:push:0"; 10 local xmlns_push = "urn:xmpp:push:0";
11
12 -- configuration
13 local include_body = module:get_option("push_notification_with_body", true);
14 local include_sender = module:get_option("push_notification_with_sender", true);
11 15
12 -- For keeping state across reloads 16 -- For keeping state across reloads
13 local push_enabled = module:shared("push-enabled-users"); 17 local push_enabled = module:shared("push-enabled-users");
14 18
15 -- http://xmpp.org/extensions/xep-0357.html#disco 19 -- http://xmpp.org/extensions/xep-0357.html#disco
84 push_info.count = push_info.count + 1; 88 push_info.count = push_info.count + 1;
85 local push_jid, push_node = push_info.jid, push_info.node; 89 local push_jid, push_node = push_info.jid, push_info.node;
86 local push_publish = st.iq({ to = push_jid, from = module.host, type = "set", id = "push" }) 90 local push_publish = st.iq({ to = push_jid, from = module.host, type = "set", id = "push" })
87 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" }) 91 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" })
88 :tag("publish", { node = push_node }); 92 :tag("publish", { node = push_node });
89 push_publish:add_child(push_form:form({ 93 local form_data = {
90 ["message-count"] = tostring(push_info.count); 94 ["message-count"] = tostring(push_info.count);
91 ["last-message-sender"] = stanza.attr.from; 95 };
92 ["last-message-body"] = stanza:get_child_text("body"); 96 if include_sender then
93 })); 97 form_data["last-message-sender"] = stanza.attr.from;
98 end
99 if include_body then
100 form_data["last-message-body"] = stanza:get_child_text("body");
101 end
102 push_publish:add_child(push_form:form(form_data));
94 push_publish:up(); -- / publish 103 push_publish:up(); -- / publish
95 if push_info.options then 104 if push_info.options then
96 push_publish:tag("publish-options"):add_child(push_info.options); 105 push_publish:tag("publish-options"):add_child(push_info.options);
97 end 106 end
98 module:send(push_publish); 107 module:send(push_publish);