(workspaceId: string)
| 7 | * Returns { isUnread, lastReadTimestamp, recencyTimestamp } for flexibility. |
| 8 | */ |
| 9 | export function useWorkspaceUnread(workspaceId: string): { |
| 10 | isUnread: boolean; |
| 11 | lastReadTimestamp: number | null; |
| 12 | recencyTimestamp: number | null; |
| 13 | } { |
| 14 | // Missing lastRead means this workspace has no persisted read baseline yet. |
| 15 | // Treat that as "implicitly read" until we observe an explicit read event, |
| 16 | // instead of coercing to epoch (0) which marks legacy workspaces unread forever. |
| 17 | const [lastReadTimestamp] = usePersistedState<number | null>( |
| 18 | getWorkspaceLastReadKey(workspaceId), |
| 19 | null, |
| 20 | { |
| 21 | listener: true, |
| 22 | } |
| 23 | ); |
| 24 | const { recencyTimestamp } = useWorkspaceSidebarState(workspaceId); |
| 25 | const isUnread = |
| 26 | recencyTimestamp !== null && lastReadTimestamp !== null && recencyTimestamp > lastReadTimestamp; |
| 27 | |
| 28 | return { isUnread, lastReadTimestamp, recencyTimestamp }; |
| 29 | } |
no test coverage detected