Fix fr comment emails (#247)

* Get answer outcome from comment

* Avoid db call if possible

* Include general comments note in comment emails

* Send market-comment on general comment
This commit is contained in:
Boa 2022-05-18 07:25:38 -06:00 committed by GitHub
parent 5adf430fad
commit 84c86552d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 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 (
@ -273,9 +274,8 @@ export const sendNewCommentEmail = async (
const subject = `Comment on ${question}`
const from = `${commentorName} <info@manifold.markets>`
if (contract.outcomeType === 'FREE_RESPONSE') {
const answerText = answer?.text ?? ''
const answerNumber = `#${answer?.id ?? ''}`
if (contract.outcomeType === 'FREE_RESPONSE' && answerId && answerText) {
const answerNumber = `#${answerId}`
await sendTemplateEmail(
privateUser.email,

View File

@ -34,7 +34,14 @@ export const onCreateComment = functions.firestore
let bet: Bet | undefined
let answer: Answer | undefined
if (comment.betId) {
if (comment.answerOutcome) {
answer =
contract.outcomeType === 'FREE_RESPONSE' && contract.answers
? contract.answers?.find(
(answer) => answer.id === comment.answerOutcome
)
: undefined
} else if (comment.betId) {
const betSnapshot = await firestore
.collection('contracts')
.doc(contractId)
@ -66,7 +73,8 @@ export const onCreateComment = functions.firestore
contract,
comment,
bet,
answer
answer?.text,
answer?.id
)
)
)