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): limit hidden chat navigation to the focused page

zqchrise832107ae401
diff --git a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
index 511909d5d2..1ec3b62906 100644
--- a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
+++ b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
@@ -10,6 +10,7 @@ const h = vi.hoisted(() => ({
alert: vi.fn(),
confirm: vi.fn(),
leave: vi.fn(),
+ focused: true,
closeSettings: null as null | (() => void),
row: null as any,
inputs: {} as Record<string, any>,
@@ -57,7 +58,7 @@ vi.mock('react-native', () => {
};
});
vi.mock('expo-router', () => ({
- useIsFocused: () => true,
+ useIsFocused: () => h.focused,
Stack: { Screen: () => null },
useRouter: () => ({ back: vi.fn(), replace: vi.fn() }),
useFocusEffect: (effect: () => void) => useEffect(effect, [effect]),
@@ -270,7 +271,7 @@ beforeEach(() => {
h.management = null;
vi.clearAllMocks();
h.uuid = 0; h.inputs = {}; h.teammateQuery = ''; h.teammates = { rows: [], loading: false, failed: false };
- h.platform.OS = 'ios'; h.keyboardAvoidingView = null; h.headerBlur = []; h.headerFade = [];
+ h.platform.OS = 'ios'; h.focused = true; h.keyboardAvoidingView = null; h.headerBlur = []; h.headerFade = [];
h.chat = { reload: vi.fn(), act: vi.fn(async () => ({ effects: [] })), online: true };
h.discarded = []; h.deleted = [];
h.local = {
@@ -877,6 +878,16 @@ describe('group settings', () => {
expect(h.leave).toHaveBeenCalledOnce();
});
+ it('keeps a hidden background page from navigating another route and leaves when focused again', async () => {
+ await render(group({ serverBacked: true }));
+ h.focused = false; h.chat.listHidden = true;
+ await render(null, 'missing');
+ expect(h.leave).not.toHaveBeenCalled();
+ h.focused = true;
+ await render(null, 'missing');
+ expect(h.leave).toHaveBeenCalledOnce();
+ });
+
it('resets lifecycle busy on reopen and keeps an old reply out of a new request', async () => {
const data = group({ serverBacked: true, supportsDissolve: true, revision: 1,
members: [{ botId: 'mimi', actorId: 'mimi', name: 'Mimi', avatar: '', avatarColor: '', status: 'active', isOwned: true, role: 'owner' }] });
diff --git a/apps/mobile/src/session/BotGroupChatScreen.tsx b/apps/mobile/src/session/BotGroupChatScreen.tsx
index a003096e95..3fceba2ed4 100644
--- a/apps/mobile/src/session/BotGroupChatScreen.tsx
+++ b/apps/mobile/src/session/BotGroupChatScreen.tsx
@@ -199,14 +199,15 @@ export function BotGroupChatScreen({ deviceId, deviceName, groupId }: { deviceId
hideScope.current = currentHideScope;
useEffect(() => () => { hideScope.current = ''; }, []);
const leftScope = useRef('');
+ const focusedRef = useRef(focused); focusedRef.current = focused;
const leaveCurrentChat = useCallback((captured: string) => {
- if (hideScope.current !== captured || leftScope.current === captured) return;
+ if (!focusedRef.current || hideScope.current !== captured || leftScope.current === captured) return;
leftScope.current = captured;
leave();
}, [leave]);
useEffect(() => {
- if (chat.listHidden) leaveCurrentChat(currentHideScope);
- }, [chat.listHidden, currentHideScope, leaveCurrentChat]);
+ if (focused && chat.listHidden) leaveCurrentChat(currentHideScope);
+ }, [focused, chat.listHidden, currentHideScope, leaveCurrentChat]);
const actFromSettings: typeof chat.act = async (action, input) => {
const captured = currentHideScope;
const receipt = await chat.act(action, input);