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(chat): keep reaction avatars current after a reset or a member rename

Dash8f474c74aa3a
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
index 7e4ef8008f..9d3ea3bcd2 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@ -1107,6 +1107,11 @@ describe('Chat Server result delivery and refresh', () => {
{ type: 'message.updated', entityId: message.id },
] }));
expect(await revision()).toBe(2);
+ // A reset skips whatever changed while disconnected: every message counts as changed once.
+ Object.defineProperty(socket, 'readyState', { value: 1 });
+ socket.emit('message', JSON.stringify({ type: 'scope_error', scope: `conversation:${roomId}`, error: { code: 'RESET_REQUIRED' } }));
+ await vi.advanceTimersByTimeAsync(0);
+ expect(await revision()).toBe(3);
});
it('refreshes a reset room and resumes realtime from the authorized snapshot cursor', async () => {
await service.getGroup(roomId);
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index 44baf3c551..be438baafe 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -183,6 +183,8 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
let actorsStale = false;
// Who reacted can change while the count stays the same; each realtime reaction change versions the message.
const reactionRevisions = new Map<string, number>();
+ // A reset skips the missed events, so every message's reactions are treated as changed once.
+ let reactionResets = 0;
let profiles: Array<typeof botProfiles.$inferSelect> = [];
const workspaces = () => chatServerWorkspaces(config.baseUrl, selfId, current);
const planning = new Map<string, { botId: string; controller: AbortController }>();
@@ -577,6 +579,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
void api<Snapshot>(`/conversations/${roomId}/snapshot`).then(value => {
if (!current() || socket !== ws || ws.readyState !== WebSocket.OPEN) return;
if (rooms.has(roomId)) advanceRoom(roomId, value.cursor);
+ reactionResets++;
changed(roomId);
ws.send(JSON.stringify({ type: 'subscribe', scope: event.scope, after: value.cursor }));
}).catch(() => ws.close());
@@ -641,7 +644,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
const quote = m.deleted || planCard ? null : readBotGroupQuote(m.content);
return { id: m.id, sequence: Number(m.seq), deleted: m.deleted, kind: planCard ? 'plan' : 'message', authorKind: legacy?.authorKind === 'system' ? 'system' : m.author.kind === 'human' ? 'user' : 'bot',
isSelf: m.authorId === selfId, threadRootId: m.threadRootId, replyCount: m.replyCount ?? 0, reactions: m.reactions ?? [], ...(quote ? { quote } : {}),
- reactionRevision: reactionRevisions.get(m.id) ?? 0,
+ reactionRevision: (reactionRevisions.get(m.id) ?? 0) + reactionResets,
authorBotId: localBot(m.authorId)?.id ?? m.authorId, authorName: legacy?.authorKind === 'system' && typeof legacy.authorName === 'string' ? legacy.authorName : member ? memberName(member) : m.author.name, content: bodyText(m),
mentions: { all: false, botIds: [] }, noticeCode: null, planId: typeof planCard?.data?.planId === 'string' ? planCard.data.planId : null, files: [], attachments: [], createdAt: Date.parse(m.createdAt) };
}
diff --git a/apps/desktop/src/renderer/features/bots/ChatReactionButton.tsx b/apps/desktop/src/renderer/features/bots/ChatReactionButton.tsx
index 0982c77b9f..834eca79db 100644
--- a/apps/desktop/src/renderer/features/bots/ChatReactionButton.tsx
+++ b/apps/desktop/src/renderer/features/bots/ChatReactionButton.tsx
@@ -71,7 +71,11 @@ export function ChatReactionButton({ groupId, messageId, reaction, revision = 0,
// that disagrees with the count (a change still in flight), keeps the honest count instead.
const current = loaded?.summary === summary ? loaded : null;
const showAvatars = wantsAvatars && (!current || current.reactors?.length === reaction.count);
- const reactors = showAvatars && current?.reactors ? reactorOrder(current.reactors, i18n.language) : null;
+ // Names follow the latest member projection; only actors no longer in it keep the name read with them.
+ const reactors = showAvatars && current?.reactors ? reactorOrder(current.reactors.map(r => {
+ const member = members?.find(m => m.actorId === r.actorId);
+ return member ? { ...r, name: member.name, formerMember: false } : r;
+ }), i18n.language) : null;
const countLabel = t(key('reactionCount'), { emoji: reaction.emoji, count: reaction.count });
const label = reactors?.length
? t(key('reactionWho'), { emoji: reaction.emoji, count: reaction.count, names: reactorNames(reactors, t, i18n.language) })
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/ChatReactionButton.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/ChatReactionButton.test.tsx
index 6cba2c4480..777e30251c 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/ChatReactionButton.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/ChatReactionButton.test.tsx
@@ -151,6 +151,17 @@ describe('reaction avatars', () => {
expect(images()).toEqual(['https://example.test/cindy-chris.png']);
});
+ it('follows member renames without another read', async () => {
+ mocks.reactors.mockResolvedValue({ ok: true, reactors: [reactor('z', 'Zoe')] });
+ const view = render(actions([{ emoji: '👍', count: 1, me: false }]));
+ await waitFor(() => expect(badge().getAttribute('aria-label')).toBe('👍 · 1: Zoe'));
+ const renamed = members.map(m => m.actorId === 'z' ? { ...m, name: 'Zoey' } : m);
+ view.rerender(<ChatMessageActions shareScope="group:room" groupId="room" members={renamed} onChanged={vi.fn()}
+ message={message([{ emoji: '👍', count: 1, me: false }])} />);
+ expect(badge().getAttribute('aria-label')).toBe('👍 · 1: Zoey');
+ expect(mocks.reactors).toHaveBeenCalledTimes(1);
+ });
+
it('keeps click as the toggle', async () => {
mocks.reactors.mockResolvedValue({ ok: true, reactors: [reactor('a', 'Dash', { isSelf: true })] });
render(actions([{ emoji: '👍', count: 1, me: true }]));
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index 9d978e8877..d7dcf9a4fb 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -366,7 +366,8 @@ Desktop 主群与 Thread 的表情回应徽标参考 Telegram:某个表情的
Chat Server 既有的回应者接口直到最后一页(离群成员保留回应,总数可超过群人数上限)并按群成员投影命名;
读取只读,不触发伙伴资料同步等任何写入。加载期间按人数预留头像位,不撑动消息;读取失败或名单与人数暂不一致时
如实显示数字。回应数、自己的状态或实时回应事件(含人数不变、只换了人的情况)变化时重新读取;实时连接断开期间,
-只换人不换数的变化要到重连回放后才更新。点击仍是添加/取消回应。回归见 `ChatReactionButton.test.tsx`
+只换人不换数的变化要到重连回放后才更新,无法回放而重置时,所有回应都按已变化重新读取。仍在群内的回应者名字
+始终取最新的群成员资料(改昵称后立即更新),只有已不在群内的成员沿用读取时的名字。点击仍是添加/取消回应。回归见 `ChatReactionButton.test.tsx`
与 `chatServer.test.ts`;手机端暂不显示回应。
当前本地验收与正式切源边界见 [Chat Server 本地联调](../dev-rules/chat-server-local-test.md)。