diff --git a/functions/src/email-templates/market-comment.html b/functions/src/email-templates/market-comment.html index 8a472941..84118964 100644 --- a/functions/src/email-templates/market-comment.html +++ b/functions/src/email-templates/market-comment.html @@ -285,7 +285,6 @@ font-size: 14px; margin: 0; padding: 5px 0; - font-weight: bold; " valign="top" > @@ -302,7 +301,10 @@ " alt="" /> - {{commentorName}} + {{commentorName}} + {{betDescription}} diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 456a92fe..221c542f 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -1,5 +1,6 @@ import _ = require('lodash') import { Answer } from '../../common/answer' +import { Bet } from '../../common/bet' import { getProbability } from '../../common/calculate' import { Comment } from '../../common/comment' import { Contract } from '../../common/contract' @@ -21,7 +22,7 @@ type market_resolved_template = { const toDisplayResolution = ( outcome: string, - prob: number, + prob?: number, resolutions?: { [outcome: string]: number } ) => { if (outcome === 'MKT' && resolutions) return 'MULTI' @@ -30,7 +31,7 @@ const toDisplayResolution = ( YES: 'YES', NO: 'NO', CANCEL: 'N/A', - MKT: formatPercent(prob), + MKT: formatPercent(prob ?? 0), }[outcome] return display === undefined ? `#${outcome}` : display @@ -144,8 +145,9 @@ export const sendMarketCloseEmail = async ( export const sendNewCommentEmail = async ( userId: string, commentCreator: User, + contract: Contract, comment: Comment, - contract: Contract + bet: Bet ) => { const privateUser = await getPrivateUser(userId) if ( @@ -165,6 +167,11 @@ export const sendNewCommentEmail = async ( const { name: commentorName, avatarUrl: commentorAvatarUrl } = commentCreator const { text } = comment + const { amount, sale, outcome } = bet + const betDescription = `${sale ? 'sold' : 'bought'} M$ ${Math.round( + amount + )} of ${toDisplayResolution(outcome)}` + const subject = `Comment on ${question}` const from = `${commentorName} ` @@ -178,6 +185,7 @@ export const sendNewCommentEmail = async ( comment: text, marketUrl, unsubscribeUrl, + betDescription, }, { from } ) diff --git a/functions/src/on-create-comment.ts b/functions/src/on-create-comment.ts index 0b2788eb..3b52dc66 100644 --- a/functions/src/on-create-comment.ts +++ b/functions/src/on-create-comment.ts @@ -5,6 +5,7 @@ import * as _ from 'lodash' import { getContract, getUser, getValues } from './utils' import { Comment } from '../../common/comment' import { sendNewCommentEmail } from './emails' +import { Bet } from '../../common/bet' const firestore = admin.firestore() @@ -23,6 +24,14 @@ export const onCreateComment = functions.firestore const commentCreator = await getUser(comment.userId) if (!commentCreator) return + const betSnapshot = await firestore + .collection('contracts') + .doc(contractId) + .collection('bets') + .doc(comment.betId) + .get() + const bet = betSnapshot.data() as Bet + const comments = await getValues( firestore.collection('contracts').doc(contractId).collection('comments') ) @@ -34,7 +43,7 @@ export const onCreateComment = functions.firestore await Promise.all( recipientUserIds.map((userId) => - sendNewCommentEmail(userId, commentCreator, comment, contract) + sendNewCommentEmail(userId, commentCreator, contract, comment, bet) ) ) })