Check new weekly email notification preferences
This commit is contained in:
parent
c6a60a6678
commit
5ab86c8362
|
@ -2,20 +2,14 @@ import * as functions from 'firebase-functions'
|
||||||
import * as admin from 'firebase-admin'
|
import * as admin from 'firebase-admin'
|
||||||
import { getAllPrivateUsers } from './utils'
|
import { getAllPrivateUsers } from './utils'
|
||||||
|
|
||||||
export const resetWeeklyEmailsFlag = functions
|
export const resetWeeklyEmailsFlag = functions.pubsub // every Monday at 12 am PT (UTC -07:00) ( 12 hours before the emails will be sent)
|
||||||
.runWith({ secrets: ['MAILGUN_KEY'] })
|
.schedule('0 7 * * 1')
|
||||||
// every Monday at 12 am PT (UTC -07:00) ( 12 hours before the emails will be sent)
|
|
||||||
.pubsub.schedule('0 7 * * 1')
|
|
||||||
.timeZone('Etc/UTC')
|
.timeZone('Etc/UTC')
|
||||||
.onRun(async () => {
|
.onRun(async () => {
|
||||||
const privateUsers = await getAllPrivateUsers()
|
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()
|
const firestore = admin.firestore()
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
privateUsersToSendEmailsTo.map(async (user) => {
|
privateUsers.map(async (user) => {
|
||||||
return firestore.collection('private-users').doc(user.id).update({
|
return firestore.collection('private-users').doc(user.id).update({
|
||||||
weeklyTrendingEmailSent: false,
|
weeklyTrendingEmailSent: false,
|
||||||
})
|
})
|
||||||
|
|
|
@ -48,7 +48,7 @@ async function sendTrendingMarketsEmailsToAllUsers() {
|
||||||
// get all users that haven't unsubscribed from weekly emails
|
// get all users that haven't unsubscribed from weekly emails
|
||||||
const privateUsersToSendEmailsTo = privateUsers.filter((user) => {
|
const privateUsersToSendEmailsTo = privateUsers.filter((user) => {
|
||||||
return (
|
return (
|
||||||
!user.unsubscribedFromWeeklyTrendingEmails &&
|
user.notificationPreferences.trending_markets.includes('email') &&
|
||||||
!user.weeklyTrendingEmailSent
|
!user.weeklyTrendingEmailSent
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user