feat(shot-status): flag shots with new comments until marked read

A per-user ShotCommentRead marker records how far each person has read a
shot's comments. Comments and replies from others after the marker put an
orange "!" beside the shot code; its popover lists them and only "Mark
read" clears it. A chip filters the board to flagged shots and marks all
read. The migration marks existing comments as read so the board starts
clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
twotalesanimation
2026-10-17 09:06:25 +02:00
parent 0aedc4b1fa
commit 7a7088f2ad
7 changed files with 489 additions and 7 deletions
@@ -0,0 +1,30 @@
-- Per-user read marker for a shot's comments: the shot-status board flags a
-- shot with "!" while it has comments from others newer than the marker.
CREATE TABLE "shot_comment_reads" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"shotId" TEXT NOT NULL,
"readAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "shot_comment_reads_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX "shot_comment_reads_userId_shotId_key" ON "shot_comment_reads"("userId", "shotId");
CREATE INDEX "shot_comment_reads_shotId_idx" ON "shot_comment_reads"("shotId");
ALTER TABLE "shot_comment_reads" ADD CONSTRAINT "shot_comment_reads_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "shot_comment_reads" ADD CONSTRAINT "shot_comment_reads_shotId_fkey" FOREIGN KEY ("shotId") REFERENCES "shots"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- Everything already commented counts as read on launch, so the board starts
-- clean instead of flagging every shot that has ever had a note.
INSERT INTO "shot_comment_reads" ("id", "userId", "shotId", "readAt")
SELECT md5(u."id" || ':' || s."id"), u."id", s."id", CURRENT_TIMESTAMP
FROM "users" u
CROSS JOIN "shots" s
WHERE u."role" <> 'CLIENT'
AND EXISTS (
SELECT 1 FROM "comments" c
JOIN "versions" v ON v."id" = c."versionId"
LEFT JOIN "tasks" t ON t."id" = v."taskId"
WHERE COALESCE(v."shotId", t."shotId") = s."id"
);
+20
View File
@@ -263,6 +263,7 @@ model User {
createdTakes Take[] @relation("TakeCreator")
uploadedTakeAttachments TakeAttachment[] @relation("TakeAttachmentUploader")
assignedBoardItems BoardItem[] @relation("BoardItemAssignee")
shotCommentReads ShotCommentRead[]
@@map("users")
}
@@ -498,6 +499,7 @@ model Shot {
exports Export[]
deliveryRequestLines DeliveryRequestLine[]
boardItems BoardItem[]
commentReads ShotCommentRead[]
@@unique([projectId, shotCode])
@@map("shots")
@@ -675,6 +677,24 @@ model Approval {
@@map("approvals")
}
/// How far each user has read a shot's comments. A comment or reply on any of
/// the shot's versions, written by someone else after `readAt`, is new to that
/// user and flags the shot on the shot-status board until they mark it read.
/// No row = nothing read since the account was created.
model ShotCommentRead {
id String @id @default(cuid())
userId String
shotId String
readAt DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
shot Shot @relation(fields: [shotId], references: [id], onDelete: Cascade)
@@unique([userId, shotId])
@@index([shotId])
@@map("shot_comment_reads")
}
model Notification {
id String @id @default(cuid())
userId String