/** * ReadStateStore — the owner's per-channel read marker (#1400). * * One row per channel in `chat_read_state` holds `last_read_seq`: every message * with `seq <= last_read_seq` counts as read. Unread = messages that are not * the owner's own and not system notes with `seq > last_read_seq`. A channel * with no row has marker 0. * * Authorization lives in `ChatV2Service`; this store only does the SQL. * * @module services/chat-v2/sqlite/read-state.store */ import type { ChatDatabase } from './chat-db.js'; /** Read marker plus the unread count it implies, as sent on the wire. */ export interface ChannelReadState { channelId: string; lastReadSeq: number; unreadCount: number; } /** SQLite-backed store for the owner's read markers. */ export declare class ReadStateStore { private readonly db; constructor(db: ChatDatabase); /** * Current marker for a channel. * * @param channelId - Channel id * @returns `last_read_seq`, or 0 when the channel has no row */ getLastReadSeq(channelId: string): number; /** * Number of unread messages in a channel for a given marker. * * @param channelId - Channel id * @param lastReadSeq - Marker to count past * @returns Unread count */ countUnreadAfter(channelId: string, lastReadSeq: number): number; /** * Marker and unread count of one channel. * * @param channelId - Channel id * @returns The channel's read state */ get(channelId: string): ChannelReadState; /** * Move the marker forward only: `max(current, seq ?? channel max seq)`. * A `seq` beyond the channel's last message is clamped to it, so a stale or * bogus client value can never hide messages that arrive later. * * @param channelId - Channel id * @param seq - Read up to this seq; omit to read everything * @param nowIso - Clock for `updated_at` (tests) * @returns The new state */ markRead(channelId: string, seq?: number, nowIso?: string): ChannelReadState; /** * Mark the message at `seq` (and everything after it) unread: the marker * becomes `seq - 1`. May move backward — that is the point. * * @param channelId - Channel id * @param seq - `seq` of the message to keep unread (>= 1) * @param nowIso - Clock for `updated_at` (tests) * @returns The new state */ markUnread(channelId: string, seq: number, nowIso?: string): ChannelReadState; /** * Channels (among `channelIds`) with unread messages, with their markers. * One grouped query instead of one per channel. * * @param channelIds - Candidate channel ids * @returns Only channels with `unreadCount > 0` */ listUnread(channelIds: string[]): ChannelReadState[]; /** * Drop a channel's marker (used when the channel is deleted). * * @param channelId - Channel id */ delete(channelId: string): void; /** Largest `seq` in a channel, 0 when empty. */ private maxSeq; /** Upsert the marker. */ private write; } //# sourceMappingURL=read-state.store.d.ts.map