Q142: a conversation is read only up to the message the reader actually saw
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
87c297dd45
commit
b18eb9ad14
11 files changed
+167
-55
No files matched your search
@@ -4,6 +4,7 @@ import type {
|
||||
AgentRecord,
|
||||
ChatMembershipRecord,
|
||||
ChatMessageRecord,
|
||||
ChatReadStateRecord,
|
||||
ChatSpaceRecord,
|
||||
EmployeeRecord,
|
||||
} from "../../src/shared/domain";
|
||||
@@ -103,3 +104,18 @@ describe("conversation pinning", () => {
|
||||
expect(conversations[0].preview).toContain("CEO:");
|
||||
});
|
||||
});
|
||||
|
||||
describe("unread counts", () => {
|
||||
test("count by position after the last read message, so a same-millisecond arrival is still unread", () => {
|
||||
const { spaces, memberships } = fixtures();
|
||||
const at = "2026-02-01T00:00:00.000Z";
|
||||
const messages = [message("m_read", "spc_general", CEO, at), message("m_same_ms", "spc_general", ENGINEER, at)];
|
||||
const unread = (readStates: ChatReadStateRecord[]) => buildConversations({ spaces, memberships, messages, readStates, employees, agents, currentEmployeeId: FOUNDER, ceoAgentId: CEO })
|
||||
.find((item) => item.space.id === "spc_general")!.unread;
|
||||
const state = (lastReadMessageId: string | null): ChatReadStateRecord => ({ orgId: ORG, employeeId: FOUNDER, spaceId: "spc_general", lastReadMessageId, lastReadAt: at });
|
||||
expect(unread([state("m_read")])).toBe(1);
|
||||
expect(unread([state("m_same_ms")])).toBe(0);
|
||||
// A read message older than the loaded window means every loaded message came after it.
|
||||
expect(unread([state("m_older_than_window")])).toBe(2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user