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): 会话深链指向已归档任务时按当前电脑打开,不再报同步失败

Dasha3c7c709877e
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index f1b6075ba2..f9b7bf83fd 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -618,6 +618,7 @@ import { countMobileRenderItemDiffs } from '@/session/messagePresentation';
import {
buildMobileSessionMessageDeepLink,
parseSessionDeepLinkUrl,
+ resolveSessionLinkDeviceId,
} from '@/session/sessionLinks';
import {
extractMobileSessionReferences,
@@ -9386,11 +9387,16 @@ function SessionScreenContent() {
}
return;
}
- // 设备口径与 devices/index openSession 一致:可达优先(canonical → 物理 → 注册表)。
+ // 设备口径与 devices/index openSession 一致:可达优先(canonical → 物理 → 注册表);
+ // 列表里没有的(已归档 / 尚未同步)退回深链冻结设备、当前任务所在设备。
const targetSession = remoteSessionStore.getSessions().find((item) => item.id === target.sessionId);
- const targetDeviceId = targetSession?.canonicalDeviceId
- ?? targetSession?.deviceLinkDeviceId
- ?? remoteSessionStore.getSessionDeviceId(target.sessionId);
+ const targetDeviceId = resolveSessionLinkDeviceId({
+ listedDeviceId: targetSession?.canonicalDeviceId
+ ?? targetSession?.deviceLinkDeviceId
+ ?? remoteSessionStore.getSessionDeviceId(target.sessionId),
+ linkedDeviceId: target.deviceId,
+ currentDeviceId: deviceId,
+ });
if (!targetDeviceId) {
setError(t('session.screen.sessionDeviceNotFound'));
return;
@@ -9400,7 +9406,9 @@ function SessionScreenContent() {
params: {
sessionId: target.sessionId,
deviceId: targetDeviceId,
- deviceName: targetSession?.deviceLinkDeviceName ?? targetDeviceId,
+ deviceName: targetSession?.deviceLinkDeviceName
+ ?? (targetDeviceId === deviceId ? deviceName : undefined)
+ ?? targetDeviceId,
...(target.messageClientId
? {
focusClientId: target.messageClientId,
@@ -9409,7 +9417,7 @@ function SessionScreenContent() {
: {}),
},
});
- }, [router, sessionId]);
+ }, [deviceId, deviceName, router, sessionId, setError, t]);
// 长按/操作条「复制消息链接」:复制带消息锚点的会话深链,可跨端粘贴跳转。
const copyMessageLink = useCallback((clientId: string) => {
@@ -9423,9 +9431,13 @@ function SessionScreenContent() {
const targetSession = remoteSessionStore.getSessions().find((item) => (
item.id === target.sessionId
));
- const targetDeviceId = targetSession?.canonicalDeviceId
- ?? targetSession?.deviceLinkDeviceId
- ?? remoteSessionStore.getSessionDeviceId(target.sessionId);
+ const targetDeviceId = resolveSessionLinkDeviceId({
+ listedDeviceId: targetSession?.canonicalDeviceId
+ ?? targetSession?.deviceLinkDeviceId
+ ?? remoteSessionStore.getSessionDeviceId(target.sessionId),
+ linkedDeviceId: target.deviceId,
+ currentDeviceId: deviceId,
+ });
const targetMaker = targetDeviceId
? (targetDeviceId === deviceId
? maker
diff --git a/apps/mobile/src/__tests__/sessionLinks.test.ts b/apps/mobile/src/__tests__/sessionLinks.test.ts
index cf2babfda1..06cc8cf590 100644
--- a/apps/mobile/src/__tests__/sessionLinks.test.ts
+++ b/apps/mobile/src/__tests__/sessionLinks.test.ts
@@ -4,6 +4,7 @@ import {
buildMobileSessionMessageDeepLink,
extractSessionLinkIds,
parseSessionDeepLinkUrl,
+ resolveSessionLinkDeviceId,
shortSessionId,
} from '@/session/sessionLinks';
@@ -81,6 +82,27 @@ describe('session links', () => {
expect(extractSessionLinkIds('没有链接')).toEqual([]);
});
+ it('resolves the device for a session link, falling back when the target is not listed', () => {
+ // 已同步列表里的可达设备优先于深链冻结值(re-link 后冻结值可能已过期)。
+ expect(resolveSessionLinkDeviceId({
+ listedDeviceId: 'listed',
+ linkedDeviceId: 'linked',
+ currentDeviceId: 'current',
+ })).toBe('listed');
+ // 已归档 / 未同步的任务不在列表里:先用深链冻结设备,再退回当前任务所在设备。
+ expect(resolveSessionLinkDeviceId({
+ listedDeviceId: undefined,
+ linkedDeviceId: 'linked',
+ currentDeviceId: 'current',
+ })).toBe('linked');
+ expect(resolveSessionLinkDeviceId({
+ listedDeviceId: undefined,
+ linkedDeviceId: null,
+ currentDeviceId: 'current',
+ })).toBe('current');
+ expect(resolveSessionLinkDeviceId({ linkedDeviceId: null, currentDeviceId: undefined })).toBeNull();
+ });
+
it('shortens long session ids for display', () => {
expect(shortSessionId('03e0c22d-19db-4ac5-814f-1ea04040b471')).toBe('03e0c22d…b471');
expect(shortSessionId('short-id')).toBe('short-id');
diff --git a/apps/mobile/src/session/sessionLinks.ts b/apps/mobile/src/session/sessionLinks.ts
index 3eeb1b361d..95989da3f4 100644
--- a/apps/mobile/src/session/sessionLinks.ts
+++ b/apps/mobile/src/session/sessionLinks.ts
@@ -89,6 +89,24 @@ export function parseSessionDeepLinkUrl(url: string): SessionDeepLinkTarget | nu
return { sessionId, messageClientId, deviceId };
}
+/**
+ * 点开 / 解析会话深链时目标任务所在的设备。已同步列表反查到的可达设备优先
+ * (re-link 后深链冻结的 `?device=` 可能已过期);列表里没有(已归档 / 尚未同步)
+ * 时用冻结值,再退回当前任务所在设备——正文里的深链多由当前任务所在电脑生成,
+ * 归档任务不在列表里,但仍在那台电脑上。
+ */
+export function resolveSessionLinkDeviceId({
+ listedDeviceId,
+ linkedDeviceId,
+ currentDeviceId,
+}: {
+ listedDeviceId?: string | null;
+ linkedDeviceId?: string | null;
+ currentDeviceId?: string | null;
+}): string | null {
+ return listedDeviceId || linkedDeviceId || currentDeviceId || null;
+}
+
/**
* 会话深链的文本匹配正则(ASCII 白名单,CJK / 空白 / 中文标点处天然收尾)。
* tokenizer 与标题预取共用同一来源;`g` flag 使用方需注意 lastIndex,