prosody: Add new module to load push registration for new sessions

This commit is contained in:
Matthew Wild 2021-10-18 14:15:56 +01:00
parent ff38924c47
commit dae151c7c9
3 changed files with 24 additions and 0 deletions

View File

@ -76,6 +76,7 @@ modules_enabled = {
"turncredentials";
"admin_shell";
"snikket_client_id";
"snikket_ios_preserve_push";
-- Spam/abuse management
"spam_reporting"; -- Allow users to report spam/abuse

View File

@ -133,6 +133,7 @@
- mod_invites_default_group
- mod_invites_bootstrap
- mod_snikket_client_id
- mod_snikket_ios_preserve_push
- name: "Install lua-ossl for encrypted push notifications"
apt:

View File

@ -0,0 +1,22 @@
-- The Snikket iOS client does not perform a push registration ("enable") on
-- every new connection (it connects every time the app is opened, so we want
-- to reduce round-trips and latency). This module attempts to locate a push
-- registration associated with the connecting client, and load it onto the
-- session so that mod_cloud_notify can find it.
local push_store = module:open_store("cloud_notify");
module:hook("resource-bind", function (event)
local session = event.session;
local client_id = session.client_id;
if not client_id then return; end
local push_registrations = push_store:get(session.username);
for push_identifier, push_registration in pairs(push_registrations) do
if push_registration.client_id == client_id then
session.push_identifier = push_identifier;
session.push_settings = push_registration;
module:log("debug", "Restored push registration for %s (%s)", client_id, push_identifier);
break;
end
end
end, 10);