Send market-comment on general comment

This commit is contained in:
Ian Philips 2022-05-18 07:15:55 -06:00
parent 4dcc996503
commit 885b9f594d
2 changed files with 8 additions and 15 deletions

View File

@ -274,15 +274,15 @@ export const sendNewCommentEmail = async (
const subject = `Comment on ${question}`
const from = `${commentorName} <info@manifold.markets>`
if (contract.outcomeType === 'FREE_RESPONSE') {
const answerNumber = answerId ? `#${answerId}` : ''
if (contract.outcomeType === 'FREE_RESPONSE' && answerId && answerText) {
const answerNumber = `#${answerId}`
await sendTemplateEmail(
privateUser.email,
subject,
'market-answer-comment',
{
answer: answerText ?? '',
answer: answerText,
answerNumber,
commentorName,
commentorAvatarUrl: commentorAvatarUrl ?? '',

View File

@ -33,17 +33,14 @@ export const onCreateComment = functions.firestore
.update({ lastCommentTime, lastUpdatedTime: Date.now() })
let bet: Bet | undefined
let answerText: string | undefined
let answerId: string | undefined
let answer: Answer | undefined
if (comment.answerOutcome) {
const answer =
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')
@ -53,14 +50,10 @@ export const onCreateComment = functions.firestore
.get()
bet = betSnapshot.data() as Bet
const answer =
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>(
@ -80,8 +73,8 @@ export const onCreateComment = functions.firestore
contract,
comment,
bet,
answerText,
answerId
answer?.text,
answer?.id
)
)
)