Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Fix: load a deep-linked thread the loaded task lists do not know yet

koeria2237d7a21a1c
diff --git a/src/components/ThreadRefs.test.ts b/src/components/ThreadRefs.test.ts
index ac799aa7a7..40939374bd 100644
--- a/src/components/ThreadRefs.test.ts
+++ b/src/components/ThreadRefs.test.ts
@@ -171,21 +171,33 @@ describe("openChatLink", () => {
expect(actions(refused)).toEqual([{ type: "notice", notice: { kind: "bot-gone", botName: null } }]);
});
- it("refuses a thread that is not the named bot's, showing that bot instead", async () => {
+ it("asks the named bot for a thread its loaded task lists do not know yet, so a cold launch still fills the transcript", async () => {
const dispatch = vi.fn();
- expect(openChatLink(dispatch, "openmausbot://thread/qa-245?bot=ada", await state(), true)).toBe(false);
+ expect(openChatLink(dispatch, "openmausbot://thread/late-1?bot=scout", await state(), true)).toBe(true);
+ expect(actions(dispatch)).toEqual([
+ { type: "select", id: "scout" },
+ { type: "switchTask", botId: "scout", threadId: "late-1" },
+ { type: "revealThread", threadId: "late-1" },
+ ]);
+ });
+
+ it("refuses a thread that is not the named bot's, showing that bot while the server vets the pair", async () => {
+ const dispatch = vi.fn();
+ expect(openChatLink(dispatch, "openmausbot://thread/qa-245?bot=ada", await state(), true)).toBe(true);
expect(actions(dispatch)).toEqual([
{ type: "select", id: "ada" },
- { type: "notice", notice: { kind: "thread-gone", botName: "Ada" } },
+ { type: "switchTask", botId: "ada", threadId: "qa-245" },
+ { type: "revealThread", threadId: "qa-245" },
]);
});
- it("refuses a room's dead thread, showing that room instead", async () => {
+ it("asks a room for its thread too", async () => {
const dispatch = vi.fn();
- expect(openChatLink(dispatch, "openmausbot://thread/gone?bot=standup", await state(), true)).toBe(false);
+ expect(openChatLink(dispatch, "openmausbot://thread/gone?bot=standup", await state(), true)).toBe(true);
expect(actions(dispatch)).toEqual([
{ type: "select", id: "standup" },
- { type: "notice", notice: { kind: "thread-gone", botName: "Standup" } },
+ { type: "switchGroupTask", groupId: "standup", threadId: "gone" },
+ { type: "revealThread", threadId: "gone" },
]);
});
@@ -227,10 +239,11 @@ describe("openChatLink", () => {
{ type: "revealThread", threadId: "scout-main" },
]);
const dead = vi.fn();
- expect(openChatLink(dead, "openmausbot://thread/gone?bot=scout", left, false)).toBe(false);
+ expect(openChatLink(dead, "openmausbot://thread/gone?bot=scout", left, false)).toBe(true);
expect(actions(dead)).toEqual([
{ type: "switchTask", botId: "scout", threadId: "scout-main" },
- { type: "notice", notice: { kind: "thread-gone", botName: "Scout" } },
+ { type: "switchTask", botId: "scout", threadId: "gone" },
+ { type: "revealThread", threadId: "gone" },
]);
const shown = vi.fn();
expect(openChatLink(shown, "openmausbot://bot/scout", left, true)).toBe(true);
diff --git a/src/components/ThreadRefs.tsx b/src/components/ThreadRefs.tsx
index 426c8624cf..d845e1d2ff 100644
--- a/src/components/ThreadRefs.tsx
+++ b/src/components/ThreadRefs.tsx
@@ -98,12 +98,25 @@ export function openChatLink(dispatch: (action: Action) => void, link: string, s
const address = parseThreadRefUrl(link);
const ref = address ? resolveThreadRefAddress(collectThreadRefs(state.bots, state.groups), address) : null;
if (ref) return openThread(dispatch, ref, state, threadsShown);
- const owner = address?.botId ? openOwner(address.botId) : undefined;
- if (owner) {
- dispatch({ type: "notice", notice: { kind: "thread-gone", botName: owner.name } });
- } else {
- showLinkNotice(dispatch, state, { kind: "thread-gone", botName: null });
+ // A thread the loaded task lists do not know yet (a cold launch can open the link before every task list has
+ // landed) still exists on the server. Ask the pinned owner for exactly that thread: the server loads it or
+ // refuses the pair, so the transcript arrives without ever showing another chat's messages.
+ if (address?.botId) {
+ const group = state.groups.find((candidate) => candidate.id === address.botId && !candidate.dm);
+ if (group) {
+ dispatch({ type: "select", id: group.id });
+ dispatch({ type: "switchGroupTask", groupId: group.id, threadId: address.threadId });
+ } else if (state.bots.some((candidate) => candidate.id === address.botId)) {
+ openOwner(address.botId);
+ dispatch({ type: "switchTask", botId: address.botId, threadId: address.threadId });
+ } else {
+ showLinkNotice(dispatch, state, { kind: "thread-gone", botName: null });
+ return false;
+ }
+ dispatch({ type: "revealThread", threadId: address.threadId });
+ return true;
}
+ showLinkNotice(dispatch, state, { kind: "thread-gone", botName: null });
return false;
}