diff --git a/functions/src/email-templates/market-answer-comment.html b/functions/src/email-templates/market-answer-comment.html new file mode 100644 index 00000000..4e1a2bfa --- /dev/null +++ b/functions/src/email-templates/market-answer-comment.html @@ -0,0 +1,561 @@ + + + + + + Market comment + + + + + + + + + + + +
+
+ + + + +
+ + + + + + + +
+ Manifold Markets +
+ + + + + + + + + + + + + + + + +
+ Answer {{answerNumber}} +
+
+ {{answer}} +
+
+
+ + {{commentorName}} + {{betDescription}} +
+
+
+ {{comment}} +
+
+ +
+
+
+ +
+
+ + diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 221c542f..28850af8 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -147,7 +147,8 @@ export const sendNewCommentEmail = async ( commentCreator: User, contract: Contract, comment: Comment, - bet: Bet + bet: Bet, + answer?: Answer ) => { const privateUser = await getPrivateUser(userId) if ( @@ -168,27 +169,49 @@ export const sendNewCommentEmail = async ( const { text } = comment const { amount, sale, outcome } = bet - const betDescription = `${sale ? 'sold' : 'bought'} M$ ${Math.round( - amount - )} of ${toDisplayResolution(outcome)}` + let betDescription = `${sale ? 'sold' : 'bought'} M$ ${Math.round(amount)}` const subject = `Comment on ${question}` const from = `${commentorName} ` - await sendTemplateEmail( - privateUser.email, - subject, - 'market-comment', - { - commentorName, - commentorAvatarUrl: commentorAvatarUrl ?? '', - comment: text, - marketUrl, - unsubscribeUrl, - betDescription, - }, - { from } - ) + if (contract.outcomeType === 'FREE_RESPONSE') { + const answerText = answer?.text ?? '' + const answerNumber = `#${answer?.id ?? ''}` + + await sendTemplateEmail( + privateUser.email, + subject, + 'market-answer-comment', + { + answer: answerText, + answerNumber, + commentorName, + commentorAvatarUrl: commentorAvatarUrl ?? '', + comment: text, + marketUrl, + unsubscribeUrl, + betDescription, + }, + { from } + ) + } else { + betDescription = `${betDescription} of ${toDisplayResolution(outcome)}` + + await sendTemplateEmail( + privateUser.email, + subject, + 'market-comment', + { + commentorName, + commentorAvatarUrl: commentorAvatarUrl ?? '', + comment: text, + marketUrl, + unsubscribeUrl, + betDescription, + }, + { from } + ) + } } export const sendNewAnswerEmail = async ( diff --git a/functions/src/on-create-comment.ts b/functions/src/on-create-comment.ts index 3b52dc66..85af37ee 100644 --- a/functions/src/on-create-comment.ts +++ b/functions/src/on-create-comment.ts @@ -32,6 +32,10 @@ export const onCreateComment = functions.firestore .get() const bet = betSnapshot.data() as Bet + const answer = + contract.answers && + contract.answers.find((answer) => answer.id === bet.outcome) + const comments = await getValues( firestore.collection('contracts').doc(contractId).collection('comments') ) @@ -43,7 +47,14 @@ export const onCreateComment = functions.firestore await Promise.all( recipientUserIds.map((userId) => - sendNewCommentEmail(userId, commentCreator, contract, comment, bet) + sendNewCommentEmail( + userId, + commentCreator, + contract, + comment, + bet, + answer + ) ) ) })