@@ -105,7 +105,8 @@ import { assetImageSource } from "../../lib/assetImageSource";
105105import { composerImageGallery } from "../../lib/composerImageGallery" ;
106106import { messageImageGallery } from "./messageImageGallery" ;
107107import { FilePreviewModal , type FilePreviewSource } from "../../components/FilePreviewModal" ;
108- import { isPdfFile } from "../../lib/filePreview" ;
108+ import { inlineFilePreviewKind , isPdfFile } from "../../lib/filePreview" ;
109+ import { ThreadInlineFilePreview } from "./ThreadInlineFilePreview" ;
109110import { flattenThemeColor } from "../../lib/mobileTheme" ;
110111import { PresentationSource } from "../../components/ui/NativePresentation" ;
111112import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -612,6 +613,55 @@ function MessageAttachmentFile(props: {
612613 } ) ( ) ;
613614 } ;
614615
616+ const openAttachment = ( ) =>
617+ isPdf
618+ ? props . onPressPreview ( {
619+ kind : "pdf" ,
620+ name : attachment . name ,
621+ environmentId : props . environmentId ,
622+ resource : {
623+ _tag : "attachment" ,
624+ attachmentId : attachment . id ,
625+ fileName : attachment . name ,
626+ mimeType : "application/pdf" ,
627+ } ,
628+ sourceIdentifier,
629+ } )
630+ : navigation . navigate ( "ThreadAttachment" , {
631+ environmentId : String ( props . environmentId ) ,
632+ ...( selectedThread ? { threadId : String ( selectedThread . id ) } : { } ) ,
633+ attachmentId : attachment . id ,
634+ name : attachment . name ,
635+ mimeType : attachment . mimeType ,
636+ sizeBytes : String ( attachment . sizeBytes ) ,
637+ } ) ;
638+ const inlineKind = inlineFilePreviewKind ( attachment ) ;
639+ if ( inlineKind ) {
640+ return (
641+ < PresentationSource identifier = { sourceIdentifier } >
642+ < ThreadInlineFilePreview
643+ key = { attachment . id }
644+ kind = { inlineKind }
645+ source = { {
646+ kind : inlineKind === "pdf" ? "pdf" : "document" ,
647+ name : attachment . name ,
648+ mimeType : attachment . mimeType ,
649+ environmentId : props . environmentId ,
650+ resource : {
651+ _tag : "attachment" ,
652+ attachmentId : attachment . id ,
653+ fileName : attachment . name ,
654+ mimeType : attachment . mimeType ,
655+ } ,
656+ } }
657+ sizeBytes = { attachment . sizeBytes }
658+ onOpen = { openAttachment }
659+ onLongPress = { ( ) => shareFile ( sourceIdentifier ) }
660+ />
661+ </ PresentationSource >
662+ ) ;
663+ }
664+
615665 if ( videoType !== null ) {
616666 const sourceIdentifier = `attachment:${ props . environmentId } :${ attachment . id } ` ;
617667 return (
@@ -646,29 +696,7 @@ function MessageAttachmentFile(props: {
646696 disabled = { opening || httpBaseUrl === null }
647697 className = "min-w-0 flex-row items-center gap-3 rounded-xl border border-border bg-card p-3 active:bg-subtle"
648698 onLongPress = { ( ) => shareFile ( sourceIdentifier ) }
649- onPress = { ( ) =>
650- isPdf
651- ? props . onPressPreview ( {
652- kind : "pdf" ,
653- name : attachment . name ,
654- environmentId : props . environmentId ,
655- resource : {
656- _tag : "attachment" ,
657- attachmentId : attachment . id ,
658- fileName : attachment . name ,
659- mimeType : "application/pdf" ,
660- } ,
661- sourceIdentifier,
662- } )
663- : navigation . navigate ( "ThreadAttachment" , {
664- environmentId : String ( props . environmentId ) ,
665- ...( selectedThread ? { threadId : String ( selectedThread . id ) } : { } ) ,
666- attachmentId : attachment . id ,
667- name : attachment . name ,
668- mimeType : attachment . mimeType ,
669- sizeBytes : String ( attachment . sizeBytes ) ,
670- } )
671- }
699+ onPress = { openAttachment }
672700 >
673701 < View className = "h-12 w-10 shrink-0 items-center justify-center rounded-lg bg-subtle" >
674702 { opening ? (
@@ -1808,6 +1836,17 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
18081836 void Haptics . selectionAsync ( ) ;
18091837 if ( media . kind === "video" ) {
18101838 setExpandedVideo ( ( current ) => current ?? media . source ) ;
1839+ } else if (
1840+ ( media . kind === "audio" || media . kind === "table" ) &&
1841+ "resource" in media . source &&
1842+ "path" in media . source . resource &&
1843+ typeof media . source . resource . path === "string"
1844+ ) {
1845+ navigation . navigate ( "ThreadFile" , {
1846+ environmentId : String ( props . environmentId ) ,
1847+ threadId : String ( props . threadId ) ,
1848+ path : fileRoutePathSegments ( media . source . resource . path ) ,
1849+ } ) ;
18111850 } else {
18121851 setExpandedFile ( ( current ) => current ?? media . source ) ;
18131852 }
@@ -1897,6 +1936,16 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
18971936 />
18981937 ) ;
18991938 }
1939+ if ( media && ( media . kind === "audio" || media . kind === "pdf" || media . kind === "table" ) ) {
1940+ return (
1941+ < ThreadInlineFilePreview
1942+ key = { image . href }
1943+ kind = { media . kind }
1944+ source = { media . source }
1945+ onOpen = { ( ) => onMarkdownLinkPress ( image . href , true ) }
1946+ />
1947+ ) ;
1948+ }
19001949 const imageSource = classifyMarkdownImageSource ( image . href , props . workspaceRoot ?? null ) ;
19011950 if ( imageSource . _tag === "Direct" ) {
19021951 return (
0 commit comments