From 5ab86c8362e9980555d4b8bbc3dfdd76f154058f Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Tue, 20 Sep 2022 09:36:44 -0400 Subject: [PATCH] Check new weekly email notification preferences --- functions/src/reset-weekly-emails-flag.ts | 12 +++--------- functions/src/weekly-markets-emails.ts | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/functions/src/reset-weekly-emails-flag.ts b/functions/src/reset-weekly-emails-flag.ts index 5a71b65b..6556814e 100644 --- a/functions/src/reset-weekly-emails-flag.ts +++ b/functions/src/reset-weekly-emails-flag.ts @@ -2,20 +2,14 @@ import * as functions from 'firebase-functions' import * as admin from 'firebase-admin' import { getAllPrivateUsers } from './utils' -export const resetWeeklyEmailsFlag = functions - .runWith({ secrets: ['MAILGUN_KEY'] }) - // every Monday at 12 am PT (UTC -07:00) ( 12 hours before the emails will be sent) - .pubsub.schedule('0 7 * * 1') +export const resetWeeklyEmailsFlag = functions.pubsub // every Monday at 12 am PT (UTC -07:00) ( 12 hours before the emails will be sent) + .schedule('0 7 * * 1') .timeZone('Etc/UTC') .onRun(async () => { const privateUsers = await getAllPrivateUsers() - // get all users that haven't unsubscribed from weekly emails - const privateUsersToSendEmailsTo = privateUsers.filter((user) => { - return !user.unsubscribedFromWeeklyTrendingEmails - }) const firestore = admin.firestore() await Promise.all( - privateUsersToSendEmailsTo.map(async (user) => { + privateUsers.map(async (user) => { return firestore.collection('private-users').doc(user.id).update({ weeklyTrendingEmailSent: false, }) diff --git a/functions/src/weekly-markets-emails.ts b/functions/src/weekly-markets-emails.ts index 50f7195a..74b09e89 100644 --- a/functions/src/weekly-markets-emails.ts +++ b/functions/src/weekly-markets-emails.ts @@ -48,7 +48,7 @@ async function sendTrendingMarketsEmailsToAllUsers() { // get all users that haven't unsubscribed from weekly emails const privateUsersToSendEmailsTo = privateUsers.filter((user) => { return ( - !user.unsubscribedFromWeeklyTrendingEmails && + user.notificationPreferences.trending_markets.includes('email') && !user.weeklyTrendingEmailSent ) })