Track per-employee chat read state and surface real unread counts
Adds chat_read_state migration (employee_id + space_id, last read message + timestamp) wired through ChatService.markSpaceRead, IPC markChatSpaceRead, and an effect in ChatPage that flushes the active space whenever the latest message id changes. Shell.computeBadges now derives the Messages badge from (message.createdAt > read_state.last_read_at) minus messages the viewer sent, so the sidebar shows true unread instead of total throughput.
This commit is contained in:
1 parent
b44e0e3657
commit
1f78ae6f2e
11 files changed
+100
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { DatabaseSync } from "node:sqlite";
|
||||
|
||||
const SCHEMA_VERSION = 4;
|
||||
const SCHEMA_VERSION = 5;
|
||||
|
||||
export function installSchema(db: DatabaseSync): void {
|
||||
db.exec(`
|
||||
@@ -484,5 +484,24 @@ export function installSchema(db: DatabaseSync): void {
|
||||
insert into schema_migrations(version, name, applied_at)
|
||||
values (4, 'files_pinned_and_scheduled_posts', datetime('now'));
|
||||
`);
|
||||
currentVersion = 4;
|
||||
}
|
||||
|
||||
if (currentVersion < 5) {
|
||||
db.exec(`
|
||||
create table if not exists chat_read_state (
|
||||
org_id text not null references organizations(id) on delete cascade,
|
||||
employee_id text not null references employees(id) on delete cascade,
|
||||
space_id text not null references chat_spaces(id) on delete cascade,
|
||||
last_read_message_id text references chat_messages(id) on delete set null,
|
||||
last_read_at text not null,
|
||||
primary key (employee_id, space_id)
|
||||
);
|
||||
|
||||
create index if not exists idx_chat_read_state_org on chat_read_state(org_id, employee_id);
|
||||
|
||||
insert into schema_migrations(version, name, applied_at)
|
||||
values (5, 'chat_read_state', datetime('now'));
|
||||
`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user