diff --git a/common/comment.ts b/common/comment.ts index 8fe25688..fe18346b 100644 --- a/common/comment.ts +++ b/common/comment.ts @@ -1,10 +1,14 @@ // Currently, comments are created after the bet, not atomically with the bet. // They're uniquely identified by the pair contractId/betId. export type Comment = { + id: string contractId: string betId: string + userId: string + text: string createdTime: number + // Denormalized, for rendering comments userName?: string userUsername?: string diff --git a/web/lib/firebase/comments.ts b/web/lib/firebase/comments.ts index d272581e..16fe4dfb 100644 --- a/web/lib/firebase/comments.ts +++ b/web/lib/firebase/comments.ts @@ -8,6 +8,7 @@ import { where, orderBy, } from 'firebase/firestore' + import { getValues, listenForValues } from './utils' import { db } from './init' import { User } from '../../../common/user' @@ -21,15 +22,20 @@ export async function createComment( commenter: User ) { const ref = doc(getCommentsCollection(contractId), betId) - return await setDoc(ref, { + + const comment: Comment = { + id: ref.id, contractId, betId, + userId: commenter.id, text, createdTime: Date.now(), userName: commenter.name, userUsername: commenter.username, userAvatarUrl: commenter.avatarUrl, - }) + } + + return await setDoc(ref, comment) } function getCommentsCollection(contractId: string) {