11import { FlatList , Pressable , StyleSheet , Text , View } from 'react-native' ;
22import { DraftsIcon } from '../icons/DraftIcon' ;
33import {
4- FileTypes ,
54 MessagePreview ,
6- TranslationContextValue ,
75 useChatContext ,
86 useStateStore ,
97 useTheme ,
@@ -14,6 +12,7 @@ import { useCallback, useEffect, useMemo } from 'react';
1412import dayjs from 'dayjs' ;
1513import { useIsFocused , useNavigation } from '@react-navigation/native' ;
1614import { ChannelResponse , DraftMessage , DraftResponse , MessageResponseBase } from 'stream-chat' ;
15+ import { getPreviewFromMessage } from '../utils/getPreviewOfMessage' ;
1716
1817export type DraftItemProps = {
1918 type ?: 'channel' | 'thread' ;
@@ -24,67 +23,6 @@ export type DraftItemProps = {
2423 thread ?: MessageResponseBase ;
2524} ;
2625
27- export const attachmentTypeIconMap = {
28- audio : '🔈' ,
29- file : '📄' ,
30- image : '📷' ,
31- video : '🎥' ,
32- voiceRecording : '🎙️' ,
33- } as const ;
34-
35- const getPreviewFromMessage = ( {
36- t,
37- draftMessage,
38- } : {
39- t : TranslationContextValue [ 't' ] ;
40- draftMessage : DraftMessage ;
41- } ) => {
42- if ( draftMessage . attachments ?. length ) {
43- const attachment = draftMessage ?. attachments ?. at ( 0 ) ;
44-
45- const attachmentIcon = attachment
46- ? `${
47- attachmentTypeIconMap [
48- ( attachment . type as keyof typeof attachmentTypeIconMap ) ?? 'file'
49- ] ?? attachmentTypeIconMap . file
50- } `
51- : '' ;
52-
53- if ( attachment ?. type === FileTypes . VoiceRecording ) {
54- return [
55- { bold : false , text : attachmentIcon } ,
56- {
57- bold : false ,
58- text : t ( 'Voice message' ) ,
59- } ,
60- ] ;
61- }
62- return [
63- { bold : false , text : attachmentIcon } ,
64- {
65- bold : false ,
66- text :
67- attachment ?. type === FileTypes . Image
68- ? attachment ?. fallback
69- ? attachment ?. fallback
70- : 'N/A'
71- : attachment ?. title
72- ? attachment ?. title
73- : 'N/A' ,
74- } ,
75- ] ;
76- }
77-
78- if ( draftMessage . text ) {
79- return [
80- {
81- bold : false ,
82- text : draftMessage . text ,
83- } ,
84- ] ;
85- }
86- } ;
87-
8826export const DraftItem = ( { type, channel, date, message, thread } : DraftItemProps ) => {
8927 const {
9028 theme : {
@@ -113,7 +51,7 @@ export const DraftItem = ({ type, channel, date, message, thread }: DraftItemPro
11351 } ;
11452
11553 const previews = useMemo ( ( ) => {
116- return getPreviewFromMessage ( { draftMessage : message , t } ) ;
54+ return getPreviewFromMessage ( { message, t } ) ;
11755 } , [ message , t ] ) ;
11856
11957 return (
0 commit comments