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. // Currently, comments are created after the bet, not atomically with the bet.
// They're uniquely identified by the pair contractId/betId. // They're uniquely identified by the pair contractId/betId.
export type Comment = { export type Comment = {
id: string
contractId: string contractId: string
betId: string betId: string
userId: string
text: string text: string
createdTime: number createdTime: number
// Denormalized, for rendering comments // Denormalized, for rendering comments
userName?: string userName?: string
userUsername?: string userUsername?: string

View File

@ -8,6 +8,7 @@ import {
where, where,
orderBy, orderBy,
} from 'firebase/firestore' } from 'firebase/firestore'
import { getValues, listenForValues } from './utils' import { getValues, listenForValues } from './utils'
import { db } from './init' import { db } from './init'
import { User } from '../../../common/user' import { User } from '../../../common/user'
@ -21,15 +22,20 @@ export async function createComment(
commenter: User commenter: User
) { ) {
const ref = doc(getCommentsCollection(contractId), betId) const ref = doc(getCommentsCollection(contractId), betId)
return await setDoc(ref, {
const comment: Comment = {
id: ref.id,
contractId, contractId,
betId, betId,
userId: commenter.id,
text, text,
createdTime: Date.now(), createdTime: Date.now(),
userName: commenter.name, userName: commenter.name,
userUsername: commenter.username, userUsername: commenter.username,
userAvatarUrl: commenter.avatarUrl, userAvatarUrl: commenter.avatarUrl,
}) }
return await setDoc(ref, comment)
} }
function getCommentsCollection(contractId: string) { function getCommentsCollection(contractId: string) {