Mercurial > prosody-modules
comparison 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 |
parents | 1656d4fd71d0 |
children | eba279ddc050 |
comparison
equal
deleted
inserted
replaced
1906:5849d70bcd37 | 1907:7fe7bd7b33b6 |
---|---|
11 | 11 |
12 module:add_feature(xmlns_push); | 12 module:add_feature(xmlns_push); |
13 | 13 |
14 local push_enabled = module:shared("push-enabled-users"); | 14 local push_enabled = module:shared("push-enabled-users"); |
15 | 15 |
16 -- http://xmpp.org/extensions/xep-0357.html#enabling | |
16 module:hook("iq-set/self/"..xmlns_push..":enable", function (event) | 17 module:hook("iq-set/self/"..xmlns_push..":enable", function (event) |
17 local origin, stanza = event.origin, event.stanza; | 18 local origin, stanza = event.origin, event.stanza; |
18 local push_jid, push_node = stanza.tags[1].attr.jid, stanza.tags[1].attr.node; | 19 -- MUST contain a 'jid' attribute of the XMPP Push Service being enabled |
19 if not push_jid or not push_node then | 20 local push_jid = stanza.tags[1].attr.jid; |
20 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid or node")); | 21 -- SHOULD contain a 'node' attribute |
22 local push_node = stanza.tags[1].attr.node; | |
23 if not push_jid then | |
24 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid")); | |
21 return true; | 25 return true; |
22 end | 26 end |
23 local publish_options = stanza.tags[1].tags[1]; | 27 local publish_options = stanza.tags[1].tags[1]; |
24 if publish_options and ( publish_options.name ~= "x" or publish_options.attr.xmlns ~= "jabber:x:data" ) then | 28 if publish_options and ( publish_options.name ~= "x" or publish_options.attr.xmlns ~= "jabber:x:data" ) then |
25 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid publish options")); | 29 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid publish options")); |
27 end | 31 end |
28 local user_push_services = push_enabled[origin.username]; | 32 local user_push_services = push_enabled[origin.username]; |
29 if not user_push_services then | 33 if not user_push_services then |
30 user_push_services = {}; | 34 user_push_services = {}; |
31 end | 35 end |
32 user_push_services[push_jid .. "<" .. push_node] = { | 36 user_push_services[push_jid .. "<" .. (push_node or "")] = { |
33 jid = push_jid; | 37 jid = push_jid; |
34 node = push_node; | 38 node = push_node; |
35 count = 0; | 39 count = 0; |
36 options = publish_options; | 40 options = publish_options; |
37 }; | 41 }; |
38 origin.send(st.reply(stanza)); | 42 origin.send(st.reply(stanza)); |
39 return true; | 43 return true; |
40 end); | 44 end); |
41 | 45 |
46 -- http://xmpp.org/extensions/xep-0357.html#disabling | |
42 module:hook("iq-set/self/"..xmlns_push..":disable", function (event) | 47 module:hook("iq-set/self/"..xmlns_push..":disable", function (event) |
43 local origin, stanza = event.origin, event.stanza; | 48 local origin, stanza = event.origin, event.stanza; |
44 local push_jid, push_node = stanza.tags[1].attr.jid, stanza.tags[1].attr.node; | 49 local push_jid = stanza.tags[1].attr.jid; -- MUST include a 'jid' attribute |
45 if not push_jid or not push_node then | 50 local push_node = stanza.tags[1].attr.node; -- A 'node' attribute MAY be included |
46 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid or node")); | 51 if not push_jid then |
52 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid")); | |
47 return true; | 53 return true; |
48 end | 54 end |
49 local user_push_services = push_enabled[origin.username]; | 55 local user_push_services = push_enabled[origin.username]; |
50 if user_push_services then | 56 for key, push_info in pairs(user_push_services) do |
51 user_push_services[push_jid .. "<" .. push_node] = nil; | 57 if push_info.jid == push_jid and (not push_node or push_info.node == push_node) then |
58 user_push_services[key] = nil; | |
59 end | |
52 end | 60 end |
53 origin.send(st.reply(stanza)); | 61 origin.send(st.reply(stanza)); |
54 return true; | 62 return true; |
55 end); | 63 end); |
56 | 64 |
60 { name = "pending-subscription-count"; type = "text-single"; }; | 68 { name = "pending-subscription-count"; type = "text-single"; }; |
61 { name = "last-message-sender"; type = "jid-single"; }; | 69 { name = "last-message-sender"; type = "jid-single"; }; |
62 { name = "last-message-body"; type = "text-single"; }; | 70 { name = "last-message-body"; type = "text-single"; }; |
63 }; | 71 }; |
64 | 72 |
73 -- http://xmpp.org/extensions/xep-0357.html#publishing | |
65 module:hook("message/offline/handle", function(event) | 74 module:hook("message/offline/handle", function(event) |
66 local origin, stanza = event.origin, event.stanza; | 75 local origin, stanza = event.origin, event.stanza; |
67 local to = stanza.attr.to; | 76 local to = stanza.attr.to; |
68 local node = to and jid.split(to) or origin.username; | 77 local node = to and jid.split(to) or origin.username; |
69 local user_push_services = push_enabled[node]; | 78 local user_push_services = push_enabled[node]; |