@@ -2,6 +2,7 @@ import * as Clipboard from "expo-clipboard";
22import * as Haptics from "expo-haptics" ;
33import { KeyboardAvoidingLegendList } from "@legendapp/list/keyboard" ;
44import { type LegendListRef } from "@legendapp/list/react-native" ;
5+ import { useLocalSearchParams , useRouter } from "expo-router" ;
56import { SymbolView } from "expo-symbols" ;
67import { memo , useCallback , useEffect , useMemo , useRef , useState } from "react" ;
78import {
@@ -22,6 +23,7 @@ import { TouchableOpacity } from "react-native-gesture-handler";
2223import ImageViewing from "react-native-image-viewing" ;
2324import { useSafeAreaInsets } from "react-native-safe-area-context" ;
2425import { useThemeColor } from "../../lib/useThemeColor" ;
26+ import { setMessageCopyText } from "./messageCopySelection" ;
2527
2628import { AppText as Text } from "../../components/AppText" ;
2729import { EmptyState } from "../../components/EmptyState" ;
@@ -325,6 +327,7 @@ function renderFeedEntry(
325327 readonly expandedWorkGroups : Record < string , boolean > ;
326328 readonly onCopyWorkRow : ( rowId : string , value : string ) => void ;
327329 readonly onToggleWorkGroup : ( groupId : string ) => void ;
330+ readonly onLongPressMessage : ( text : string ) => void ;
328331 readonly onPressImage : ( uri : string , headers ?: Record < string , string > ) => void ;
329332 readonly iconSubtleColor : string | import ( "react-native" ) . ColorValue ;
330333 readonly markdownStyles : MarkdownStyleSets ;
@@ -343,41 +346,43 @@ function renderFeedEntry(
343346 if ( isUser ) {
344347 return (
345348 < View className = "mb-3.5 items-end gap-1.5" >
346- < View className = "max-w-[85%] gap-2 rounded-[22px] rounded-br-[10px] border border-blue-300/50 bg-blue-50/80 px-4 py-4 dark:border-blue-400/20 dark:bg-blue-500/12" >
347- { message . text . trim ( ) . length > 0 ? (
348- < Markdown
349- options = { { gfm : true } }
350- renderers = { styles . renderers }
351- styles = { styles . styles }
352- theme = { styles . theme }
353- >
354- { message . text }
355- </ Markdown >
356- ) : null }
357- { attachments . map ( ( attachment ) => {
358- const uri = messageImageUrl ( props . httpBaseUrl , attachment . id ) ;
359- if ( ! uri ) {
360- return null ;
361- }
362- const headers = props . bearerToken
363- ? { Authorization : `Bearer ${ props . bearerToken } ` }
364- : undefined ;
365-
366- return (
367- < TouchableOpacity
368- key = { attachment . id }
369- activeOpacity = { 0.7 }
370- onPress = { ( ) => props . onPressImage ( uri , headers ) }
349+ < Pressable onLongPress = { ( ) => props . onLongPressMessage ( message . text ) } >
350+ < View className = "max-w-[85%] gap-2 rounded-[22px] rounded-br-[10px] border border-blue-300/50 bg-blue-50/80 px-4 py-4 dark:border-blue-400/20 dark:bg-blue-500/12" >
351+ { message . text . trim ( ) . length > 0 ? (
352+ < Markdown
353+ options = { { gfm : true } }
354+ renderers = { styles . renderers }
355+ styles = { styles . styles }
356+ theme = { styles . theme }
371357 >
372- < Image
373- source = { { uri, ...( headers ? { headers } : { } ) } }
374- className = "aspect-[1.3] w-full rounded-[18px] bg-neutral-200 dark:bg-neutral-800"
375- resizeMode = "cover"
376- />
377- </ TouchableOpacity >
378- ) ;
379- } ) }
380- </ View >
358+ { message . text }
359+ </ Markdown >
360+ ) : null }
361+ { attachments . map ( ( attachment ) => {
362+ const uri = messageImageUrl ( props . httpBaseUrl , attachment . id ) ;
363+ if ( ! uri ) {
364+ return null ;
365+ }
366+ const headers = props . bearerToken
367+ ? { Authorization : `Bearer ${ props . bearerToken } ` }
368+ : undefined ;
369+
370+ return (
371+ < TouchableOpacity
372+ key = { attachment . id }
373+ activeOpacity = { 0.7 }
374+ onPress = { ( ) => props . onPressImage ( uri , headers ) }
375+ >
376+ < Image
377+ source = { { uri, ...( headers ? { headers } : { } ) } }
378+ className = "aspect-[1.3] w-full rounded-[18px] bg-neutral-200 dark:bg-neutral-800"
379+ resizeMode = "cover"
380+ />
381+ </ TouchableOpacity >
382+ ) ;
383+ } ) }
384+ </ View >
385+ </ Pressable >
381386 < Text className = "px-1 text-right font-t3-medium text-xs text-neutral-500 dark:text-neutral-500" >
382387 { timestampLabel }
383388 </ Text >
@@ -392,44 +397,46 @@ function renderFeedEntry(
392397 }
393398
394399 return (
395- < View className = "mb-3.5 gap-1.5 px-1" >
396- { message . text . trim ( ) . length > 0 ? (
397- < Markdown
398- options = { { gfm : true } }
399- renderers = { styles . renderers }
400- styles = { styles . styles }
401- theme = { styles . theme }
402- >
403- { message . text }
404- </ Markdown >
405- ) : null }
406- { attachments . map ( ( attachment ) => {
407- const uri = messageImageUrl ( props . httpBaseUrl , attachment . id ) ;
408- if ( ! uri ) {
409- return null ;
410- }
411- const headers = props . bearerToken
412- ? { Authorization : `Bearer ${ props . bearerToken } ` }
413- : undefined ;
414-
415- return (
416- < TouchableOpacity
417- key = { attachment . id }
418- activeOpacity = { 0.7 }
419- onPress = { ( ) => props . onPressImage ( uri , headers ) }
400+ < Pressable onLongPress = { ( ) => props . onLongPressMessage ( message . text ) } >
401+ < View className = "mb-3.5 gap-1.5 px-1" >
402+ { message . text . trim ( ) . length > 0 ? (
403+ < Markdown
404+ options = { { gfm : true } }
405+ renderers = { styles . renderers }
406+ styles = { styles . styles }
407+ theme = { styles . theme }
420408 >
421- < Image
422- source = { { uri, ...( headers ? { headers } : { } ) } }
423- className = "aspect-[1.3] w-full rounded-[18px] bg-neutral-200 dark:bg-neutral-800"
424- resizeMode = "cover"
425- />
426- </ TouchableOpacity >
427- ) ;
428- } ) }
429- < Text className = "font-t3-medium text-xs text-neutral-500 dark:text-neutral-500" >
430- { timestampLabel }
431- </ Text >
432- </ View >
409+ { message . text }
410+ </ Markdown >
411+ ) : null }
412+ { attachments . map ( ( attachment ) => {
413+ const uri = messageImageUrl ( props . httpBaseUrl , attachment . id ) ;
414+ if ( ! uri ) {
415+ return null ;
416+ }
417+ const headers = props . bearerToken
418+ ? { Authorization : `Bearer ${ props . bearerToken } ` }
419+ : undefined ;
420+
421+ return (
422+ < TouchableOpacity
423+ key = { attachment . id }
424+ activeOpacity = { 0.7 }
425+ onPress = { ( ) => props . onPressImage ( uri , headers ) }
426+ >
427+ < Image
428+ source = { { uri, ...( headers ? { headers } : { } ) } }
429+ className = "aspect-[1.3] w-full rounded-[18px] bg-neutral-200 dark:bg-neutral-800"
430+ resizeMode = "cover"
431+ />
432+ </ TouchableOpacity >
433+ ) ;
434+ } ) }
435+ < Text className = "font-t3-medium text-xs text-neutral-500 dark:text-neutral-500" >
436+ { timestampLabel }
437+ </ Text >
438+ </ View >
439+ </ Pressable >
433440 ) ;
434441 }
435442
@@ -524,6 +531,9 @@ const IOS_NAV_BAR_HEIGHT = 44;
524531
525532export const ThreadFeed = memo ( function ThreadFeed ( props : ThreadFeedProps ) {
526533 const listRef = useRef < LegendListRef > ( null ) ;
534+ const router = useRouter ( ) ;
535+ const { environmentId } = useLocalSearchParams < { environmentId ?: string | string [ ] } > ( ) ;
536+ const resolvedEnvironmentId = Array . isArray ( environmentId ) ? environmentId [ 0 ] : environmentId ;
527537 const copyFeedbackTimeoutRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
528538 const [ copiedRowId , setCopiedRowId ] = useState < string | null > ( null ) ;
529539 const [ expandedWorkGroups , setExpandedWorkGroups ] = useState < Record < string , boolean > > ( { } ) ;
@@ -563,6 +573,19 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
563573 } ;
564574 } , [ ] ) ;
565575
576+ const onLongPressMessage = useCallback (
577+ ( text : string ) => {
578+ if ( ! resolvedEnvironmentId ) return ;
579+ void Haptics . selectionAsync ( ) ;
580+ setMessageCopyText ( text ) ;
581+ router . push ( {
582+ pathname : "/threads/[environmentId]/[threadId]/message-copy" ,
583+ params : { environmentId : resolvedEnvironmentId , threadId : props . threadId } ,
584+ } ) ;
585+ } ,
586+ [ resolvedEnvironmentId , props . threadId , router ] ,
587+ ) ;
588+
566589 const onCopyWorkRow = useCallback ( ( rowId : string , value : string ) => {
567590 void Clipboard . setStringAsync ( value ) ;
568591 void Haptics . selectionAsync ( ) ;
@@ -594,6 +617,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
594617 copiedRowId,
595618 httpBaseUrl : props . httpBaseUrl ,
596619 expandedWorkGroups,
620+ onLongPressMessage,
597621 onCopyWorkRow,
598622 onToggleWorkGroup,
599623 onPressImage,
@@ -605,6 +629,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
605629 expandedWorkGroups ,
606630 iconSubtleColor ,
607631 markdownStyles ,
632+ onLongPressMessage ,
608633 onCopyWorkRow ,
609634 onPressImage ,
610635 onToggleWorkGroup ,
0 commit comments