Include general comments note in comment emails

This commit is contained in:
Ian Philips 2022-05-17 16:16:39 -06:00
parent 231bbb3517
commit 4dcc996503
2 changed files with 16 additions and 8 deletions

View File

@ -244,7 +244,8 @@ export const sendNewCommentEmail = async (
contract: Contract,
comment: Comment,
bet?: Bet,
answer?: Answer
answerText?: string,
answerId?: string
) => {
const privateUser = await getPrivateUser(userId)
if (
@ -274,15 +275,14 @@ export const sendNewCommentEmail = async (
const from = `${commentorName} <info@manifold.markets>`
if (contract.outcomeType === 'FREE_RESPONSE') {
const answerText = answer?.text ?? ''
const answerNumber = `#${answer?.id ?? ''}`
const answerNumber = answerId ? `#${answerId}` : ''
await sendTemplateEmail(
privateUser.email,
subject,
'market-answer-comment',
{
answer: answerText,
answer: answerText ?? '',
answerNumber,
commentorName,
commentorAvatarUrl: commentorAvatarUrl ?? '',

View File

@ -33,14 +33,17 @@ export const onCreateComment = functions.firestore
.update({ lastCommentTime, lastUpdatedTime: Date.now() })
let bet: Bet | undefined
let answer: Answer | undefined
let answerText: string | undefined
let answerId: string | undefined
if (comment.answerOutcome) {
answer =
const answer =
contract.outcomeType === 'FREE_RESPONSE' && contract.answers
? contract.answers?.find(
(answer) => answer.id === comment.answerOutcome
)
: undefined
answerText = answer?.text
answerId = answer?.id
} else if (comment.betId) {
const betSnapshot = await firestore
.collection('contracts')
@ -50,10 +53,14 @@ export const onCreateComment = functions.firestore
.get()
bet = betSnapshot.data() as Bet
answer =
const answer =
contract.outcomeType === 'FREE_RESPONSE' && contract.answers
? contract.answers.find((answer) => answer.id === bet?.outcome)
: undefined
answerText = answer?.text
answerId = answer?.id
} else if (contract.outcomeType === 'FREE_RESPONSE') {
answerText = 'General Comments'
}
const comments = await getValues<Comment>(
@ -73,7 +80,8 @@ export const onCreateComment = functions.firestore
contract,
comment,
bet,
answer
answerText,
answerId
)
)
)