diff options
author | Vitaly Takmazov | 2023-01-31 23:06:07 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-31 23:06:18 +0300 |
commit | cd9f0535f2e52db986f40aff179731ab608d1d1f (patch) | |
tree | 2d9f41028b25faab1fc4ce78a06d10d5df5f32fa /vnext/server/sender.js | |
parent | 7f296b55669d6d3ff89713856def50aad11333b3 (diff) |
WebPush: cleanup expired tokens
Diffstat (limited to 'vnext/server/sender.js')
-rw-r--r-- | vnext/server/sender.js | 12 |
1 files changed, 11 insertions, 1 deletions
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)); }); } |