From dae151c7c991de6750814ac9755a3dba1485c57f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 18 Oct 2021 14:15:56 +0100 Subject: [PATCH] prosody: Add new module to load push registration for new sessions --- ansible/files/prosody.cfg.lua | 1 + ansible/tasks/prosody.yml | 1 + .../mod_snikket_ios_preserve_push.lua | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 snikket-modules/mod_snikket_ios_preserve_push/mod_snikket_ios_preserve_push.lua diff --git a/ansible/files/prosody.cfg.lua b/ansible/files/prosody.cfg.lua index 912484e..962a3e1 100644 --- a/ansible/files/prosody.cfg.lua +++ b/ansible/files/prosody.cfg.lua @@ -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 diff --git a/ansible/tasks/prosody.yml b/ansible/tasks/prosody.yml index a913932..76a698b 100644 --- a/ansible/tasks/prosody.yml +++ b/ansible/tasks/prosody.yml @@ -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: diff --git a/snikket-modules/mod_snikket_ios_preserve_push/mod_snikket_ios_preserve_push.lua b/snikket-modules/mod_snikket_ios_preserve_push/mod_snikket_ios_preserve_push.lua new file mode 100644 index 0000000..428953f --- /dev/null +++ b/snikket-modules/mod_snikket_ios_preserve_push/mod_snikket_ios_preserve_push.lua @@ -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);