Set email sent flag if skipped over
This commit is contained in:
parent
f7bf42d2e0
commit
3ed3b6fb42
|
@ -46,12 +46,14 @@ async function sendTrendingMarketsEmailsToAllUsers() {
|
||||||
? await getAllPrivateUsers()
|
? await getAllPrivateUsers()
|
||||||
: filterDefined([await getPrivateUser('6hHpzvRG0pMq8PNJs7RZj2qlZGn2')])
|
: filterDefined([await getPrivateUser('6hHpzvRG0pMq8PNJs7RZj2qlZGn2')])
|
||||||
// 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
|
||||||
return (
|
.filter((user) => {
|
||||||
user.notificationPreferences.trending_markets.includes('email') &&
|
return (
|
||||||
!user.weeklyTrendingEmailSent
|
user.notificationPreferences.trending_markets.includes('email') &&
|
||||||
)
|
!user.weeklyTrendingEmailSent
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
.slice(150) // Send the emails out in batches
|
||||||
log(
|
log(
|
||||||
'Sending weekly trending emails to',
|
'Sending weekly trending emails to',
|
||||||
privateUsersToSendEmailsTo.length,
|
privateUsersToSendEmailsTo.length,
|
||||||
|
@ -74,6 +76,7 @@ async function sendTrendingMarketsEmailsToAllUsers() {
|
||||||
trendingContracts.map((c) => c.question).join('\n ')
|
trendingContracts.map((c) => c.question).join('\n ')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: convert to Promise.all
|
||||||
for (const privateUser of privateUsersToSendEmailsTo) {
|
for (const privateUser of privateUsersToSendEmailsTo) {
|
||||||
if (!privateUser.email) {
|
if (!privateUser.email) {
|
||||||
log(`No email for ${privateUser.username}`)
|
log(`No email for ${privateUser.username}`)
|
||||||
|
@ -84,6 +87,9 @@ async function sendTrendingMarketsEmailsToAllUsers() {
|
||||||
})
|
})
|
||||||
if (contractsAvailableToSend.length < numContractsToSend) {
|
if (contractsAvailableToSend.length < numContractsToSend) {
|
||||||
log('not enough new, unbet-on contracts to send to user', privateUser.id)
|
log('not enough new, unbet-on contracts to send to user', privateUser.id)
|
||||||
|
await firestore.collection('private-users').doc(privateUser.id).update({
|
||||||
|
weeklyTrendingEmailSent: true,
|
||||||
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// choose random subset of contracts to send to user
|
// choose random subset of contracts to send to user
|
||||||
|
|
Loading…
Reference in New Issue
Block a user