Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

A tag brings an unfollowed thread back, like Slack (#3010) (#3061)

harness-for-autonomous[bot]b82c85cba2b8
diff --git a/backend/integration/superTabFollowedThreads.test.ts b/backend/integration/superTabFollowedThreads.test.ts
index 0fc10a40a..751e02902 100644
--- a/backend/integration/superTabFollowedThreads.test.ts
+++ b/backend/integration/superTabFollowedThreads.test.ts
@@ -278,6 +278,35 @@ describe('the inbox honors Follow and Unfollow', () => {
})
})
+describe('a tag brings an unfollowed thread back (task #3010, as in Slack)', () => {
+ /** Owner's thread in Web that peer read and then unfollowed. */
+ async function unfollowedScene() {
+ const s = await scene()
+ const [root, other] = await insert(s.tabId, s.web, [{ text: 'Owner root', author: personAuthor(owner) }, { text: 'Other root', author: personAuthor(owner) }])
+ await markRead(s.tabId, s.web, await newestIn(s.tabId, s.web), peer)
+ await insert(s.tabId, s.web, [{ text: 'Worker reply', author: agentAuthor(s.worker), thread: root }, { text: 'Worker reply 2', author: agentAuthor(s.worker), thread: other }])
+ for (const each of [root!, other!]) await follow(s.tabId, s.web, each, false, peer)
+ return { ...s, root: root!, other: other! }
+ }
+ const reply = (s: { tabId: string; web: string }, root: string, mentions: string[]) => store.execute(owner, s.tabId, { operationId: randomUUID(),
+ command: { type: 'message.send', conversationId: s.web, text: 'A reply.', replyTo: root, recipientIds: [], mentions } })
+ const listedRoots = async (tabId: string) => { const { unread, read } = (await threads(tabId, peer)).body.data; return roots([...unread, ...read]) }
+
+ it('puts the thread back on the tagged person\'s Threads page, and a reply that tags nobody keeps it off', async () => {
+ const s = await unfollowedScene()
+ expect(await listedRoots(s.tabId)).toEqual([])
+ await reply(s, s.other, [])
+ expect(await stored(s.tabId, s.other, peer)).toEqual([expect.objectContaining({ follow: false })])
+ expect(await listedRoots(s.tabId)).toEqual([])
+ await reply(s, s.root, [peer.sub])
+ expect(await stored(s.tabId, s.root, peer)).toEqual([expect.objectContaining({ follow: null })])
+ expect(await listedRoots(s.tabId)).toEqual(['Owner root'])
+ // Only the tagged thread, and only the tagged person's mark.
+ expect(await stored(s.tabId, s.other, peer)).toEqual([expect.objectContaining({ follow: false })])
+ expect(await stored(s.tabId, s.root, owner)).toEqual([])
+ })
+})
+
describe('a thread reply past the person\'s thread mark, though the chat\'s mark is further on', () => {
/** Peer's thread in Web with a reply peer read; a later thread-only reply; then a main message peer reads in the chat. With
* `opened`, peer read the thread to its first reply on some device; with `followOnly`, peer only followed it. */
diff --git a/backend/src/superTabs/mentions.ts b/backend/src/superTabs/mentions.ts
index 01cc5785c..71f7b84e3 100644
--- a/backend/src/superTabs/mentions.ts
+++ b/backend/src/superTabs/mentions.ts
@@ -165,6 +165,20 @@ export async function writeMentions(tx: Tx, tabId: string, state: SuperTabState,
createdAt: new Date(now), resolvedAt: null, resolvedBy: null, ...(message.holdMentions ? { holdUntil: new Date(now + NO_WORKER_GRACE_MS) } : {}),
})))
if (data.length) await tx.superTabMention.createMany({ data })
+ await bringBackUnfollowed(tx, tabId, messages, now)
+}
+
+/** A tag in a thread reply puts the thread back on the tagged person's Threads page, as in Slack: their Unfollow of it is cleared
+ * (follow back to no choice; updatedAt moves so their other devices read the change), in the write of the tag. A reply that tags
+ * nobody leaves an Unfollow as it is, and a send that tags nobody in a thread sends no command. At most MAX_MENTIONS ids a message,
+ * in one raw update by `_id`, which Prisma would send as $expr (hotFilters.test.ts). */
+async function bringBackUnfollowed(tx: Tx, tabId: string, messages: MessageDraft[], now: number): Promise<void> {
+ const ids = [...new Set(messages.flatMap(message => message.thread && message.thread !== message.id ? (message.mentions ?? []).map(personId =>
+ stableId(tabId, message.conversationId, message.thread!, personId)) : []))]
+ if (!ids.length) return
+ const answer = await tx.$runCommandRaw({ update: 'SuperTabThreadMark', updates: [{ q: { _id: { $in: ids }, tabId, follow: false },
+ u: { $set: { follow: null, updatedAt: { $date: new Date(now).toISOString() } } }, multi: true }] }) as { writeErrors?: unknown[] }
+ if (answer.writeErrors?.length) throw new Error('The database refused some thread follows')
}
/** Any post by the tagged person in that conversation answers every earlier tag there, in a thread or not. */
diff --git a/backend/src/superTabs/mentionsUnfollow.test.ts b/backend/src/superTabs/mentionsUnfollow.test.ts
new file mode 100644
index 000000000..7a602e8e2
--- /dev/null
+++ b/backend/src/superTabs/mentionsUnfollow.test.ts
@@ -0,0 +1,59 @@
+import { describe, expect, it } from 'vitest'
+import type { Prisma } from '@prisma/client'
+import { writeMentions } from './mentions.js'
+import { stableId, type MessageDraft, type SuperTabState } from './model.js'
+
+// A tag in a thread the person unfollowed brings it back (Slack, anh Dee 11-05): the tag's write clears their Unfollow.
+
+const NOW = 5_000
+const state = { conversations: [{ id: 'chat', projectId: 'p' }] } as unknown as SuperTabState
+const author = { kind: 'agent' as const, id: 'worker', name: 'Worker', membershipGeneration: 'g' }
+const draft = (id: string, mentions: string[], thread?: string): MessageDraft =>
+ ({ id, conversationId: 'chat', author, text: 'Please look.', replyTo: null, recipients: [], mentions, ...(thread ? { thread } : {}) })
+
+/** A transaction that logs its writes: the tag rows created and the raw commands sent. */
+function fakeTx() {
+ const created: unknown[] = []
+ const commands: Array<Record<string, any>> = []
+ const tx = {
+ superTabMention: { async createMany({ data }: { data: unknown[] }) { created.push(...data) } },
+ async $runCommandRaw(command: Record<string, any>) { commands.push(command); return { nModified: 1 } },
+ }
+ return { tx: tx as unknown as Prisma.TransactionClient, created, commands }
+}
+
+describe('a tag in a thread brings back an unfollowed thread', () => {
+ it('clears the tagged person\'s Unfollow of the thread, in the write of the tag', async () => {
+ const { tx, created, commands } = fakeTx()
+ await writeMentions(tx, 'tab', state, [draft('reply', ['peer', 'third'], 'root')], NOW)
+ expect(created).toHaveLength(2)
+ expect(commands).toHaveLength(1)
+ const [update] = commands[0]!.updates
+ expect(commands[0]!.update).toBe('SuperTabThreadMark')
+ expect(update.q).toEqual({ _id: { $in: [stableId('tab', 'chat', 'root', 'peer'), stableId('tab', 'chat', 'root', 'third')] }, tabId: 'tab', follow: false })
+ // Back to no choice: the tag now puts the thread on their list. updatedAt moves so their other devices read the change.
+ expect(update.u).toEqual({ $set: { follow: null, updatedAt: { $date: new Date(NOW).toISOString() } } })
+ expect(update.multi).toBe(true)
+ })
+
+ it('keeps an Unfollow when the reply tags nobody, and sends no extra command', async () => {
+ const { tx, created, commands } = fakeTx()
+ await writeMentions(tx, 'tab', state, [draft('reply', [], 'root'), draft('plain', [])], NOW)
+ expect(created).toHaveLength(0)
+ expect(commands).toEqual([])
+ })
+
+ it('leaves an Unfollow alone when the tag is in the chat, not in a thread', async () => {
+ const { tx, created, commands } = fakeTx()
+ await writeMentions(tx, 'tab', state, [draft('top', ['peer']), draft('own', ['third'], 'own')], NOW)
+ expect(created).toHaveLength(2)
+ expect(commands).toEqual([])
+ })
+
+ it('covers each thread and person of one write once', async () => {
+ const { tx, commands } = fakeTx()
+ await writeMentions(tx, 'tab', state, [draft('a', ['peer'], 'root'), draft('b', ['peer'], 'root'), draft('c', ['peer'], 'other')], NOW)
+ expect(commands).toHaveLength(1)
+ expect(commands[0]!.updates[0].q._id.$in.sort()).toEqual([stableId('tab', 'chat', 'root', 'peer'), stableId('tab', 'chat', 'other', 'peer')].sort())
+ })
+})