aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-31 23:06:07 +0300
committerGravatar Vitaly Takmazov2023-01-31 23:06:18 +0300
commitcd9f0535f2e52db986f40aff179731ab608d1d1f (patch)
tree2d9f41028b25faab1fc4ce78a06d10d5df5f32fa
parent7f296b55669d6d3ff89713856def50aad11333b3 (diff)
WebPush: cleanup expired tokens
-rw-r--r--vnext/server/sender.js12
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)); });
}