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): 同步伙伴群头像圆形聚拢与前后排序 (#6280)

Dash25a03f03e8b2
diff --git a/apps/mobile/src/__tests__/BotGroupAvatars.test.tsx b/apps/mobile/src/__tests__/BotGroupAvatars.test.tsx
index f244741f52..a443503bce 100644
--- a/apps/mobile/src/__tests__/BotGroupAvatars.test.tsx
+++ b/apps/mobile/src/__tests__/BotGroupAvatars.test.tsx
@@ -10,7 +10,7 @@ const h = vi.hoisted(() => {
});
vi.mock('react-native', async () => {
const { createElement } = await import('react');
- return { View: ({ children }: any) => createElement('div', null, children),
+ return { View: ({ children, style }: any) => createElement('div', { style: Object.assign({}, ...[style].flat(Infinity).filter(Boolean)) }, children),
Image: ({ source, onError }: any) => { h.failImage = onError; return createElement('img', { src: source.uri, 'data-asset': typeof source === 'string' ? source : undefined }); },
StyleSheet: { create: (value: any) => value } };
});
@@ -23,7 +23,7 @@ vi.mock('@/device-link/DeviceLinkContext', () => ({ useDeviceLink: () => ({ invo
vi.mock('@/device-link/mobileMakerTransport', () => ({ createMobileMakerTransport: () => ({ fetchRemoteMedia: vi.fn() }) }));
vi.mock('@/session/remoteMedia', () => ({ resolveMobileRemoteMedia: h.remoteMedia }));
vi.mock('@/config/env', () => ({ DEVICE_LINK_API_BASE_URL: 'https://relay.example.invalid' }));
-vi.mock('@/theme', async () => ({ ...await import('@/theme/tokens'), useTheme: () => ({ colors: {} }), useThemedStyles: () => ({}) }));
+vi.mock('@/theme', async () => ({ ...await import('@/theme/tokens'), useTheme: () => ({ colors: {} }), useThemedStyles: (factory: any) => factory({}) }));
vi.mock('lucide-react-native', () => ({ Users: () => null }));
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key, i18n: { language: 'en' } }) }));
vi.mock('@/session/messageMarkdown', () => ({ parseMobileMarkdownInlines: () => [] }));
@@ -33,7 +33,7 @@ vi.mock('@/session/CompanionPresenceRing', () => ({ CompanionPresenceRing: () =>
vi.mock('@/device-link/remoteResourceCache', () => ({ cachedBotItem: () => null, readRemoteResourceSnapshot: async () => ({}),
remoteResourceCacheRevision: () => 0, subscribeRemoteResourceCache: () => () => {}, isRemoteResourceUnread: () => false }));
import { chatGroupView, chatRoomRow, type ChatSnapshot } from '@/chat/chatServerClient';
-import { BotGroupAvatar, useBotGroupIdentities } from '@/session/BotGroupAvatars';
+import { BotGroupAvatar, BotGroupDuoAvatar, useBotGroupIdentities } from '@/session/BotGroupAvatars';
import { BotGroupListRow } from '@/session/BotGroupList';
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
@@ -41,6 +41,41 @@ let root: Root | undefined;
beforeEach(() => { h.remoteMedia.mockClear(); h.invoke.mockClear(); });
afterEach(() => { act(() => root?.unmount()); root = undefined; vi.unstubAllGlobals(); });
+// Product rule §5/§8.2: previous coverage only exercised single-member image sources.
+// Render the real shared row/header mark: two members expose reversed occlusion;
+// three expose truncation, four/five expose cluster geometry, six expose the cap (unit).
+it.each(['row', 'header'] as const)('keeps the first members in front inside the %s mark as membership changes', async (variant) => {
+ const host = document.createElement('div'); root = createRoot(host);
+ const members = Array.from({ length: 6 }, (_, index) => ({ botId: String(index), name: `Member ${index}`, avatarUrl: `https://avatars.example.invalid/${index}.png` }));
+ for (const count of [2, 3, 4, 5, 6, 1, 0]) {
+ await act(async () => root!.render(createElement(BotGroupDuoAvatar, { deviceId: '', members: members.slice(0, count), online: true, variant })));
+ const images = Array.from(host.querySelectorAll('img'));
+ expect(images.map((img) => img.getAttribute('src'))).toEqual(members.slice(0, Math.min(count, 5)).reverse().map((member) => member.avatarUrl));
+ if (count < 2) continue;
+ const frame = host.firstElementChild as HTMLElement;
+ const box = parseFloat(frame.style.width);
+ const layers = images.map((img) => img.parentElement!);
+ // Paint order only implies foreground when layers are siblings with no overriding z-index.
+ expect(layers.every((layer) => layer.parentElement === frame && layer.style.position === 'absolute' && !layer.style.zIndex)).toBe(true);
+ if (count === 2) continue;
+ const centers = layers.map((layer) => {
+ const size = parseFloat(layer.style.width);
+ const left = parseFloat(layer.style.left), top = parseFloat(layer.style.top);
+ expect(left).toBeGreaterThanOrEqual(0); expect(top).toBeGreaterThanOrEqual(0);
+ expect(left + size).toBeLessThanOrEqual(box + 0.001); expect(top + size).toBeLessThanOrEqual(box + 0.001);
+ return { x: left + size / 2 - box / 2, y: top + size / 2 - box / 2, size };
+ });
+ const distances = centers.map((point, index) => {
+ const next = centers[(index + 1) % centers.length];
+ expect(Math.hypot(point.x, point.y)).toBeCloseTo(Math.hypot(centers[0].x, centers[0].y));
+ const distance = Math.hypot(next.x - point.x, next.y - point.y);
+ expect(distance).toBeLessThan(point.size); // neighboring circles actually overlap
+ return distance;
+ });
+ distances.forEach((distance) => expect(distance).toBeCloseTo(distances[0]));
+ }
+});
+
it('renders a server member public avatar without computer resolution and recovers after a changed image', async () => {
const snapshot: ChatSnapshot = { room: { id: 'group', name: 'Discussion', kind: 'group', archived: false, revision: 1,
created_at: '', updated_at: '', response_mode: 'all', speaking_mode: 'auto' }, cursor: '1', messages: [], members: [
diff --git a/apps/mobile/src/session/BotGroupAvatars.tsx b/apps/mobile/src/session/BotGroupAvatars.tsx
index 70a32fed62..f684de5600 100644
--- a/apps/mobile/src/session/BotGroupAvatars.tsx
+++ b/apps/mobile/src/session/BotGroupAvatars.tsx
@@ -1,6 +1,6 @@
/**
- * 群的身份标记(对照桌面 BotGroupAvatars.tsx):列表行与聊天顶栏都用两位成员斜向叠放
- * (行 44 框、顶栏 32 框,两个头像都收在框内)。每个头像仍是 RemoteCompanionAvatar;叠放处用与
+ * 群的身份标记(对照桌面 BotGroupAvatars.tsx):双人斜向叠放,三人以上圆形聚拢,最多前五位。
+ * 列表行 44 框、聊天顶栏 32 框;第一位始终在最前层。每个头像仍是 RemoteCompanionAvatar;叠放处用与
* 底色同色的 2pt 描边隔开,不引入阴影或新 token。头像与名字取伙伴列表缓存(只用于显示),
* 缓存里没有时退回群里带来的名字与头像字段。
*/
@@ -74,7 +74,7 @@ export function BotGroupAvatar({ deviceId, identity, size, online }: {
}
/**
- * Group mark (Desktop BotGroupDuoAvatar): two members offset diagonally, both kept inside the box.
+ * Group mark: a diagonal pair or circular cluster, kept inside the row/header box.
* The front avatar carries a 2pt page-colored ring; while someone in the group works, that ring
* breathes in Heart Orange (CompanionPresenceRing).
*/
@@ -91,11 +91,31 @@ export function BotGroupDuoAvatar({ deviceId, members, online, variant = 'row',
<Users size={iconSize.md} color={colors.textTertiary} />
</View>;
}
+ if (members.length >= 3) {
+ // Match Desktop: take the first five, then paint back-to-front so the first is unobscured.
+ const visible = members.slice(0, 5).reverse();
+ const diameter = box * (visible.length === 3 ? 0.6 : visible.length === 4 ? 0.55 : 0.5);
+ // Image geometry excludes the page-colored border; this is not a toolbar icon size.
+ const imageDiameter = diameter - STACK_RING * 2;
+ const orbit = (box - diameter) / 2;
+ return <View style={frame} accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
+ {visible.map((member, index) => {
+ const angle = (-3 * Math.PI) / 4 + (index * 2 * Math.PI) / visible.length;
+ return <View key={member.botId} style={[styles.ring, {
+ position: 'absolute', width: diameter, height: diameter,
+ left: orbit * (1 + Math.cos(angle)), top: orbit * (1 + Math.sin(angle)),
+ }]}>
+ <BotGroupAvatar deviceId={deviceId} identity={member} size={imageDiameter} online={online} />
+ {index === visible.length - 1 ? <CompanionPresenceRing active={working} gap={0} width={STACK_RING} /> : null}
+ </View>;
+ })}
+ </View>;
+ }
const front = avatar + STACK_RING * 2;
return <View style={frame} accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
- <View style={styles.duoBack}><BotGroupAvatar deviceId={deviceId} identity={first} size={second ? avatar : box} online={online} /></View>
+ <View style={styles.duoBack}><BotGroupAvatar deviceId={deviceId} identity={second ?? first} size={second ? avatar : box} online={online} /></View>
{second ? <View style={[styles.ring, { position: 'absolute', left: box - front, top: box - front }]}>
- <BotGroupAvatar deviceId={deviceId} identity={second} size={avatar} online={online} />
+ <BotGroupAvatar deviceId={deviceId} identity={first} size={avatar} online={online} />
<CompanionPresenceRing active={working} gap={0} width={STACK_RING} />
</View> : <CompanionPresenceRing active={working} />}
</View>;
diff --git a/apps/mobile/src/session/BotGroupList.tsx b/apps/mobile/src/session/BotGroupList.tsx
index 1c6fbdf5ec..e0a723e8ef 100644
--- a/apps/mobile/src/session/BotGroupList.tsx
+++ b/apps/mobile/src/session/BotGroupList.tsx
@@ -1,6 +1,6 @@
/**
* 伙伴页里的群聊行(对照桌面 BotGroupSidebarSection.tsx):与伙伴行同一个 CompanionListRow,
- * 按最近活动和伙伴混排。双头像收在 44 框内;第二行是电脑给的预览(安排状态或最近一条消息,
+ * 按最近活动和伙伴混排。成员组合头像收在 44 框内;第二行是电脑给的预览(安排状态或最近一条消息,
* 已按语言给好,手机不改写);有伙伴正在说话、安排或做事时,时间位换成转圈、前面的头像呼吸。
* 只在至少一台电脑支持群聊时出现(旧版桌面没有这个集合)。新建群聊在伙伴页顶栏的「+」菜单里。
*/
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index a01cf5c317..f0b686e9ad 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -334,8 +334,11 @@
### 8.2 界面
-- 伙伴页把群聊和伙伴混排在同一个列表里,按最近活动排序:群用双人叠放头像、群名、最近状态(与电脑侧栏相同的分工
+- 伙伴页把群聊和伙伴混排在同一个列表里,按最近活动排序:群用成员组合头像、群名、最近状态(与电脑侧栏相同的分工
状态)、运行中标记,行样式与伙伴行一致。右上角「+」菜单可新建伙伴或新建群聊。
+- 群列表与聊天顶部的组合头像复用第 5 节的顺序与布局:两人斜向叠放,三人以上圆形聚拢,最多取群成员前五位,
+ 第一位在最前层完整显示,其余依次向后。同色描边随 Light / Dark 变化;保持列表 44pt、顶部 32pt 区域与运行中呼吸环。
+ 实现与回归见 `apps/mobile/src/session/BotGroupAvatars.tsx`、`apps/mobile/src/__tests__/BotGroupAvatars.test.tsx`。
- 群设置里点成员行打开该成员的菜单(设为负责人、移出群聊);群至少保留两人,移出在只剩两人时不可用。
- 群聊页与电脑一致:多作者时间线、安排卡、交接消息与文件名、「下一步 · 继续」「没做完 · 重试」、
「N 步都做完了」、正在发言/安排/做的伙伴、待确认操作内嵌;输入框支持 @、附件(见 3.1)与「+」安排分工。