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, contract: Contract,
comment: Comment, comment: Comment,
bet?: Bet, bet?: Bet,
answer?: Answer answerText?: string,
answerId?: string
) => { ) => {
const privateUser = await getPrivateUser(userId) const privateUser = await getPrivateUser(userId)
if ( if (
@ -273,9 +274,8 @@ export const sendNewCommentEmail = async (
const subject = `Comment on ${question}` const subject = `Comment on ${question}`
const from = `${commentorName} <info@manifold.markets>` const from = `${commentorName} <info@manifold.markets>`
if (contract.outcomeType === 'FREE_RESPONSE') { if (contract.outcomeType === 'FREE_RESPONSE' && answerId && answerText) {
const answerText = answer?.text ?? '' const answerNumber = `#${answerId}`
const answerNumber = `#${answer?.id ?? ''}`
await sendTemplateEmail( await sendTemplateEmail(
privateUser.email, privateUser.email,

View File

@ -34,7 +34,14 @@ export const onCreateComment = functions.firestore
let bet: Bet | undefined let bet: Bet | undefined
let answer: Answer | 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 const betSnapshot = await firestore
.collection('contracts') .collection('contracts')
.doc(contractId) .doc(contractId)
@ -66,7 +73,8 @@ export const onCreateComment = functions.firestore
contract, contract,
comment, comment,
bet, bet,
answer answer?.text,
answer?.id
) )
) )
) )