From cd9f0535f2e52db986f40aff179731ab608d1d1f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 31 Jan 2023 23:06:07 +0300 Subject: WebPush: cleanup expired tokens --- vnext/server/sender.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'vnext/server/sender.js') diff --git a/vnext/server/sender.js b/vnext/server/sender.js index 7adb1ceb..db006233 100644 --- a/vnext/server/sender.js +++ b/vnext/server/sender.js @@ -69,7 +69,7 @@ export function sendNotification(productionIds, sandboxIds, data) { log(`${badTokens.length} APNS tokens deleted`); } }); - results.filter(r => r.method === 'fcm') + results.filter(r => r.method === 'gcm') .forEach(async r => { let badTokens = r.message.filter(m => m.errorMsg === 'NotRegistered' || m.errorMsg === 'MismatchSenderId').map(m => { return { 'type': 'fcm', 'token': m.regId }; @@ -89,6 +89,16 @@ export function sendNotification(productionIds, sandboxIds, data) { log(`${badTokens.length} MPNS tokens deleted`); } }); + results.filter(r => r.method === 'webPush') + .forEach(async r => { + let badTokens = r.message.filter(m => m.error && m.error['statusCode'] === 410).map(m => { + return { 'type': 'web', 'token': JSON.stringify(m.regId) }; + }); + if (badTokens.length > 0) { + await deleteSubscribers(badTokens); + log(`${badTokens.length} WebPush tokens deleted`); + } + }); }) .catch((err) => { console.error(JSON.stringify(err)); }); } -- cgit v1.2.3