Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): 旧页贴回的补读次数按版本重新计算

Dashc5f4b229f47d
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
index 10bcfb1b5f..2196747f41 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
@@ -330,13 +330,15 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {
// Older shares checked before the latest edit, deletion or reset are re-checked from the
// committed timeline, whichever of a refresh and an older page landed last. One refresh
// checks up to the per-read cap, so a bounded number of follow-ups reaches all of them.
- const shareFollowUps = useRef(0);
+ // Each version gets its own budget: an edit mid-way makes every card stale again.
+ const shareFollowUps = useRef<{ version: number | undefined; count: number }>({ version: undefined, count: 0 });
useEffect(() => {
- if (state.kind !== 'ready') { shareFollowUps.current = 0; return; }
- if (!staleBotGroupShares(state.older, state.group.threadShareVersion).length) { shareFollowUps.current = 0; return; }
+ const version = state.kind === 'ready' ? state.group.threadShareVersion : undefined;
+ if (shareFollowUps.current.version !== version) shareFollowUps.current = { version, count: 0 };
+ if (state.kind !== 'ready' || !staleBotGroupShares(state.older, version).length) { shareFollowUps.current.count = 0; return; }
const total = state.older.filter(message => message.threadShare).length;
- if (shareFollowUps.current >= Math.ceil(total / BOT_GROUP_SHOWN_SHARES_MAX) + 1) return;
- shareFollowUps.current += 1;
+ if (shareFollowUps.current.count >= Math.ceil(total / BOT_GROUP_SHOWN_SHARES_MAX) + 1) return;
+ shareFollowUps.current.count += 1;
loadRef.current();
}, [state]);
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 1586f021e0..50e31ee0c7 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -2501,6 +2501,29 @@ describe('shares on older pages', () => {
expect(await screen.findByText('编辑后的原文')).toBeTruthy();
expect(screen.queryByText('编辑前的原文')).toBeNull();
});
+
+ it('gives each new version its own follow-up budget', async () => {
+ const share = { messageId: 'old-reply', threadRootId: 'old-root', status: 'available' as const, authorKind: 'bot' as const, authorBotId: 'xiaoman', authorName: '小满',
+ sharedByAuthor: false, content: '原文', attachments: [], createdAt: 1, edited: false, version: 1 };
+ const oldShare = msg({ id: 'old-share', sequence: 1, authorKind: 'user', isSelf: false, authorBotId: 'alice-actor', authorName: 'Alice', content: '↪ 卡片文字', threadShare: share });
+ let version = 1;
+ // The server cannot confirm this share for now, so every refresh leaves it stale.
+ mocks.getBotGroup.mockImplementation(async (_groupId: string, options?: { beforeSequence?: number }) => ({ ok: true, group: detail({ serverBacked: true,
+ threadShareVersion: version, ...(options?.beforeSequence ? { hasMoreBefore: false, messages: [oldShare] } : { hasMoreBefore: true, messages: [msg({ id: 'new', sequence: 50, content: '最新' })] }) }) }));
+ renderView();
+ fireEvent.click(await screen.findByRole('button', { name: 'bots.groupChat.timeline.loadEarlier' }));
+ await screen.findByText('原文');
+ const settle = async () => { for (let i = 0; i < 6; i += 1) await act(async () => { await Promise.resolve(); }); };
+ version = 2;
+ await act(async () => mocks.pushes.forEach(push => push({ groupId: 'g1', change: 'messages' })));
+ await settle();
+ const afterFirstEdit = mocks.getBotGroup.mock.calls.length;
+ // A later edit: the stale card is re-checked again, not left on the first edit's spent budget.
+ version = 3;
+ await act(async () => mocks.pushes.forEach(push => push({ groupId: 'g1', change: 'messages' })));
+ await settle();
+ expect(mocks.getBotGroup.mock.calls.length - afterFirstEdit).toBeGreaterThan(1);
+ });
});
describe('more older shares than one refresh re-reads', () => {