import * as React from 'react'; import { Dimensions, // Image as RNImage, Pressable, StyleSheet, View, } from 'react-native'; import { userInfoFromMessage } from '../../chat/utils'; import { useConfigContext } from '../../config'; import { useColors } from '../../hook/useColors'; import { ChatMessage, ChatMessageType } from '../../rename.chat'; import { usePaletteContext } from '../../theme'; import { Icon } from '../../ui/Image'; import { SingleLineText, Text } from '../../ui/Text'; import { formatTsForConvList } from '../../utils'; import { Avatar } from '../Avatar'; import { useMessageSnapshot } from '../hooks/useMessageSnapshot'; import { MessageDefaultImage } from './MessageListItem'; import { getImageShowSize, getImageThumbUrl, getVideoThumbUrl, } from './MessageListItem.hooks'; import type { MessageHistoryListItemProps } from './types'; export function MessageHistoryListItem(props: MessageHistoryListItemProps) { const { model, onClicked, containerStyle } = props; const { msg } = model; const { userId, userName, avatarURL } = userInfoFromMessage(msg) ?? {}; const { formatTime } = useConfigContext(); const { getColor } = useColors(); const msgType = msg.body.type; const maxWidth = Dimensions.get('window').width * 0.6; const maxTextWidth = Dimensions.get('window').width - 32 - 16 * 2 - 12; const { getMessageSnapshot } = useMessageSnapshot(); const getMessageFormatTime = React.useCallback( (msg?: ChatMessage, timestamp?: number): string => { const cb = formatTime?.conversationListCallback; if (msg === undefined && timestamp) { return cb ? cb(timestamp) : formatTsForConvList(timestamp); } else if (msg) { // !!! local time is bug. return cb ? cb(msg.serverTime) : formatTsForConvList(msg.serverTime); } else { return ''; } }, [formatTime?.conversationListCallback] ); return ( onClicked?.(model)} onLongPress={() => {}} > {userName ?? userId} {getMessageFormatTime(msg)} {msgType === ChatMessageType.IMAGE ? ( ) : msgType === ChatMessageType.VIDEO ? ( ) : ( {getMessageSnapshot(msg)} )} ); } export type MessageHistoryImageProps = { msg: ChatMessage; maxWidth?: number; }; export function MessageHistoryImage(props: MessageHistoryImageProps) { const { msg, maxWidth } = props; // const url1 = // '/storage/emulated/0/Android/data/com.hyphenate.rn.ChatUikitExample/1135220126133718#demo/files/asterisk003/asterisk001/53e8d540-a144-11ee-a811-ab4c303d7025.jpg'; // const url3 = // 'file:///storage/emulated/0/Android/data/com.hyphenate.rn.ChatUikitExample/1135220126133718%23demo/files/asterisk003/asterisk001/53e8d540-a144-11ee-a811-ab4c303d7025.jpg'; // const url5 = // 'file:///storage/emulated/0/Android/data/com.hyphenate.rn.ChatUikitExample/1135220126133718#demo/files/asterisk003/asterisk001/53e8d540-a144-11ee-a811-ab4c303d7025.jpg'; // const url2 = // '/var/mobile/Containers/Data/Application/CC0AD493-D627-463B-B351-44500E6FB1E2/tmp/AD1256B8-B32C-4CFE-B5F5-ECA21662B4E8.jpg'; const [thumbUrl, setThumbUrl] = React.useState(undefined); const { width, height } = getImageShowSize(msg, maxWidth); React.useEffect(() => { msg.status; getImageThumbUrl(msg) .then((url) => { setThumbUrl(url); }) .catch(); }, [msg, msg.status]); return ( ); } export type MessageHistoryVideoProps = { msg: ChatMessage; maxWidth?: number; }; export function MessageHistoryVideo(props: MessageHistoryVideoProps) { const { msg, maxWidth } = props; const [thumbUrl, setThumbUrl] = React.useState(); const { width, height } = getImageShowSize(msg, maxWidth); const [showTriangle, setShowTriangle] = React.useState(true); const { colors } = usePaletteContext(); const { getColor } = useColors({ video: { light: colors.neutral[98], dark: colors.neutral[95], }, }); React.useEffect(() => { msg.status; getVideoThumbUrl(msg) .then((url) => { if (url) { setThumbUrl(url); } }) .catch(); }, [msg, msg.status]); return ( { setShowTriangle(false); }} /> {showTriangle === true ? ( ) : null} ); } export const MessageHistoryListItemMemo = React.memo(MessageHistoryListItem);