Software /
code /
prosody-modules
Diff
mod_cloud_notify/mod_cloud_notify.lua @ 1907:7fe7bd7b33b6
mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 14 Oct 2015 13:41:03 +0200 |
parent | 1784:1656d4fd71d0 |
child | 1908:eba279ddc050 |
line wrap: on
line diff
--- a/mod_cloud_notify/mod_cloud_notify.lua Wed Oct 14 13:20:59 2015 +0200 +++ b/mod_cloud_notify/mod_cloud_notify.lua Wed Oct 14 13:41:03 2015 +0200 @@ -13,11 +13,15 @@ local push_enabled = module:shared("push-enabled-users"); +-- http://xmpp.org/extensions/xep-0357.html#enabling module:hook("iq-set/self/"..xmlns_push..":enable", function (event) local origin, stanza = event.origin, event.stanza; - local push_jid, push_node = stanza.tags[1].attr.jid, stanza.tags[1].attr.node; - if not push_jid or not push_node then - origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid or node")); + -- MUST contain a 'jid' attribute of the XMPP Push Service being enabled + local push_jid = stanza.tags[1].attr.jid; + -- SHOULD contain a 'node' attribute + local push_node = stanza.tags[1].attr.node; + if not push_jid then + origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid")); return true; end local publish_options = stanza.tags[1].tags[1]; @@ -29,7 +33,7 @@ if not user_push_services then user_push_services = {}; end - user_push_services[push_jid .. "<" .. push_node] = { + user_push_services[push_jid .. "<" .. (push_node or "")] = { jid = push_jid; node = push_node; count = 0; @@ -39,16 +43,20 @@ return true; end); +-- http://xmpp.org/extensions/xep-0357.html#disabling module:hook("iq-set/self/"..xmlns_push..":disable", function (event) local origin, stanza = event.origin, event.stanza; - local push_jid, push_node = stanza.tags[1].attr.jid, stanza.tags[1].attr.node; - if not push_jid or not push_node then - origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid or node")); + local push_jid = stanza.tags[1].attr.jid; -- MUST include a 'jid' attribute + local push_node = stanza.tags[1].attr.node; -- A 'node' attribute MAY be included + if not push_jid then + origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid")); return true; end local user_push_services = push_enabled[origin.username]; - if user_push_services then - user_push_services[push_jid .. "<" .. push_node] = nil; + for key, push_info in pairs(user_push_services) do + if push_info.jid == push_jid and (not push_node or push_info.node == push_node) then + user_push_services[key] = nil; + end end origin.send(st.reply(stanza)); return true; @@ -62,6 +70,7 @@ { name = "last-message-body"; type = "text-single"; }; }; +-- http://xmpp.org/extensions/xep-0357.html#publishing module:hook("message/offline/handle", function(event) local origin, stanza = event.origin, event.stanza; local to = stanza.attr.to;