Pull subscription checking out to userIsEmailSubscribed function
This commit is contained in:
parent
926688ae50
commit
6dead11c9a
|
@ -16,6 +16,10 @@ const from = {
|
||||||
from: 'David from Manifold <david@manifold.markets>',
|
from: 'David from Manifold <david@manifold.markets>',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const userIsEmailSubscribed = (user: PrivateUser | undefined, emailType: keyof PrivateUser): user is PrivateUser & {email: string} => {
|
||||||
|
return !!(user?.email && !user[emailType])
|
||||||
|
}
|
||||||
|
|
||||||
export const sendMarketResolutionEmail = async (
|
export const sendMarketResolutionEmail = async (
|
||||||
userId: string,
|
userId: string,
|
||||||
investment: number,
|
investment: number,
|
||||||
|
@ -28,10 +32,7 @@ export const sendMarketResolutionEmail = async (
|
||||||
resolutions?: { [outcome: string]: number }
|
resolutions?: { [outcome: string]: number }
|
||||||
) => {
|
) => {
|
||||||
const privateUser = await getPrivateUser(userId)
|
const privateUser = await getPrivateUser(userId)
|
||||||
if (
|
if (!userIsEmailSubscribed(privateUser, 'unsubscribedFromResolutionEmails'))
|
||||||
!privateUser?.email ||
|
|
||||||
privateUser.unsubscribedFromResolutionEmails
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
const user = await getUser(userId)
|
const user = await getUser(userId)
|
||||||
|
@ -147,10 +148,7 @@ export const sendOneWeekBonusEmail = async (
|
||||||
user: User,
|
user: User,
|
||||||
privateUser: PrivateUser
|
privateUser: PrivateUser
|
||||||
) => {
|
) => {
|
||||||
if (
|
if (!userIsEmailSubscribed(privateUser, 'unsubscribedFromGenericEmails'))
|
||||||
!privateUser?.email ||
|
|
||||||
privateUser.unsubscribedFromGenericEmails
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
const { name, id: userId } = user
|
const { name, id: userId } = user
|
||||||
|
@ -176,10 +174,7 @@ export const sendThankYouEmail = async (
|
||||||
user: User,
|
user: User,
|
||||||
privateUser: PrivateUser
|
privateUser: PrivateUser
|
||||||
) => {
|
) => {
|
||||||
if (
|
if (!userIsEmailSubscribed(privateUser, 'unsubscribedFromGenericEmails'))
|
||||||
!privateUser?.email ||
|
|
||||||
privateUser.unsubscribedFromGenericEmails
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
const { name, id: userId } = user
|
const { name, id: userId } = user
|
||||||
|
@ -205,10 +200,7 @@ export const sendMarketCloseEmail = async (
|
||||||
privateUser: PrivateUser,
|
privateUser: PrivateUser,
|
||||||
contract: Contract
|
contract: Contract
|
||||||
) => {
|
) => {
|
||||||
if (
|
if (!userIsEmailSubscribed(privateUser, 'unsubscribedFromResolutionEmails'))
|
||||||
!privateUser?.email ||
|
|
||||||
privateUser.unsubscribedFromResolutionEmails
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
const { username, name, id: userId } = user
|
const { username, name, id: userId } = user
|
||||||
|
@ -246,10 +238,8 @@ export const sendNewCommentEmail = async (
|
||||||
answerId?: string
|
answerId?: string
|
||||||
) => {
|
) => {
|
||||||
const privateUser = await getPrivateUser(userId)
|
const privateUser = await getPrivateUser(userId)
|
||||||
if (
|
|
||||||
!privateUser?.email ||
|
if (!userIsEmailSubscribed(privateUser, 'unsubscribedFromCommentEmails'))
|
||||||
privateUser.unsubscribedFromCommentEmails
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
const { question, creatorUsername, slug } = contract
|
const { question, creatorUsername, slug } = contract
|
||||||
|
@ -325,10 +315,7 @@ export const sendNewAnswerEmail = async (
|
||||||
if (answer.userId === userId) return
|
if (answer.userId === userId) return
|
||||||
|
|
||||||
const privateUser = await getPrivateUser(userId)
|
const privateUser = await getPrivateUser(userId)
|
||||||
if (
|
if (!userIsEmailSubscribed(privateUser, 'unsubscribedFromAnswerEmails'))
|
||||||
!privateUser?.email ||
|
|
||||||
privateUser.unsubscribedFromAnswerEmails
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
const { question, creatorUsername, slug } = contract
|
const { question, creatorUsername, slug } = contract
|
||||||
|
|
Loading…
Reference in New Issue
Block a user