Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 保留经电脑传递的本群头像
nana52537c284263
diff --git a/apps/mobile/src/__tests__/BotGroupAvatars.test.tsx b/apps/mobile/src/__tests__/BotGroupAvatars.test.tsxindex 0a3e30a575..ef1cc76511 100644--- a/apps/mobile/src/__tests__/BotGroupAvatars.test.tsx+++ b/apps/mobile/src/__tests__/BotGroupAvatars.test.tsx@@ -39,6 +39,7 @@ vi.mock('@/device-link/peerFileCache', () => ({ createPeerFileCache: async (owneimport { chatGroupView, chatRoomRow, type ChatSnapshot } from '@/chat/chatServerClient';import { BotGroupAvatar, BotGroupDuoAvatar, useBotGroupIdentities } from '@/session/BotGroupAvatars';import { BotGroupListRow } from '@/session/BotGroupList';+import { parseBotGroupChatData } from '@/session/botGroupRemote';Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });let root: Root | undefined;@@ -101,6 +102,29 @@ it('renders a server member public avatar without computer resolution and recoveexpect(host.querySelector('img')?.getAttribute('src')).toBe(snapshot.members[0].avatar);});+// Regression: direct Chat Server rendering was covered, but the computer's+// group block lost avatarUrl during parsing (PR #6807). Exercise that boundary+// through the real identity hook and image component, including reset (unit).+it('renders the computer group avatar and its reset to the account avatar', async () => {+ let avatarUrl: string | null = 'https://avatars.example.invalid/group.png';+ const Probe = () => {+ const identityFor = useBotGroupIdentities('mac');+ const member = parseBotGroupChatData({ id: 'group', name: 'Group', messages: [], members: [+ { botId: 'person', name: 'Person', avatar: avatarUrl ? '' : '🙂', avatarUrl, status: 'active' },+ ] })!.members[0];+ return createElement(BotGroupAvatar, { deviceId: 'mac', identity: identityFor(member.botId, member.name, member), size: 28, online: true });+ };+ const host = document.createElement('div'); root = createRoot(host);+ for (const next of [avatarUrl, 'https://avatars.example.invalid/account.png', null]) {+ avatarUrl = next;+ await act(async () => root!.render(createElement(Probe)));+ if (next) expect(host.querySelector('img')?.getAttribute('src')).toBe(next);+ else { expect(host.querySelector('img')).toBeNull(); expect(host.textContent).toBe('🙂'); }+ }+ expect(h.remoteMedia).not.toHaveBeenCalled();+ expect(h.invoke).not.toHaveBeenCalled();+});+it('keeps computer local media avatars on the existing resolver', async () => {h.remoteMedia.mockResolvedValueOnce({ url: 'https://media.example.invalid/thumbnail.png', previewable: true, mimeType: 'image/png' });const host = document.createElement('div'); root = createRoot(host);diff --git a/apps/mobile/src/__tests__/botGroupRemote.test.ts b/apps/mobile/src/__tests__/botGroupRemote.test.tsindex 711f88cbf4..da61354d7a 100644--- a/apps/mobile/src/__tests__/botGroupRemote.test.ts+++ b/apps/mobile/src/__tests__/botGroupRemote.test.ts@@ -47,6 +47,18 @@ function chatData(overrides: Record<string, unknown> = {}) {}describe('parseBotGroupChatData', () => {+ // The new public group image field must not turn a host path, credentialed URL+ // or malformed input into a phone image source; keep the legacy fallback (unit).+ it.each([null, 7, 'http://example.invalid/avatar.png', 'file:///avatar.png',+ 'https://user:[email protected]/avatar.png', 'https://', `https://example.invalid/${'x'.repeat(4_096)}`,+ ])('drops an invalid member image URL without dropping its fallback: %s', avatarUrl => {+ const member = parseBotGroupChatData(chatData({ members: [+ { botId: 'person', name: 'Person', avatar: '🙂', avatarUrl, status: 'active' },+ ] }))!.members[0];+ expect(member.avatarUrl).toBeUndefined();+ expect(member.avatar).toBe('🙂');+ });+it('retains validated management roles, revisions and capability without granting them to old hosts', () => {const parsed = parseBotGroupChatData(chatData({ revision: 3, supportsSettingsManagement: true,members: [{ botId: 'mimi', name: 'Mimi', role: 'admin', isOwned: true }] }));diff --git a/apps/mobile/src/session/botGroupRemote.ts b/apps/mobile/src/session/botGroupRemote.tsindex 21ab89f0c2..2dd067dc41 100644--- a/apps/mobile/src/session/botGroupRemote.ts+++ b/apps/mobile/src/session/botGroupRemote.ts@@ -152,6 +152,11 @@ function parseMember(value: unknown): BotGroupMemberView | null {const botId = id(record?.botId);const name = text(record?.name, MAX_NAME);if (!record || !botId || name === null) return null;+ let avatarUrl: string | null = null;+ try {+ const url = new URL(text(record.avatarUrl, 4_096) ?? '');+ if (url.protocol === 'https:' && !url.username && !url.password) avatarUrl = url.href;+ } catch { /* Invalid public images leave the existing avatar fallback intact. */ }return {botId,name,@@ -163,6 +168,7 @@ function parseMember(value: unknown): BotGroupMemberView | null {...(typeof record.isSelf === 'boolean' ? { isSelf: record.isSelf } : {}),...(record.role === 'owner' || record.role === 'admin' || record.role === 'member' || record.role === 'guest' ? { role: record.role } : {}),avatar: text(record.avatar, 4_096) ?? '',+ ...(avatarUrl ? { avatarUrl } : {}),avatarColor: text(record.avatarColor, 64) ?? '',status: enumOf(record.status, MEMBER_STATUSES) ?? 'missing',};diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 9b3bbee0fd..679f0d630e 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -6,6 +6,8 @@ Chat Server 的 `/me.capabilities` 新增可选 `groupMemberAvatar: 1`;Desktop`supportsMemberAvatar`,未声明时不展示换头像入口,也不退回账号头像编辑器。成员投影沿用 `avatar` 返回当前群的有效头像,并新增可选 `groupAvatar`(可空覆盖值)和`defaultAvatarUrl`(账号头像)。旧桌面与手机忽略新增字段,沿既有 `avatar` 显示路径读取。+手机经电脑读取群资源时,成员解析须保留有效的 HTTPS `avatarUrl`,交给现有头像组件显示;+缺失或非法地址沿用原头像回退。回归覆盖群头像、恢复账号头像与旧数据解析,不新增手机编辑入口。Desktop 既有 `chatServer.manage` 增加 `avatar` action;本机校验裁剪字节后复用 OSS 头像上传,复用 `POST /conversations/:id/nickname`,仅提交当前成员与可选 `avatar` 公开地址,`null` 恢复账号头像。该接口的 `nickname` 与 `avatar` 均为可选,至少提供一项;未传的字段保持原值,不回传缓存昵称。