Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bot-group): send the last follow click after an uncertain save
zqchris4baac578670e
diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsxindex 9bcb360383..5b73ef1a25 100644--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx@@ -235,16 +235,20 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,followWriteRef.current += 1;const owner = getDataOwnerGeneration();const current = () => aliveRef.current && isDataOwnerGenerationCurrent(owner);+ // A failed write may still have been saved (a timeout or a dropped connection): until a later+ // write succeeds, the server's value is unknown and the newest click is always sent.+ let uncertain = false;try {- while (save.wanted !== null && save.wanted !== save.saved) {+ while (save.wanted !== null && (uncertain || save.wanted !== save.saved)) {const wanted: boolean = save.wanted;save.wanted = null;let failure: string | null = null;try {const result = await api().followThread({ groupId: group.id, rootId, following: wanted });- if (result.ok) save.saved = result.following;+ if (result.ok) { save.saved = result.following; uncertain = false; }else failure = t(chatErrorKey(result.errorCode));} catch { failure = t(key('requestFailed')); }+ if (failure) uncertain = true;if (!current()) return;// A newer click is saved next; only the last outcome is shown.if (save.wanted !== null) continue;@@ -255,6 +259,8 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,save.saving = false;save.wanted = null;followWriteRef.current += 1;+ // Read what the server kept after a failure: the switch then shows the real choice.+ if (uncertain && current()) refreshRef.current();}}, [following, group.id, rootId, t]);useEffect(() => {diff --git a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsxindex 622427c85d..055e117828 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx@@ -15,7 +15,7 @@ import { shareSelectionStore } from '@/components/chat/shareSelectionStore';import { queryShareableMessageIds, stripInteractiveElements } from '@/lib/shareConversationImage';const mocks = vi.hoisted(() => ({- status: vi.fn(), react: vi.fn(), reactors: vi.fn(), thread: vi.fn(), reply: vi.fn(), createInvite: vi.fn(), previewInvite: vi.fn(), acceptInvite: vi.fn(),+ status: vi.fn(), react: vi.fn(), reactors: vi.fn(), thread: vi.fn(), followThread: vi.fn(), reply: vi.fn(), createInvite: vi.fn(), previewInvite: vi.fn(), acceptInvite: vi.fn(),refresh: vi.fn(), shareToMain: vi.fn(), ownerCurrent: true,}));// Partial: the 话题 reply box shares the group composer, whose attachment pieces pull in the app i18n instance.@@ -92,6 +92,29 @@ describe('chat interaction controls', () => {expect(mocks.shareToMain).toHaveBeenCalledOnce();});+ // bot-group-chat.md §10「关注开关」: the server keeps the reader's last click.+ it('still sends the last follow click when an earlier save failed but may have been kept', async () => {+ mocks.thread.mockResolvedValue({ ok: true, root: message, replies: [], hasMore: false, following: false });+ let failFirst: (error: Error) => void = () => {};+ mocks.followThread.mockReturnValueOnce(new Promise((_resolve, reject) => { failFirst = reject; }))+ .mockResolvedValueOnce({ ok: true, following: false });+ render(<ChatThreadPanel group={group} rootId="root" onClose={vi.fn()} />);+ const follow = await waitFor(() => {+ const button = document.querySelector('[data-thread-follow]') as HTMLButtonElement | null;+ if (!button) throw new Error('follow switch not shown');+ return button;+ });+ fireEvent.click(follow);+ expect(follow.getAttribute('aria-pressed')).toBe('true');+ fireEvent.click(follow);+ expect(follow.getAttribute('aria-pressed')).toBe('false');+ // The first save times out after the server may already have kept it.+ await act(async () => { failFirst(new Error('timeout')); });+ await waitFor(() => expect(mocks.followThread).toHaveBeenCalledTimes(2));+ expect(mocks.followThread.mock.calls.map(([input]) => input.following)).toEqual([true, false]);+ expect(follow.getAttribute('aria-pressed')).toBe('false');+ });+it('refits a typed thread reply when the panel width changes, not when only its height does', () => {const observed: Array<{ target: Element; callback: () => void }> = [];vi.stubGlobal('ResizeObserver', class {