Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

19 linesCodeBlameRaw
1/**
2 * The read mark: how far a member has read a conversation
3 * (`channel_members.last_read_id`). Every surface that shows messages
4 * marks them read through it, whichever it is: the conversation in Chat,
5 * the Ask panel, Home's Summarize, the phone app.
6 */
7
8/**
9 * Moves `principal`'s read mark in `channelId` up to `id`. Only forward:
10 * reading an old thread does not mark newer messages unread. Says whether
11 * it moved, so the read is told to their tabs and devices only then.
12 */
13export async function markReadUpTo(db: D1Database, channelId: string, principal: string, id: string): Promise<boolean> {
14 const changed = await db
15 .prepare("UPDATE channel_members SET last_read_id = ?1 WHERE channel_id = ?2 AND principal = ?3 AND (last_read_id IS NULL OR last_read_id < ?1)")
16 .bind(id, channelId, principal)
17 .run();
18 return changed.meta.changes > 0;
19}