diff --git a/apps/mobile/src/features/threads/LinkedThreadSheet.tsx b/apps/mobile/src/features/threads/LinkedThreadSheet.tsx index 0096c9d576a91..cc345f60d77bb 100644 --- a/apps/mobile/src/features/threads/LinkedThreadSheet.tsx +++ b/apps/mobile/src/features/threads/LinkedThreadSheet.tsx @@ -26,6 +26,8 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator"; import { AppText as Text } from "../../components/ui/AppText"; import { Button } from "../../components/ui/Button"; import { ScreenContent } from "../../components/ui/ScreenContent"; +import { resolveMarkdownLinkPresentation } from "../../lib/markdownLinks"; +import { tryOpenExternalUrl } from "../../lib/openExternalUrl"; import { SelectableMarkdownText } from "../../native/SelectableMarkdownText"; import { useEnvironments } from "../../state/environments"; import { @@ -44,6 +46,15 @@ import { ReadOnlyComposerBar } from "./ReadOnlyComposerBar"; import { ThreadInspectorHeader, type ThreadInspectorPresentation } from "./thread-inspector-header"; import { useOpenLinkedThread } from "./useOpenLinkedThread"; +function openWebLink(href: string) { + const link = resolveMarkdownLinkPresentation(href); + if (link.kind === "external") void tryOpenExternalUrl(link.href, "markdown-link"); +} + +function canOpenWebLink(href: string) { + return resolveMarkdownLinkPresentation(href).kind === "external"; +} + function ActivityRow(props: { readonly activity: ThreadFeedActivity; readonly target: LinkedThreadTarget; @@ -163,7 +174,14 @@ function LinkedThreadEntry(props: { } // A message the agent sent with a tool reads as its own words, as on the thread screen. if (entry.type === "sent-message") { - return ; + return ( + + ); } if (entry.type !== "message" || entry.message.text.trim() === "") return null; return entry.message.role === "user" ? ( @@ -173,7 +191,12 @@ function LinkedThreadEntry(props: { ) : ( - + ); } diff --git a/apps/mobile/src/native/EnrichedMarkdownText.tsx b/apps/mobile/src/native/EnrichedMarkdownText.tsx index ff542959413ec..71b89c11d0b2a 100644 --- a/apps/mobile/src/native/EnrichedMarkdownText.tsx +++ b/apps/mobile/src/native/EnrichedMarkdownText.tsx @@ -346,19 +346,21 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) { else if (actionId === "enriched-share-link") void Share.share({ message: url }); else onFileContextMenuAction?.(url, actionId); }; + const defaultLinkMenu = (url: string) => ({ + title: url, + actions: [ + ...(props.canOpenLinkFromMenu?.(url) === false + ? [] + : [{ id: "enriched-open-link", title: gt("Open link") }]), + { id: "enriched-copy-link", title: gt("Copy link") }, + ...(Platform.OS === "ios" ? [{ id: "enriched-share-link", title: gt("Share link") }] : []), + ], + }); const linkContextMenuItems = Platform.OS === "ios" && (fileContextMenu || props.onLinkPress || props.onImagePress) ? Object.fromEntries( linkUrls.map((url) => { - const menu = modelContextMenu(url) ?? - fileContextMenu?.(url) ?? { - title: url, - actions: [ - { id: "enriched-open-link", title: gt("Open link") }, - { id: "enriched-copy-link", title: gt("Copy link") }, - { id: "enriched-share-link", title: gt("Share link") }, - ], - }; + const menu = modelContextMenu(url) ?? fileContextMenu?.(url) ?? defaultLinkMenu(url); return [ enrichedLinkVariantPattern(url), menu.actions.map((action) => ({ @@ -438,14 +440,8 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) { const onLinkLongPress = Platform.OS === "android" && props.fileContextMenu ? ({ url }: { url: string }) => { - const menu = modelContextMenu(url) ?? - props.fileContextMenu?.(url) ?? { - title: url, - actions: [ - { id: "enriched-open-link", title: gt("Open link") }, - { id: "enriched-copy-link", title: gt("Copy link") }, - ], - }; + const menu = + modelContextMenu(url) ?? props.fileContextMenu?.(url) ?? defaultLinkMenu(url); setActiveMenu({ url, menu }); openAndroidMenu?.(); } diff --git a/apps/mobile/src/native/SelectableMarkdownText.types.ts b/apps/mobile/src/native/SelectableMarkdownText.types.ts index 95b9545122b97..13ed9f6685815 100644 --- a/apps/mobile/src/native/SelectableMarkdownText.types.ts +++ b/apps/mobile/src/native/SelectableMarkdownText.types.ts @@ -77,6 +77,7 @@ export interface SelectableMarkdownTextProps { readonly models?: ReadonlyArray; readonly preserveSoftBreaks?: boolean; readonly onLinkPress?: (href: string) => void; + readonly canOpenLinkFromMenu?: (href: string) => boolean; readonly onCiteText?: (text: string) => void; readonly fileContextMenu?: (href: string) => MarkdownFileContextMenu | undefined; readonly onFileContextMenuAction?: (href: string, actionId: string) => void;