From c880e164f93606cfc00d2b979de2664b4e261531 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sun, 1 May 2022 11:04:27 -0400 Subject: [PATCH] Track lastUpdatedTime --- common/contract.ts | 1 + functions/src/on-create-bet.ts | 3 ++- functions/src/on-create-comment.ts | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common/contract.ts b/common/contract.ts index ecad95bd..82a330b5 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -20,6 +20,7 @@ export type FullContract< visibility: 'public' | 'unlisted' createdTime: number // Milliseconds since epoch + lastUpdatedTime?: number // Updated on new bet or comment lastBetTime?: number lastCommentTime?: number closeTime?: number // When no more trading is allowed diff --git a/functions/src/on-create-bet.ts b/functions/src/on-create-bet.ts index 12e6e720..deaa4c4a 100644 --- a/functions/src/on-create-bet.ts +++ b/functions/src/on-create-bet.ts @@ -19,9 +19,10 @@ export const onCreateBet = functions.firestore throw new Error('Could not find contract corresponding with bet') const bet = change.data() as Bet + const lastBetTime = bet.createdTime await firestore .collection('contracts') .doc(contract.id) - .update({ lastBetTime: bet.createdTime }) + .update({ lastBetTime, lastUpdatedTime: Date.now() }) }) diff --git a/functions/src/on-create-comment.ts b/functions/src/on-create-comment.ts index d232e2ed..18fc6757 100644 --- a/functions/src/on-create-comment.ts +++ b/functions/src/on-create-comment.ts @@ -22,6 +22,7 @@ export const onCreateComment = functions.firestore throw new Error('Could not find contract corresponding with comment') const comment = change.data() as Comment + const lastCommentTime = comment.createdTime const commentCreator = await getUser(comment.userId) if (!commentCreator) throw new Error('Could not find contract creator') @@ -29,7 +30,7 @@ export const onCreateComment = functions.firestore await firestore .collection('contracts') .doc(contract.id) - .update({ lastCommentTime: comment.createdTime }) + .update({ lastCommentTime, lastUpdatedTime: Date.now() }) let bet: Bet | undefined let answer: Answer | undefined