annotate mod_cloud_notify/mod_cloud_notify.lua @ 2198:eb53a830864c

mod_cloud_notify: default false for sending body and sender
author Chris Ballinger <chrisballinger@gmail.com>
date Thu, 02 Jun 2016 14:07:22 -0700
parents 218a3d3f7f97
children e9e38ae8037f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- XEP-0357: Push (aka: My mobile OS vendor won't let me have persistent TCP connections)
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2015 Kim Alvefur
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 --
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- This file is MIT/X11 licensed.
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local st = require"util.stanza";
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local jid = require"util.jid";
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local dataform = require"util.dataforms".new;
2141
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
9 local filters = require "util.filters";
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local xmlns_push = "urn:xmpp:push:0";
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
1909
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
13 -- configuration
2198
eb53a830864c mod_cloud_notify: default false for sending body and sender
Chris Ballinger <chrisballinger@gmail.com>
parents: 2141
diff changeset
14 local include_body = module:get_option("push_notification_with_body", false);
eb53a830864c mod_cloud_notify: default false for sending body and sender
Chris Ballinger <chrisballinger@gmail.com>
parents: 2141
diff changeset
15 local include_sender = module:get_option("push_notification_with_sender", false);
1909
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
16
1908
eba279ddc050 mod_cloud_notify: Add some comments describing code blocks
Kim Alvefur <zash@zash.se>
parents: 1907
diff changeset
17 -- For keeping state across reloads
eba279ddc050 mod_cloud_notify: Add some comments describing code blocks
Kim Alvefur <zash@zash.se>
parents: 1907
diff changeset
18 local push_enabled = module:shared("push-enabled-users");
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
1908
eba279ddc050 mod_cloud_notify: Add some comments describing code blocks
Kim Alvefur <zash@zash.se>
parents: 1907
diff changeset
20 -- http://xmpp.org/extensions/xep-0357.html#disco
eba279ddc050 mod_cloud_notify: Add some comments describing code blocks
Kim Alvefur <zash@zash.se>
parents: 1907
diff changeset
21 module:add_feature(xmlns_push);
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22
1907
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
23 -- http://xmpp.org/extensions/xep-0357.html#enabling
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 module:hook("iq-set/self/"..xmlns_push..":enable", function (event)
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 local origin, stanza = event.origin, event.stanza;
1907
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
26 -- MUST contain a 'jid' attribute of the XMPP Push Service being enabled
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
27 local push_jid = stanza.tags[1].attr.jid;
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
28 -- SHOULD contain a 'node' attribute
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
29 local push_node = stanza.tags[1].attr.node;
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
30 if not push_jid then
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
31 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid"));
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 return true;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local publish_options = stanza.tags[1].tags[1];
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 if publish_options and ( publish_options.name ~= "x" or publish_options.attr.xmlns ~= "jabber:x:data" ) then
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid publish options"));
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 return true;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 local user_push_services = push_enabled[origin.username];
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 if not user_push_services then
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 user_push_services = {};
1922
e170b11b60b8 mod_cloud_notify: Save list of push services
Kim Alvefur <zash@zash.se>
parents: 1909
diff changeset
42 push_enabled[origin.username] = user_push_services;
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 end
1907
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
44 user_push_services[push_jid .. "<" .. (push_node or "")] = {
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 jid = push_jid;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 node = push_node;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 count = 0;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 options = publish_options;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 };
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 origin.send(st.reply(stanza));
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 return true;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 end);
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53
1907
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
54 -- http://xmpp.org/extensions/xep-0357.html#disabling
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 module:hook("iq-set/self/"..xmlns_push..":disable", function (event)
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 local origin, stanza = event.origin, event.stanza;
1907
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
57 local push_jid = stanza.tags[1].attr.jid; -- MUST include a 'jid' attribute
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
58 local push_node = stanza.tags[1].attr.node; -- A 'node' attribute MAY be included
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
59 if not push_jid then
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
60 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing jid"));
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 return true;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 local user_push_services = push_enabled[origin.username];
1907
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
64 for key, push_info in pairs(user_push_services) do
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
65 if push_info.jid == push_jid and (not push_node or push_info.node == push_node) then
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
66 user_push_services[key] = nil;
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
67 end
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 origin.send(st.reply(stanza));
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 return true;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 end);
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 local push_form = dataform {
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 { name = "FORM_TYPE"; type = "hidden"; value = "urn:xmpp:push:summary"; };
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 { name = "message-count"; type = "text-single"; };
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 { name = "pending-subscription-count"; type = "text-single"; };
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 { name = "last-message-sender"; type = "jid-single"; };
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 { name = "last-message-body"; type = "text-single"; };
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 };
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80
1907
7fe7bd7b33b6 mod_cloud_notify: Allow the 'node' to be left out when disabling, clients MAY include it (and therefore leave it out)
Kim Alvefur <zash@zash.se>
parents: 1784
diff changeset
81 -- http://xmpp.org/extensions/xep-0357.html#publishing
2141
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
82 local function handle_notify_request(origin, stanza)
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 local to = stanza.attr.to;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 local node = to and jid.split(to) or origin.username;
1784
1656d4fd71d0 mod_cloud_notify: Fix syntax errors and name
Kim Alvefur <zash@zash.se>
parents: 1783
diff changeset
85 local user_push_services = push_enabled[node];
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 if not user_push_services then return end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87
1784
1656d4fd71d0 mod_cloud_notify: Fix syntax errors and name
Kim Alvefur <zash@zash.se>
parents: 1783
diff changeset
88 for _, push_info in pairs(user_push_services) do
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 push_info.count = push_info.count + 1;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 local push_jid, push_node = push_info.jid, push_info.node;
1923
b030e46ec640 mod_cloud_notify: Send notification from bare user JID per http://xmpp.org/extensions/xep-0357.html#publishing
Kim Alvefur <zash@zash.se>
parents: 1922
diff changeset
91 local push_publish = st.iq({ to = push_jid, from = node .. "@" .. module.host, type = "set", id = "push" })
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" })
1924
c84cf61ca0f3 mod_cloud_notify: Wrap notification form in <item>
Kim Alvefur <zash@zash.se>
parents: 1923
diff changeset
93 :tag("publish", { node = push_node })
2051
cb0fc00a7086 mod_cloud_notify: Fix syntax error
Kim Alvefur <zash@zash.se>
parents: 2050
diff changeset
94 :tag("item")
2050
49cc6a555dc7 mod_cloud_notify: Wrap form in namespaced element per the XEP (fixes #630)
Kim Alvefur <zash@zash.se>
parents: 2046
diff changeset
95 :tag("notification", { xmlns = xmlns_push });
1909
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
96 local form_data = {
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 ["message-count"] = tostring(push_info.count);
1909
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
98 };
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
99 if include_sender then
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
100 form_data["last-message-sender"] = stanza.attr.from;
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
101 end
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
102 if include_body then
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
103 form_data["last-message-body"] = stanza:get_child_text("body");
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
104 end
c7389fe74de7 mod_cloud_notify: Make inclusion of message sender and body optional via config option
Kim Alvefur <zash@zash.se>
parents: 1908
diff changeset
105 push_publish:add_child(push_form:form(form_data));
2050
49cc6a555dc7 mod_cloud_notify: Wrap form in namespaced element per the XEP (fixes #630)
Kim Alvefur <zash@zash.se>
parents: 2046
diff changeset
106 push_publish:up(); -- / notification
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 push_publish:up(); -- / publish
2046
980e5f5bd62c mod_cloud_notify: put publish-options into <pubsub> not into <publish>
Daniel Gultsch <daniel@gultsch.de>
parents: 1924
diff changeset
108 push_publish:up(); -- / pubsub
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 if push_info.options then
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 push_publish:tag("publish-options"):add_child(push_info.options);
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 module:send(push_publish);
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 end
2141
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
114 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
115
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
116 -- publish on offline message
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
117 module:hook("message/offline/handle", function(event)
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
118 if event.stanza._notify then
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
119 event.stanza._notify = nil;
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
120 return;
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
121 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
122 return handle_notify_request(event.origin, event.stanza);
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 end, 1);
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124
2141
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
125 -- publish on unacked smacks message
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
126 local function process_new_stanza(stanza, session)
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
127 if getmetatable(stanza) ~= st.stanza_mt then
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
128 return stanza; -- Things we don't want to touch
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
129 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
130 if stanza.name == "message" and stanza.attr.xmlns == nil and
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
131 ( stanza.attr.type == "chat" or ( stanza.attr.type or "normal" ) == "normal" ) and
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
132 -- not already notified via cloud
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
133 not stanza._notify then
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
134 stanza._notify = true;
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
135 session.log("debug", "Invoking cloud handle_notify_request for new smacks hibernated stanza...");
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
136 handle_notify_request(session, stanza)
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
137 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
138 return stanza;
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
139 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
140
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
141 -- smacks hibernation is started
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
142 local function hibernate_session(event)
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
143 local session = event.origin;
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
144 local queue = event.queue;
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
145 -- process already unacked stanzas
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
146 for i=1,#queue do
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
147 process_new_stanza(queue[i], session);
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
148 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
149 -- process future unacked (hibernated) stanzas
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
150 filters.add_filter(session, "stanzas/out", process_new_stanza);
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
151 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
152
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
153 -- smacks hibernation is ended
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
154 local function restore_session(event)
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
155 local session = event.origin;
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
156 filters.remove_filter(session, "stanzas/out", process_new_stanza);
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
157 end
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
158
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
159 module:hook("smacks-hibernation-start", hibernate_session);
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
160 module:hook("smacks-hibernation-end", restore_session);
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
161
218a3d3f7f97 mod_cloud_notify: added ability to notify even if the session is hibernated by mod_smacks
tmolitor <thilo@eightysoft.de>
parents: 2051
diff changeset
162
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 module:hook("message/offline/broadcast", function(event)
1784
1656d4fd71d0 mod_cloud_notify: Fix syntax errors and name
Kim Alvefur <zash@zash.se>
parents: 1783
diff changeset
164 local user_push_services = push_enabled[event.origin.username];
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 if not user_push_services then return end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166
1784
1656d4fd71d0 mod_cloud_notify: Fix syntax errors and name
Kim Alvefur <zash@zash.se>
parents: 1783
diff changeset
167 for _, push_info in pairs(user_push_services) do
1783
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 if push_info then
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
169 push_info.count = 0;
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171 end
b31fe2d22310 mod_cloud_notify: XEP-0357: Push - the server bits ("app server" not included)
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 end, 1);