diff --git a/functions/src/notifications/reengagement.ts b/functions/src/notifications/reengagement.ts index 131916e1..fe92e5c4 100644 --- a/functions/src/notifications/reengagement.ts +++ b/functions/src/notifications/reengagement.ts @@ -1,6 +1,7 @@ import * as functions from 'firebase-functions' import * as admin from 'firebase-admin' import { recipientInQuietHours } from './quietHours' +import { pruneDeadTokens } from './pruneTokens' const THREE_DAYS_MS = 3 * 24 * 60 * 60 * 1000 const TEN_DAYS_MS = 10 * 24 * 60 * 60 * 1000 @@ -102,7 +103,7 @@ async function sendNudge( const tokens = await getUserTokens(db, userId, userData) if (tokens.length === 0) return - await Promise.allSettled( + const results = await Promise.allSettled( tokens.map((token) => messaging.send({ token, @@ -118,6 +119,7 @@ async function sendNudge( }) ) ) + await pruneDeadTokens(db, userId, tokens, results) } async function getUserTokens(