Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): keep cloud group description drafts until saved
Chris50ab640519af
diff --git a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsxindex 0768e9a68b..a51e8813af 100644--- a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx+++ b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx@@ -162,11 +162,11 @@ vi.mock('@/session/HomeHeaderGlassButton', () => ({HomeHeaderGlassButton: ({ onPress, testID, disabled, children }: any) => el('button', { 'data-testid': testID, disabled, onClick: onPress }, children),}));vi.mock('@/session/CompanionSheet', () => ({- CompanionSheet: ({ visible, children, onClose, onClosed, testID }: any) => {+ CompanionSheet: ({ visible, children, footer, preventDismiss, onClose, onClosed, testID }: any) => {if (testID === 'botGroup.settings') h.closeSettings = onClose;const was = useRef(visible);useEffect(() => { if (was.current && !visible) onClosed?.(); was.current = visible; }, [visible]);- return visible ? el('div', { 'data-testid': testID }, children) : null;+ return visible ? el('div', { 'data-testid': testID, 'data-prevent-dismiss': String(!!preventDismiss) }, children, footer) : null;},}));vi.mock('@/session/BotGroupAvatars', () => ({@@ -1309,19 +1309,57 @@ describe('group settings', () => {await openSettings(data);await act(async () => { h.inputs['botGroup.settings.description'].onChangeText('My draft'); });manage.mockRejectedValueOnce(new Error('REVISION_CONFLICT'));- await act(async () => { h.inputs['botGroup.settings.description'].onBlur(); });+ await click('botGroup.settings.descriptionSave');expect(manage).toHaveBeenLastCalledWith('update', { description: 'My draft', expectedRevision: 5 });expect(h.inputs['botGroup.settings.description'].value).toBe('My draft');expect(byId('botGroup.settings')?.textContent).toContain('groupChat.settings.conflict');h.management.group = { ...data, description: 'Other edit', revision: 6 };await render(h.management.group);expect(h.inputs['botGroup.settings.description'].value).toBe('My draft');- await act(async () => { h.inputs['botGroup.settings.description'].onBlur(); });+ await click('botGroup.settings.descriptionSave');expect(manage).toHaveBeenLastCalledWith('update', { description: 'My draft', expectedRevision: 6 });await click(`botGroup.settings.memberMenu.${data.members[1].botId}.action.role:${data.members[1].botId}`);expect(manage).toHaveBeenLastCalledWith('set-member-role', { actorId: 'member-actor', role: 'admin' });});+ // Regression: native dismissal need not emit blur, so an edited description was lost.+ // Unit tier uses the production settings component; no artificial onBlur is dispatched.+ it('keeps an unblurred cloud draft open until saving succeeds or the user explicitly cancels', async () => {+ const data = group({ serverBacked: true, supportsSettingsManagement: true, revision: 5, description: 'Original' });+ data.members[0] = { ...data.members[0], isOwned: true, role: 'owner' };+ let finish!: () => void;+ const manage = vi.fn(() => new Promise(resolve => { finish = () => resolve({ effects: [] }); }));+ h.chat.server = true;+ h.management = { group: data, editable: true, loading: false, reason: null, act: manage, refresh: vi.fn() };+ await openSettings(data);+ await act(async () => { h.inputs['botGroup.settings.description'].onChangeText('Unblurred draft'); });+ await act(async () => { h.closeSettings?.(); });+ expect(byId('botGroup.settings')).not.toBeNull();+ expect(byId('botGroup.settings')?.dataset.preventDismiss).toBe('true');+ expect(manage).not.toHaveBeenCalled();+ await click('botGroup.settings.descriptionSave');+ expect(manage).toHaveBeenCalledWith('update', { description: 'Unblurred draft', expectedRevision: 5 });+ await act(async () => { h.closeSettings?.(); });+ expect(byId('botGroup.settings')).not.toBeNull();+ await act(async () => { finish(); });+ expect(byId('botGroup.settings')?.dataset.preventDismiss).toBe('false');+ await act(async () => { h.closeSettings?.(); });+ expect(byId('botGroup.settings')).toBeNull();++ await click('botGroup.settingsButton');+ manage.mockRejectedValueOnce(new Error('NETWORK_ERROR'));+ await act(async () => { h.inputs['botGroup.settings.description'].onChangeText('Retained on failure'); });+ await click('botGroup.settings.descriptionSave');+ await act(async () => { h.closeSettings?.(); });+ expect(h.inputs['botGroup.settings.description'].value).toBe('Retained on failure');+ expect(byId('botGroup.settings')?.dataset.preventDismiss).toBe('true');+ await click('botGroup.settings.descriptionCancel');+ expect(byId('botGroup.settings')).toBeNull();+ await click('botGroup.settingsButton');+ expect(h.inputs['botGroup.settings.description'].value).toBe('Original');+ expect(byId('botGroup.settings.descriptionSave')).toBeNull();+ });+it('explains unavailable management and offers retry without enabling edits', async () => {const refresh = vi.fn();h.management = { editable: false, loading: false, reason: 'unavailable', act: vi.fn(), refresh };diff --git a/apps/mobile/src/session/BotGroupSettingsSheet.tsx b/apps/mobile/src/session/BotGroupSettingsSheet.tsxindex f41d44bf3c..5b97263fdd 100644--- a/apps/mobile/src/session/BotGroupSettingsSheet.tsx+++ b/apps/mobile/src/session/BotGroupSettingsSheet.tsx@@ -16,7 +16,7 @@ import {import { chatGroupMembership, isActiveBotGroupMember } from '@cindy/maker-shared/botGroupPresentation';import { useAuth } from '@/auth/AuthContext';import { Text, TextInput } from '@/components/AppText';-import { MainWindowOptionButton } from '@/components/MobilePrimitives';+import { MainWindowActionButton, MainWindowOptionButton } from '@/components/MobilePrimitives';import { mobileInteractionStyles } from '@/components/mobileInteractionStyles';import type { RemoteResourceHostTarget } from '@/device-link/remoteResources';import { showConfirm } from '@/platform/chrome';@@ -105,9 +105,9 @@ function BotGroupSettingsContent({ visible, group, host, identityFor, online, acconst candidatesLoading = management ? cloudCandidates.loading : teammates.loading;const candidatesFailed = management ? cloudCandidates.failed : teammates.failed;const [description, setDescription] = useState(group.description ?? '');- const descriptionDirty = useRef(false);+ const [descriptionDirty, setDescriptionDirty] = useState(false);const descriptionRevision = useRef(group.revision);- useEffect(() => { if (!descriptionDirty.current) setDescription(group.description ?? ''); }, [group.description]);+ useEffect(() => { if (!descriptionDirty) setDescription(group.description ?? ''); }, [group.description, descriptionDirty]);// Follow renames that land from the computer while the field is not being edited.useEffect(() => { if (!nameFocused.current && !nameDirty.current) setName(group.name); }, [group.name]);@@ -161,6 +161,19 @@ function BotGroupSettingsContent({ visible, group, host, identityFor, online, acif (saved) nameDirty.current = false;};+ const saveDescription = async () => {+ if (!descriptionDirty) return;+ const captured = scope;+ if (errors.description) descriptionRevision.current = group.revision;+ const saved = await run('description', 'update', { description, expectedRevision: descriptionRevision.current }, 'groupChat.settings.descriptionSaveFailed');+ if (saved && active.current === captured) setDescriptionDirty(false);+ };++ // Native dismissal can happen without TextInput.onBlur. Keep the draft visible until+ // the user saves it or explicitly cancels, including after a rejected server write.+ const preventDismiss = busy !== null || descriptionDirty;+ const close = () => { if (!descriptionDirty) onClose(); };+const setMembers = async (botIds: string[]) => {const saved = await run('members', 'set-members', { botIds }, 'groupChat.settings.membersSaveFailed');if (saved) setPicking(false);@@ -205,8 +218,15 @@ function BotGroupSettingsContent({ visible, group, host, identityFor, online, acstyle={[styles.segment, unavailable && styles.inheritedInactive]} testID={`botGroup.settings.${section}.${option.value}`} />)}</View>;- return <CompanionSheet visible={visible} title={t('groupChat.settings.title')} onClose={onClose} onClosed={onClosed}- preventDismiss={busy !== null} testID="botGroup.settings">+ return <CompanionSheet visible={visible} title={t('groupChat.settings.title')} onClose={close} onClosed={onClosed}+ preventDismiss={preventDismiss} testID="botGroup.settings"+ footer={descriptionDirty ? <View style={styles.draftActions}>+ <MainWindowActionButton action={{ label: t('devices.common.cancel'), disabled: busy !== null,+ onPress: () => { if (busyRef.current) return; setDescriptionDirty(false); setDescription(group.description ?? ''); onClose(); },+ testID: 'botGroup.settings.descriptionCancel' }} />+ <MainWindowActionButton action={{ label: t('devices.common.save'), tone: 'primary', busy: busy === 'description', disabled: locked,+ onPress: () => void saveDescription(), testID: 'botGroup.settings.descriptionSave' }} />+ </View> : undefined}><View style={styles.content}>{management && (management.loading || management.reason) ? <View style={styles.managementRow} testID="botGroup.settings.management">{management.loading ? <ActivityIndicator size="small" color={colors.textSecondary} testID="botGroup.settings.connecting" /> : null}@@ -236,13 +256,8 @@ function BotGroupSettingsContent({ visible, group, host, identityFor, online, ac<Text style={styles.sectionTitle}>{t('groupChat.settings.description')}</Text><TextInput accessibilityLabel={t('groupChat.settings.description')} value={description} maxLength={2000} multilineeditable={!locked} style={[styles.input, styles.description]} testID="botGroup.settings.description"- onChangeText={value => { if (!descriptionDirty.current || errors.description) descriptionRevision.current = group.revision;- descriptionDirty.current = true; setDescription(value); setErrors(current => ({ ...current, description: undefined })); }}- onBlur={() => { if (descriptionDirty.current) {- if (errors.description) descriptionRevision.current = group.revision;- void run('description', 'update', { description, expectedRevision: descriptionRevision.current }, 'groupChat.settings.descriptionSaveFailed')- .then(saved => { if (saved) descriptionDirty.current = false; });- } }} />+ onChangeText={value => { if (!descriptionDirty || errors.description) descriptionRevision.current = group.revision;+ setDescriptionDirty(true); setDescription(value); setErrors(current => ({ ...current, description: undefined })); }} />{error('description')}</View> : null}@@ -407,6 +422,7 @@ function BotGroupSettingsContent({ visible, group, host, identityFor, online, acconst makeStyles = (colors: ThemeColors) => StyleSheet.create({content: { gap: spacing.xl, paddingTop: spacing.sm, paddingBottom: spacing.xl },settingsBody: { gap: spacing.xl },+ draftActions: { flexDirection: 'row', justifyContent: 'flex-end', gap: spacing.sm },managementRow: { minHeight: 44, flexDirection: 'row', alignItems: 'center', gap: spacing.sm },managementText: { color: colors.textSecondary, fontSize: typeScale.footnote, lineHeight: lineHeight.caption },reconnect: { minHeight: 44, minWidth: 44, justifyContent: 'center', alignItems: 'center' },diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex 9427ef5392..976195c733 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -494,7 +494,8 @@ Chat Server 声明 `capabilities.groupSingleSpeaker: 1` 时,服务器群按下服务器未声明 `groupSingleSpeaker` 时保留发言方式。所有写入仍由服务器按实时群角色核权,同账号拥有的群主/管理员 actor 可沿用 Desktop 的 `X-Chat-Actor` 管理路径;不能借用其他账号身份。成员候选来自账号云端伙伴列表,不以电脑在线状态筛选;添加/移出/角色修改逐个提交,- 不整批覆盖成员。群资料保存携带编辑时的 `expectedRevision`,冲突保留输入并重读最新设置;+ 不整批覆盖成员。简介编辑后显示明确的保存/取消操作,草稿或保存进行中阻止直接关闭;+ 失败保留草稿,取消才放弃。群资料保存携带编辑时的 `expectedRevision`,冲突保留输入并重读最新设置;网络结果不确定时仅由用户重试,复用同一操作回执 ID,避免重复执行。账号、群或设置页生命周期变化后,旧请求不能恢复授权或影响新页面;写后重新读取,读取失败保留已确认保存的结果但暂停继续编辑,提供服务器读取重试。