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): 切换账号后伙伴段的新建入口立即服务新账号

Chris3a876d082737
diff --git a/apps/mobile/src/__tests__/TeammateCreateController.test.tsx b/apps/mobile/src/__tests__/TeammateCreateController.test.tsx
index 9e65669559..4f6546435d 100644
--- a/apps/mobile/src/__tests__/TeammateCreateController.test.tsx
+++ b/apps/mobile/src/__tests__/TeammateCreateController.test.tsx
@@ -47,6 +47,17 @@ it('fences late native menu and create dismissal callbacks after account replace
h.account++; await render();
await act(async () => { oldMenu.onAction('pc'); oldSheet.onClosed(); }); expect(h.created).not.toHaveBeenCalled();
});
+// Android and wide screens host the home list at the root, so an account switch reaches the same instance.
+it('serves the new account after a switch without remounting, and never closes its form for the old one', async () => {
+ await render(); await act(async () => h.menu.onAction('mac')); const oldSheet = h.sheet;
+ h.account++; h.sheet = null; await render();
+ expect(h.sheet).toBeNull();
+ await act(async () => h.menu.onAction('pc'));
+ expect(h.sheet.deviceId).toBe('pc'); expect(h.sheet.visible).toBe(true);
+ await act(async () => { oldSheet.onCreated(ref); oldSheet.onClosed(); }); expect(h.created).not.toHaveBeenCalled();
+ await act(async () => { h.sheet.onCreated(ref); h.sheet.onClose(); h.sheet.onClosed(); });
+ expect(h.created).toHaveBeenCalledExactlyOnceWith(hosts[1], ref);
+});
it('offers group chats in the same menu and reports a new group only after its form closes', async () => {
await render([], [hosts[1]]);
diff --git a/apps/mobile/src/session/TeammateCreateController.tsx b/apps/mobile/src/session/TeammateCreateController.tsx
index 0632ca7209..c520d81009 100644
--- a/apps/mobile/src/session/TeammateCreateController.tsx
+++ b/apps/mobile/src/session/TeammateCreateController.tsx
@@ -27,13 +27,14 @@ type CreateOptions = {
* 新建伙伴 / 新建群聊的菜单与表单。支持群聊时是一个菜单(多台电脑时再选电脑);旧版电脑不支持
* 群聊时直接新建伙伴。表单关闭后才回报创建结果,避免两个 Modal 叠加。
* The trigger is drawn by the caller: the task home's teammate section moves it between states, and
- * a moving trigger must not unmount an open form or drop its receipt. Callers remount it on account
- * changes (the home is keyed by account).
+ * a moving trigger must not unmount an open form or drop its receipt. It starts over on an account
+ * switch by itself: the root-hosted home list (Android, wide screens) keeps its state across the
+ * account-keyed route.
*/
export function useTeammateCreateController({ targets, groupTargets = [], preferredDeviceId, onCreated, onGroupCreated }: CreateOptions) {
const { t } = useTranslation();
const { accountGeneration } = useAuth();
- const [account] = useState(accountGeneration);
+ const [account, setAccount] = useState(accountGeneration);
const currentAccount = useRef(accountGeneration); currentAccount.current = accountGeneration;
const mounted = useRef(true);
useEffect(() => { mounted.current = true; return () => { mounted.current = false; }; }, []);
@@ -43,6 +44,11 @@ export function useTeammateCreateController({ targets, groupTargets = [], prefer
const pendingChoice = useRef<Choice | null>(null);
const receipt = useRef<RemoteResourceRef | null>(null);
const groupReceipt = useRef<string | null>(null);
+ // Callbacks already handed out keep the old account and stay fenced; new ones serve the new account.
+ if (account !== accountGeneration) {
+ setAccount(accountGeneration); setOpen(null); setVisible(false); setChoosing(false);
+ }
+ useEffect(() => { pendingChoice.current = null; receipt.current = null; groupReceipt.current = null; }, [accountGeneration]);
const withGroups = groupTargets.length > 0 && !!onGroupCreated;
const order = (hosts: readonly RemoteResourceHostTarget[]) => [...hosts]
.sort((a, b) => Number(b.deviceId === preferredDeviceId) - Number(a.deviceId === preferredDeviceId));