Skip to content

Commit

Permalink
Merge pull request #7930 from ForumMagnum/fix-mistakes-from-dialogue-…
Browse files Browse the repository at this point in the history
…comment-count-PR

Fix mistakes in Update Comment Count PR
  • Loading branch information
Raemon committed Oct 4, 2023
2 parents dd9144f + dcb24ee commit b7e99a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Binary file removed bun.lockb
Binary file not shown.
18 changes: 12 additions & 6 deletions packages/lesswrong/server/callbacks/commentCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ getCollectionHooks("Comments").newSync.add(async function CommentsNewOperations
if (comment.postId) {
const lastCommentedAt = new Date()

if (!comment.debateResponse) {
await Posts.rawUpdateOne(comment.postId, {
$set: {lastCommentedAt},
})
}
// Debate responses should not trigger lastCommentedAt updates
// (we're using a Promise.resolve() here to make sure we always have a promise to await)
const updateLastCommentedAtPromise = comment.debateResponse
? Promise.resolve()
: Posts.rawUpdateOne(comment.postId, {$set: {lastCommentedAt}})

// we're updating the comment author's lastVisitedAt time for the post as well,
// so that their comment doesn't cause the post to look like it has unread comments
await ReadStatuses.rawUpdateOne({
const updateReadStatusesPromise = ReadStatuses.rawUpdateOne({
postId: comment.postId,
userId: comment.userId,
tagId: null,
Expand All @@ -112,6 +112,12 @@ getCollectionHooks("Comments").newSync.add(async function CommentsNewOperations
lastUpdated: lastCommentedAt
}
})

await Promise.all([
updateLastCommentedAtPromise,
updateReadStatusesPromise
])

} else if (comment.tagId) {
const fieldToSet = comment.tagCommentType === "SUBFORUM" ? "lastSubforumCommentAt" : "lastCommentedAt"
await Tags.rawUpdateOne(comment.tagId, {
Expand Down

0 comments on commit b7e99a4

Please sign in to comment.