Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import type { MemberProfile } from "@g1t/contracts"; | |
| 5 | ||
| 6 | import { conversationHref, countsAfterRead, messageDeliveries, preview, recipients, type Person } from "./notify.ts"; | |
| 7 | ||
| 8 | const person = (id: string, username: string, muted = false): Person => ({ key: `user:${id}`, user_id: id, username, muted }); | |
| 9 | const ana = person("u1", "ana"); | |
| 10 | const bo = person("u2", "bo"); | |
| 11 | const cy = person("u3", "cy", true); | |
| 12 | ||
| 13 | const kinds = (list: ReturnType<typeof recipients>) => Object.fromEntries(list.map((r) => [r.user_id, r.kind])); | |
| 14 | ||
| 15 | test("a direct message notifies everyone else in it, muted or not, never the author", () => { | |
| 16 | const out = recipients({ author: "user:u1", channelKind: "dm", people: [ana, bo, cy], mentioned: [], thread: null }); | |
| 17 | assert.deepEqual(kinds(out), { u2: "dm", u3: "dm" }); | |
| 18 | }); | |
| 19 | ||
| 20 | test("in a channel, a mention notifies the person named even when muted; the rest only count", () => { | |
| 21 | const out = recipients({ author: "user:u1", channelKind: "channel", people: [ana, bo, cy], mentioned: ["CY"], thread: null }); | |
| 22 | assert.deepEqual(kinds(out), { u2: null, u3: "mention" }); | |
| 23 | assert.deepEqual( | |
| 24 | out.map((r) => [r.user_id, r.mentioned, r.muted]), | |
| 25 | [ | |
| 26 | ["u2", false, false], | |
| 27 | ["u3", true, true], | |
| 28 | ], | |
| 29 | ); | |
| 30 | }); | |
| 31 | ||
| 32 | test("a reply notifies the people in its thread unless they muted the conversation", () => { | |
| 33 | const out = recipients({ author: "user:u1", channelKind: "channel", people: [ana, bo, cy], mentioned: [], thread: new Set(["user:u1", "user:u2", "user:u3"]) }); | |
| 34 | assert.deepEqual(kinds(out), { u2: "thread_reply", u3: null }); | |
| 35 | }); | |
| 36 | ||
| 37 | test("an agent's message notifies the people in its DM and counts for everyone", () => { | |
| 38 | const out = recipients({ author: "agent:a1", channelKind: "dm", people: [ana], mentioned: [], thread: null }); | |
| 39 | assert.deepEqual(kinds(out), { u1: "dm" }); | |
| 40 | }); | |
| 41 | ||
| 42 | test("deliveries: counts for everyone, a notification for those it is for, the author's count cleared", () => { | |
| 43 | const author: MemberProfile = { kind: "user", id: "u1", name: "ana", display_name: "Ana Lima", avatar: "abc", role: null, avatar_seed: null }; | |
| 44 | const items = messageDeliveries({ | |
| 45 | slug: "acme", | |
| 46 | channel: { id: "chn_1", kind: "channel", name: "design" }, | |
| 47 | message: { id: "msg_1", author: "user:u1", body: "hey **@bo** look", card_title: null, thread_root: null, created_at: "2026-10-08T00:00:00Z" }, | |
| 48 | author, | |
| 49 | recipients: recipients({ author: "user:u1", channelKind: "channel", people: [ana, bo, cy], mentioned: ["bo"], thread: null }), | |
| 50 | }); | |
| 51 | assert.equal(items.length, 3); | |
| 52 | const [toBo, toCy, self] = items; | |
| 53 | assert.deepEqual(toBo.counts, { channel_id: "chn_1", unread: 1, mentions: 1, muted: false }); | |
| 54 | assert.equal(toBo.notification?.kind, "mention"); | |
| 55 | assert.equal(toBo.notification?.title, "Ana Lima in #design"); | |
| 56 | assert.equal(toBo.notification?.body, "hey @bo look"); | |
| 57 | assert.equal(toBo.notification?.href, "/acme/-/chat/design"); | |
| 58 | assert.equal(toBo.notification?.actor.avatar, "abc"); | |
| 59 | assert.deepEqual(toCy.counts, { channel_id: "chn_1", unread: 1, mentions: 0, muted: true }); | |
| 60 | assert.equal(toCy.notification, null); | |
| 61 | assert.deepEqual(self, { user_id: "u1", workspace: "acme", counts: { channel_id: "chn_1", unread: 0, mentions: 0, set: true }, notification: null }); | |
| 62 | }); | |
| 63 | ||
| 64 | test("a reply links to its thread; a DM to the DM", () => { | |
| 65 | assert.equal(conversationHref("acme", { id: "chn_9", kind: "dm", name: null }, null), "/acme/-/chat/dm/chn_9"); | |
| 66 | assert.equal(conversationHref("acme", { id: "chn_1", kind: "channel", name: "ops" }, "msg_1"), "/acme/-/chat/ops?thread=msg_1"); | |
| 67 | }); | |
| 68 | ||
| 69 | test("previews are one short line without markup", () => { | |
| 70 | assert.equal(preview("**bold** and `code`\n\nnext [link](https://x)"), "bold and code next link"); | |
| 71 | assert.equal(preview("```\nlong code\n```"), "[code]"); | |
| 72 | assert.equal(preview("x".repeat(300)).length, 140); | |
| 73 | }); | |
| 74 | ||
| 75 | test("counts after a read: what is left past the mark, mentions included, never your own", () => { | |
| 76 | const rows = [ | |
| 77 | { channel_id: "c", id: "m3", author: "user:u2", mentions: " ana " }, | |
| 78 | { channel_id: "c", id: "m4", author: "user:u1", mentions: "" }, | |
| 79 | { channel_id: "c", id: "m5", author: "agent:a1", mentions: "" }, | |
| 80 | ]; | |
| 81 | assert.deepEqual(countsAfterRead(rows, "c", "user:u1", "ana", "m2"), { unread: 2, mentions: 1 }); | |
| 82 | assert.deepEqual(countsAfterRead([], "c", "user:u1", "ana", "m9"), { unread: 0, mentions: 0 }); | |
| 83 | }); |
This file's history is long; its oldest lines are credited to the oldest commit read.