comparison mod_cloud_notify/mod_cloud_notify.lua @ 2254:122cb5f4930f

mod_cloud_notify: Cache <enable> in local
author Kim Alvefur <zash@zash.se>
date Thu, 28 Jul 2016 12:10:09 +0200
parents 97ebd28a8a75
children cdfc917a8cc7
comparison
equal deleted inserted replaced
2253:97ebd28a8a75 2254:122cb5f4930f
24 end); 24 end);
25 25
26 -- http://xmpp.org/extensions/xep-0357.html#enabling 26 -- http://xmpp.org/extensions/xep-0357.html#enabling
27 module:hook("iq-set/self/"..xmlns_push..":enable", function (event) 27 module:hook("iq-set/self/"..xmlns_push..":enable", function (event)
28 local origin, stanza = event.origin, event.stanza; 28 local origin, stanza = event.origin, event.stanza;
29 local enable = stanza.tags[1];
29 origin.log("debug", "Attempting to enable push notifications"); 30 origin.log("debug", "Attempting to enable push notifications");
30 -- MUST contain a 'jid' attribute of the XMPP Push Service being enabled 31 -- MUST contain a 'jid' attribute of the XMPP Push Service being enabled
31 local push_jid = stanza.tags[1].attr.jid; 32 local push_jid = enable.attr.jid;
32 -- SHOULD contain a 'node' attribute 33 -- SHOULD contain a 'node' attribute
33 local push_node = stanza.tags[1].attr.node; 34 local push_node = enable.attr.node;
34 if not push_jid then 35 if not push_jid then
35 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid")); 36 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid"));
36 return true; 37 return true;
37 end 38 end
38 local publish_options = stanza.tags[1].tags[1]; 39 local publish_options = enable.tags[1];
39 if publish_options and ( publish_options.name ~= "x" or publish_options.attr.xmlns ~= "jabber:x:data" ) then 40 if publish_options and ( publish_options.name ~= "x" or publish_options.attr.xmlns ~= "jabber:x:data" ) then
40 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid publish options")); 41 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid publish options"));
41 return true; 42 return true;
42 end 43 end
43 local user_push_services = push_enabled:get(origin.username); 44 local user_push_services = push_enabled:get(origin.username);