@devries-cameron20 / t3code Mirror · read-only / commits / 38e946455a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

fix(mobile): unavailable thread links are labeled in the app language (#38651)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 19, 2026 at 03:48 UTC 38e946455a64ed3a4cc22c14679ae41d49424c54
4 files changed +56 -47
apps/mobile/src/state/entities.ts
+12 -7
@@ -20,11 +20,11 @@ import {
20 guessThreadLinkRef,
21 hasThreadLinks,
22 parseThreadLinkHref,
23 - relabelThreadLinks,
23 threadLinkCandidates,
24 threadLinkRefs,
25 type ThreadLink,
26 } from "@t3tools/shared/threadLinks";
27 +import { relabelThreadLinks } from "@t3tools/shared/threadLinksCopy";
28 import * as Schema from "effect/Schema";
29 import { AsyncResult, Atom } from "effect/reactivity";
30 import { msg, useMessages } from "gt-react-native";
@@ -246,12 +246,17 @@ export function useLiveThreadLinkLabels(markdown: string, environmentId: Environ
246 ? threadLinkTitlesAtom(JSON.stringify(threadLinkRefs(markdown, environmentId).map(threadKey)))
247 : EMPTY_THREAD_LINK_TITLES_ATOM,
248 );
249 - return relabelThreadLinks(markdown, environmentId, (ref) => {
250 - const title = titles.get(threadKey(ref));
251 - return title === FALLBACK_THREAD_TITLE
252 - ? resolve(msg("Thread", { $context: "fallback title of a linked thread" }))
253 - : title;
254 - });
249 + return relabelThreadLinks(
250 + markdown,
251 + environmentId,
252 + (ref) => {
253 + const title = titles.get(threadKey(ref));
254 + return title === FALLBACK_THREAD_TITLE
255 + ? resolve(msg("Thread", { $context: "fallback title of a linked thread" }))
256 + : title;
257 + },
258 + resolve,
259 + );
260 }
261
262 /** Keyed reads; every thread is read only to place a v1 link its message's environment lacks. */
packages/shared/src/threadLinks.test.ts
+12 -1
@@ -1,5 +1,7 @@
1 import { describe, expect, it, vi } from "vite-plus/test";
2 import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
3 +import { mFallback } from "gt-i18n";
4 +import type { MFunctionType } from "gt-i18n/types";
5
6 import {
7 formatHostedThreadLink,
@@ -7,10 +9,10 @@ import {
9 guessThreadLinkRef,
10 hostedThreadLink,
11 parseThreadLinkHref,
10 - relabelThreadLinks,
12 threadLinkCandidates,
13 threadLinkRefs,
14 } from "./threadLinks.ts";
15 +import { relabelThreadLinks } from "./threadLinksCopy.ts";
16
17 const ref = (environmentId: string, threadId = "chat-1") => ({
18 environmentId: EnvironmentId.make(environmentId),
@@ -22,6 +24,12 @@ const titlesIn =
24 (titles: Record<string, Record<string, string>>) =>
25 ({ environmentId, threadId }: ScopedThreadRef) =>
26 titles[environmentId]?.[threadId];
27 +const japanese: MFunctionType = (encodedMsg, options) => {
28 + const english = mFallback(encodedMsg, options);
29 + return (
30 + english === "Thread no longer available" ? "スレッドは利用できなくなりました" : english
31 + ) as typeof english;
32 +};
33
34 describe("thread link destinations", () => {
35 it("names a v1 link's thread in the message's environment, as written and then decoded", () => {
@@ -140,6 +148,9 @@ describe("thread links", () => {
148 expect(relabelThreadLinks("[Old](t3-thread://v1/t1)", local, () => undefined)).toBe(
149 "[Old](t3-thread://v1/t1)",
150 );
151 + expect(relabelThreadLinks("See <t3-thread://v1/gone>", local, () => undefined, japanese)).toBe(
152 + "See スレッドは利用できなくなりました",
153 + );
154 });
155
156 it("leaves links inside code spans and fences as written", () => {
packages/shared/src/threadLinks.ts
-37
@@ -179,12 +179,6 @@ export function threadLinkRefs(
179 return [...refs.values()];
180 }
181
182 -function unknownThreadLinkLabel(link: ThreadLink, messageEnvironmentId: EnvironmentId): string {
183 - return link.environmentId === null || link.environmentId === messageEnvironmentId
184 - ? "Thread no longer available"
185 - : "Thread on another machine";
186 -}
187 -
182 /** Rewrites each link outside code `replace` answers for. `label` is a Markdown link's own text. */
183 export function replaceThreadLinks(
184 markdown: string,
@@ -200,34 +194,3 @@ export function replaceThreadLinks(
194 return (link && replace(link, groups.label)) ?? source;
195 });
196 }
203 -
204 -/**
205 - * Writes each link with its thread's current title, a hosted link as a v2 link. A link `title`
206 - * cannot resolve becomes plain text, its written label or a neutral one, except a labeled v1
207 - * link, which may open elsewhere.
208 - */
209 -export function relabelThreadLinks(
210 - markdown: string,
211 - messageEnvironmentId: EnvironmentId,
212 - title: (ref: ScopedThreadRef) => string | undefined,
213 -): string {
214 - return replaceThreadLinks(markdown, (written, label) => {
215 - const environmentId = written.environmentId ?? messageEnvironmentId;
216 - const decoded = percentDecodedThreadLinkId(written.threadId);
217 - const threadId =
218 - title({ environmentId, threadId: written.threadId }) === undefined &&
219 - decoded !== null &&
220 - title({ environmentId, threadId: decoded }) !== undefined
221 - ? decoded
222 - : written.threadId;
223 - const current = title({ environmentId, threadId });
224 - if (current === undefined) {
225 - if (label !== undefined && written.environmentId === null) return undefined;
226 - return label?.trim() || unknownThreadLinkLabel(written, messageEnvironmentId);
227 - }
228 - return formatThreadLink(
229 - { environmentId: written.environmentId, threadId },
230 - current.trim() || label || threadId,
231 - );
232 - });
233 -}
packages/shared/src/threadLinksCopy.ts
+32 -2
@@ -1,8 +1,13 @@
1 -import type { EnvironmentId } from "@t3tools/contracts";
1 +import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
2 import { mFallback, msg } from "gt-i18n";
3 import type { MFunctionType } from "gt-i18n/types";
4
5 -import type { ThreadLink } from "./threadLinks.ts";
5 +import {
6 + formatThreadLink,
7 + replaceThreadLinks,
8 + threadLinkCandidates,
9 + type ThreadLink,
10 +} from "./threadLinks.ts";
11
12 /** @public */
13 export function unknownThreadLinkLabel(
@@ -14,3 +19,28 @@ export function unknownThreadLinkLabel(
19 ? resolve(msg("Thread no longer available"))
20 : resolve(msg("Thread on another machine"));
21 }
22 +
23 +/**
24 + * Writes each link with its thread's current title, a hosted link as a v2 link. A link `title`
25 + * cannot resolve becomes plain text, its written label or a neutral one, except a labeled v1
26 + * link, which may open elsewhere.
27 + */
28 +export function relabelThreadLinks(
29 + markdown: string,
30 + messageEnvironmentId: EnvironmentId,
31 + title: (ref: ScopedThreadRef) => string | undefined,
32 + resolve: MFunctionType = mFallback,
33 +): string {
34 + return replaceThreadLinks(markdown, (written, label) => {
35 + for (const ref of threadLinkCandidates(written, messageEnvironmentId)) {
36 + const current = title(ref);
37 + if (current === undefined) continue;
38 + return formatThreadLink(
39 + { environmentId: written.environmentId, threadId: ref.threadId },
40 + current.trim() || label || ref.threadId,
41 + );
42 + }
43 + if (label !== undefined && written.environmentId === null) return undefined;
44 + return label?.trim() || unknownThreadLinkLabel(written, messageEnvironmentId, resolve);
45 + });
46 +}