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(mobile): 避免新群同步时短暂重复

nanaa63e5c3bbd48
diff --git a/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx b/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
index 2353b0f317..8f7e8ab1cc 100644
--- a/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
+++ b/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
@@ -380,6 +380,25 @@ it('clears access on everyone member-read rejection and ignores an older authori
await act(async () => { chat.reload(); });
expect(chat.state.kind).toBe('ready');
});
+it('deduplicates computer copies before the server roster discovers a new group', async () => {
+ h.auth.accountGeneration++;
+ h.targets = ['mac', 'pc'].map(deviceId => ({ deviceId, deviceName: deviceId }));
+ h.legacy.isOnline.mockReturnValue(true);
+ h.legacy.items = h.targets.map(host => ({ key: host.deviceId, host, item: {
+ ref: { collectionId: 'bot-groups', kind: 'bot-group', id }, revision: '1', display: { title: 'Discussion' }, links: [],
+ } }));
+ const original = h.auth.apiFetch.getMockImplementation()!;
+ let finish!: (rooms: typeof room[]) => void;
+ const pending = new Promise<typeof room[]>(resolve => { finish = resolve; });
+ h.auth.apiFetch.mockImplementation((path, options) => path.startsWith('/v1/conversations?') ? pending : original(path, options));
+ await render();
+ expect(roster.items.map(row => row.item.ref.id)).toEqual([id]);
+ expect(roster.items[0].host.deviceId).toBe('mac');
+ await act(async () => { finish([room]); });
+ expect(roster.items.map(row => row.item.ref.id)).toEqual([id]);
+ expect(roster.items[0].host.deviceId).toBe('');
+});
+
it('deduplicates server copies from multiple computers while retaining a local legacy group', async () => {
h.legacy.items = ['mac', 'pc'].map(deviceId => ({ key: deviceId, host: { deviceId, deviceName: deviceId }, item: { ref: { collectionId: 'bot-groups', kind: 'bot-group', id }, revision: '1', display: { title: 'Discussion' }, links: [] } }));
h.legacy.isOnline.mockReturnValue(true);
diff --git a/apps/mobile/src/session/useBotGroupRoster.ts b/apps/mobile/src/session/useBotGroupRoster.ts
index d232671c67..f6fcece500 100644
--- a/apps/mobile/src/session/useBotGroupRoster.ts
+++ b/apps/mobile/src/session/useBotGroupRoster.ts
@@ -15,11 +15,16 @@ export function useBotGroupRoster(targets: readonly RemoteResourceHostTarget[],
const hosts = targets.length ? targets : NO_TARGETS;
const list = useRemoteResourceList(BOT_GROUP_REMOTE_COLLECTION_ID, hosts, enabled && hosts.length > 0);
// A removed server membership must not reappear through a stale computer cache.
- const serverIds = server.serverIds;
+ const seen = new Set(server.serverIds);
// Old cached rows carry no server/local discriminator. Only a current-epoch
// authenticated collection reply can authorize the compatibility projection.
- const legacy = list.items.filter((row) => row.item.ref.kind === BOT_GROUP_REMOTE_RESOURCE_KIND
- && list.isOnline(row.host) && !serverIds.has(row.item.ref.id) && !revoked.has(row.host.deviceId) && hosts.some((host) => host.deviceId === row.host.deviceId));
+ const legacy = list.items.filter((row) => {
+ const id = row.item.ref.id;
+ if (row.item.ref.kind !== BOT_GROUP_REMOTE_RESOURCE_KIND || !list.isOnline(row.host) || seen.has(id)
+ || revoked.has(row.host.deviceId) || !hosts.some((host) => host.deviceId === row.host.deviceId)) return false;
+ seen.add(id);
+ return true;
+ });
return {
items: [...server.items, ...legacy],
loading: server.loading || (hosts.length > 0 && list.loading),