Annotate

mod_web_push/mod_web_push.lua @ 3696:310061f6e1df

mod_bookmarks2: Fix traceback on updating from no legacy bookmarks to bookmarks 2.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Sep 2019 14:55:03 +0200
parent 3612:2cee9fcb318b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3612
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
1 -- XEP-XXXX: Web Push (aka: My mobile OS vendor won't let me have persistent TCP connections, take two)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
2 -- Copyright (C) 2019 Maxime “pep” Buquet
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
3 --
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
4 -- Heavily based on mod_cloud_notify.
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
5 -- Copyright (C) 2015-2016 Kim Alvefur
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
6 -- Copyright (C) 2017-2018 Thilo Molitor
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
7
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
8
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
9 local st = require"util.stanza";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
10 local dataform = require "util.dataforms";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
11 local http = require "net.http";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
12
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
13 local os_time = os.time;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
14 local next = next;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
15 local jid = require"util.jid";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
16 local filters = require"util.filters";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
17
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
18 local xmlns_webpush = "urn:xmpp:webpush:0";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
19
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
20 local max_push_devices = module:get_option_number("push_max_devices", 5);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
21 local dummy_body = module:get_option_string("push_notification_important_body", "New Message!");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
22
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
23 local host_sessions = prosody.hosts[module.host].sessions;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
24
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
25 -- TODO: Generate it at setup time. Obviously not to be used other than for
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
26 -- testing purposes, or at all.
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
27 -- ECDH keypair
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
28 local server_pubkey = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEhxZpb8yIVc/2hNesGLGAxEakyYy0MqEetjgL7BIOm8ybhVKxapKqNXjXJ+NOO5/b0Z0UuBg/HynGnf0xKKNhBQ==";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
29 local server_privkey = "MHcCAQEEIPhZac9pQ8aVTx9a5JyRcqfk3nuQQUFy3PaDcSWleojzoAoGCCqGSM49AwEHoUQDQgAEhxZpb8yIVc/2hNesGLGAxEakyYy0MqEetjgL7BIOm8ybhVKxapKqNXjXJ+NOO5/b0Z0UuBg/HynGnf0xKKNhBQ==";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
30
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
31 -- Advertize disco feature
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
32 local function account_disco_info(event)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
33 local form = dataform.new {
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
34 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/webpush#public-key" };
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
35 { name = "webpush#public-key", value = server_pubkey };
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
36 };
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
37 (event.reply or event.stanza):tag("feature", {var=xmlns_webpush}):up()
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
38 :add_child(form:form({}, "result"));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
39 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
40 module:hook("account-disco-info", account_disco_info);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
41
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
42 -- ordered table iterator, allow to iterate on the natural order of the keys of a table,
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
43 -- see http://lua-users.org/wiki/SortedIteration
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
44 local function __genOrderedIndex( t )
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
45 local orderedIndex = {}
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
46 for key in pairs(t) do
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
47 table.insert( orderedIndex, key )
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
48 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
49 -- sort in reverse order (newest one first)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
50 table.sort( orderedIndex, function(a, b)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
51 if a == nil or t[a] == nil or b == nil or t[b] == nil then return false end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
52 -- only one timestamp given, this is the newer one
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
53 if t[a].timestamp ~= nil and t[b].timestamp == nil then return true end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
54 if t[a].timestamp == nil and t[b].timestamp ~= nil then return false end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
55 -- both timestamps given, sort normally
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
56 if t[a].timestamp ~= nil and t[b].timestamp ~= nil then return t[a].timestamp > t[b].timestamp end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
57 return false -- normally not reached
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
58 end)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
59 return orderedIndex
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
60 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
61 local function orderedNext(t, state)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
62 -- Equivalent of the next function, but returns the keys in timestamp
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
63 -- order. We use a temporary ordered key table that is stored in the
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
64 -- table being iterated.
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
65
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
66 local key = nil
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
67 --print("orderedNext: state = "..tostring(state) )
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
68 if state == nil then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
69 -- the first time, generate the index
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
70 t.__orderedIndex = __genOrderedIndex( t )
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
71 key = t.__orderedIndex[1]
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
72 else
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
73 -- fetch the next value
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
74 for i = 1, #t.__orderedIndex do
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
75 if t.__orderedIndex[i] == state then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
76 key = t.__orderedIndex[i+1]
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
77 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
78 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
79 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
80
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
81 if key then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
82 return key, t[key]
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
83 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
84
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
85 -- no more value to return, cleanup
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
86 t.__orderedIndex = nil
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
87 return
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
88 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
89 local function orderedPairs(t)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
90 -- Equivalent of the pairs() function on tables. Allows to iterate
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
91 -- in order
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
92 return orderedNext, t, nil
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
93 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
94
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
95 -- small helper function to return new table with only "maximum" elements containing only the newest entries
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
96 local function reduce_table(table, maximum)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
97 local count = 0;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
98 local result = {};
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
99 for key, value in orderedPairs(table) do
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
100 count = count + 1;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
101 if count > maximum then break end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
102 result[key] = value;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
103 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
104 return result;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
105 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
106
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
107 local push_store = (function()
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
108 local store = module:open_store();
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
109 local push_services = {};
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
110 local api = {};
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
111 function api:get(user)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
112 if not push_services[user] then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
113 local err;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
114 push_services[user], err = store:get(user);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
115 if not push_services[user] and err then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
116 module:log("warn", "Error reading web push notification storage for user '%s': %s", user, tostring(err));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
117 push_services[user] = {};
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
118 return push_services[user], false;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
119 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
120 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
121 if not push_services[user] then push_services[user] = {} end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
122 return push_services[user], true;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
123 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
124 function api:set(user, data)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
125 push_services[user] = reduce_table(data, max_push_devices);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
126 local ok, err = store:set(user, push_services[user]);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
127 if not ok then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
128 module:log("error", "Error writing web push notification storage for user '%s': %s", user, tostring(err));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
129 return false;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
130 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
131 return true;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
132 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
133 function api:set_identifier(user, push_identifier, data)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
134 local services = self:get(user);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
135 services[push_identifier] = data;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
136 return self:set(user, services);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
137 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
138 return api;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
139 end)();
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
140
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
141 local function push_enable(event)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
142 local origin, stanza = event.origin, event.stanza;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
143 local enable = stanza.tags[1];
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
144 origin.log("debug", "Attempting to enable web push notifications");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
145 -- MUST contain a 'href' attribute of the XMPP Push Service being enabled
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
146 local push_endpoint = nil;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
147 local push_auth = nil;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
148 local push_p256dh = nil;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
149
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
150 local endpoint_tag = enable:get_child('endpoint');
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
151 if endpoint_tag ~= nil then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
152 push_endpoint = endpoint_tag:get_text();
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
153 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
154 local auth_tag = enable:get_child('auth');
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
155 if auth_tag ~= nil then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
156 push_auth = auth_tag:get_text();
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
157 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
158 local p256dh_tag = enable:get_child('p256dh');
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
159 if p256dh_tag ~= nil then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
160 push_p256dh = p256dh_tag:get_text();
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
161 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
162 if not push_endpoint or not push_auth or not push_p256dh then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
163 origin.log("debug", "Web Push notification enable request missing 'endpoint', 'auth', or 'p256dh' tags");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
164 origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing enable child tag"));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
165 return true;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
166 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
167 local push_identifier = "foo";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
168 local push_service = push_endpoint;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
169 local ok = push_store:set_identifier(origin.username, push_identifier, push_service);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
170 if not ok then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
171 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
172 else
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
173 origin.push_identifier = push_identifier;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
174 origin.push_settings = push_service;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
175 origin.log("info", "Web Push notifications enabled for %s (%s)", tostring(stanza.attr.from), tostring(origin.push_identifier));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
176 origin.send(st.reply(stanza));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
177 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
178 return true;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
179 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
180 module:hook("iq-set/self/"..xmlns_webpush..":enable", push_enable);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
181
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
182 -- module:hook("iq-set/self/"..xmlns_webpush..":disable", push_disable);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
183
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
184 -- small helper function to extract relevant push settings
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
185 local function get_push_settings(stanza, session)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
186 local to = stanza.attr.to;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
187 local node = to and jid.split(to) or session.username;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
188 local user_push_services = push_store:get(node);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
189 return node, user_push_services;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
190 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
191
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
192 local function log_http_req(response_body, response_code, response)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
193 module:log("debug", "FOO: response_body: %s; response_code: %s; response: %s", response_body, tostring(response_code), tostring(response));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
194 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
195
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
196 local function handle_notify_request(stanza, node, user_push_services, log_push_decline)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
197 local pushes = 0;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
198 if not user_push_services or next(user_push_services) == nil then return pushes end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
199
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
200 for push_identifier, push_info in pairs(user_push_services) do
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
201 local send_push = true; -- only send push to this node when not already done for this stanza or if no stanza is given at all
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
202 if stanza then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
203 if not stanza._push_notify then stanza._push_notify = {}; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
204 if stanza._push_notify[push_identifier] then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
205 if log_push_decline then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
206 module:log("debug", "Already sent push notification for %s@%s to %s", node, module.host, tostring(push_info));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
207 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
208 send_push = false;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
209 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
210 stanza._push_notify[push_identifier] = true;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
211 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
212
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
213 if send_push then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
214 local headers = { TTL = "60" };
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
215 http.request(push_info, { method = "POST", headers = headers }, log_http_req);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
216 pushes = pushes + 1;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
217 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
218 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
219 return pushes;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
220 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
221
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
222 -- publish on offline message
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
223 module:hook("message/offline/handle", function(event)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
224 local node, user_push_services = get_push_settings(event.stanza, event.origin);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
225 module:log("debug", "Invoking web push handle_notify_request() for offline stanza");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
226 handle_notify_request(event.stanza, node, user_push_services, true);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
227 end, 1);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
228
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
229 -- is this push a high priority one (this is needed for ios apps not using voip pushes)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
230 local function is_important(stanza)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
231 local st_name = stanza and stanza.name or nil;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
232 if not st_name then return false; end -- nonzas are never important here
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
233 if st_name == "presence" then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
234 return false; -- same for presences
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
235 elseif st_name == "message" then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
236 -- unpack carbon copies
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
237 local stanza_direction = "in";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
238 local carbon;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
239 local st_type;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
240 -- support carbon copied message stanzas having an arbitrary message-namespace or no message-namespace at all
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
241 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:2}/forwarded/message"); end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
242 if not carbon then carbon = find(stanza, "{urn:xmpp:carbons:1}/forwarded/message"); end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
243 stanza_direction = carbon and stanza:child_with_name("sent") and "out" or "in";
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
244 if carbon then stanza = carbon; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
245 st_type = stanza.attr.type;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
246
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
247 -- headline message are always not important
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
248 if st_type == "headline" then return false; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
249
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
250 -- carbon copied outgoing messages are not important
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
251 if carbon and stanza_direction == "out" then return false; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
252
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
253 -- We can't check for body contents in encrypted messages, so let's treat them as important
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
254 -- Some clients don't even set a body or an empty body for encrypted messages
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
255
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
256 -- check omemo https://xmpp.org/extensions/inbox/omemo.html
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
257 if stanza:get_child("encrypted", "eu.siacs.conversations.axolotl") or stanza:get_child("encrypted", "urn:xmpp:omemo:0") then return true; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
258
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
259 -- check xep27 pgp https://xmpp.org/extensions/xep-0027.html
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
260 if stanza:get_child("x", "jabber:x:encrypted") then return true; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
261
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
262 -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
263 if stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then return true; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
264
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
265 local body = stanza:get_child_text("body");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
266 if st_type == "groupchat" and stanza:get_child_text("subject") then return false; end -- groupchat subjects are not important here
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
267 return body ~= nil and body ~= ""; -- empty bodies are not important
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
268 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
269 return false; -- this stanza wasn't one of the above cases --> it is not important, too
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
270 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
271
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
272 -- publish on unacked smacks message
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
273 local function process_smacks_stanza(stanza, session)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
274 if session.push_identifier then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
275 session.log("debug", "Invoking web push handle_notify_request() for smacks queued stanza");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
276 local user_push_services = {[session.push_identifier] = session.push_settings};
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
277 local node = get_push_settings(stanza, session);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
278 if handle_notify_request(stanza, node, user_push_services, true) ~= 0 then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
279 if session.hibernating and not session.first_hibernated_push then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
280 -- if important stanzas are treated differently (pushed with last-message-body field set to dummy string)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
281 -- and the message was important (e.g. had a last-message-body field) OR if we treat all pushes equally,
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
282 -- then record the time of first push in the session for the smack module which will extend its hibernation
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
283 -- timeout based on the value of session.first_hibernated_push
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
284 if not dummy_body or (dummy_body and is_important(stanza)) then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
285 session.first_hibernated_push = os_time();
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
286 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
287 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
288 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
289 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
290 return stanza;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
291 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
292
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
293 local function process_smacks_queue(queue, session)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
294 if not session.push_identifier then return; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
295 local user_push_services = {[session.push_identifier] = session.push_settings};
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
296 local notified = { unimportant = false; important = false }
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
297 for i=1, #queue do
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
298 local stanza = queue[i];
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
299 local node = get_push_settings(stanza, session);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
300 local stanza_type = "unimportant"
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
301 if dummy_body and is_important(stanza) then stanza_type = "important"; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
302 if not notified[stanza_type] then -- only notify if we didn't try to push for this stanza type already
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
303 -- session.log("debug", "Invoking cloud handle_notify_request() for smacks queued stanza: %d", i);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
304 if handle_notify_request(stanza, node, user_push_services, false) ~= 0 then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
305 if session.hibernating and not session.first_hibernated_push then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
306 -- if important stanzas are treated differently (pushed with last-message-body field set to dummy string)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
307 -- and the message was important (e.g. had a last-message-body field) OR if we treat all pushes equally,
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
308 -- then record the time of first push in the session for the smack module which will extend its hibernation
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
309 -- timeout based on the value of session.first_hibernated_push
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
310 if not dummy_body or (dummy_body and is_important(stanza)) then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
311 session.first_hibernated_push = os_time();
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
312 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
313 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
314 session.log("debug", "Web Push handle_notify_request() > 0, not notifying for other queued stanzas of type %s", stanza_type);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
315 notified[stanza_type] = true
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
316 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
317 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
318 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
319 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
320
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
321 -- smacks hibernation is started
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
322 local function hibernate_session(event)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
323 local session = event.origin;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
324 local queue = event.queue;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
325 session.first_hibernated_push = nil;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
326 -- process unacked stanzas
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
327 process_smacks_queue(queue, session);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
328 -- process future unacked (hibernated) stanzas
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
329 filters.add_filter(session, "stanzas/out", process_smacks_stanza, -990);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
330 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
331
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
332 -- smacks hibernation is ended
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
333 local function restore_session(event)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
334 local session = event.resumed;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
335 if session then -- older smacks module versions send only the "intermediate" session in event.session and no session.resumed one
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
336 filters.remove_filter(session, "stanzas/out", process_smacks_stanza);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
337 session.first_hibernated_push = nil;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
338 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
339 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
340
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
341 -- smacks ack is delayed
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
342 local function ack_delayed(event)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
343 local session = event.origin;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
344 local queue = event.queue;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
345 -- process unacked stanzas (handle_notify_request() will only send push requests for new stanzas)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
346 process_smacks_queue(queue, session);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
347 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
348
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
349 -- archive message added
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
350 local function archive_message_added(event)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
351 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id }
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
352 -- only notify for new mam messages when at least one device is online
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
353 if not event.for_user or not host_sessions[event.for_user] then return; end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
354 local stanza = event.stanza;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
355 local user_session = host_sessions[event.for_user].sessions;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
356 local to = stanza.attr.to;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
357 to = to and jid.split(to) or event.origin.username;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
358
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
359 -- only notify if the stanza destination is the mam user we store it for
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
360 if event.for_user == to then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
361 local user_push_services = push_store:get(to);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
362 if next(user_push_services) == nil then return end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
363
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
364 -- only notify nodes with no active sessions (smacks is counted as active and handled separate)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
365 local notify_push_services = {};
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
366 for identifier, push_info in pairs(user_push_services) do
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
367 local identifier_found = nil;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
368 for _, session in pairs(user_session) do
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
369 -- module:log("debug", "searching for '%s': identifier '%s' for session %s", tostring(identifier), tostring(session.push_identifier), tostring(session.full_jid));
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
370 if session.push_identifier == identifier then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
371 identifier_found = session;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
372 break;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
373 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
374 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
375 if identifier_found then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
376 identifier_found.log("debug", "Not web push notifying '%s' of new MAM stanza (session still alive)", identifier);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
377 else
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
378 notify_push_services[identifier] = push_info;
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
379 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
380 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
381
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
382 handle_notify_request(event.stanza, to, notify_push_services, true);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
383 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
384 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
385
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
386 module:hook("smacks-hibernation-start", hibernate_session);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
387 module:hook("smacks-hibernation-end", restore_session);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
388 module:hook("smacks-ack-delayed", ack_delayed);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
389 module:hook("archive-message-added", archive_message_added);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
390
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
391 function module.command(arg)
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
392 print("TODO: Generate server keypair")
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
393 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
394
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
395 module:log("info", "Module loaded");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
396 function module.unload()
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
397 if module.unhook then
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
398 module:unhook("account-disco-info", account_disco_info);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
399 module:unhook("iq-set/self/"..xmlns_webpush..":enable", push_enable);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
400 -- module:unhook("iq-set/self/"..xmlns_webpush..":disable", push_disable);
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
401 end
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
402
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
403 module:log("info", "Module unloaded");
2cee9fcb318b Initial version of mod_web_push. WARNING: Do not use.
Maxime “pep” Buquet <pep@bouah.net>
parents:
diff changeset
404 end