add id, userId to comment

This commit is contained in:
mantikoros 2022-01-26 14:18:58 -06:00
parent 2ea05f8913
commit 55dabd2dc9
2 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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) {