import * as React from 'react'; import { // Dimensions, // Image as RNImage, Pressable, 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 { HighText, SingleLineText } from '../../ui/Text'; import { formatTsForConvList } from '../../utils'; import { Avatar } from '../Avatar'; import { useMessageSnapshot } from '../hooks/useMessageSnapshot'; import type { MessageSearchItemProps } from './types'; export function MessageSearchItem(props: MessageSearchItemProps) { const { model, onClicked } = props; const { msg, keyword } = model; const { userId, userName, avatarURL } = userInfoFromMessage(msg) ?? {}; const { formatTime } = useConfigContext(); const { colors } = usePaletteContext(); const { getColor } = useColors({ t2: { light: colors.neutral[5], dark: colors.neutral[6], }, }); const { getMessageSnapshot } = useMessageSnapshot(); const msgType = msg.body.type; 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) { return cb ? cb(msg.localTime) : formatTsForConvList(msg.localTime); } else { return ''; } }, [formatTime?.conversationListCallback] ); return ( { onClicked?.(model); }} > {userName ?? userId} {getMessageFormatTime(msg)} {msgType === ChatMessageType.TXT ? ( ) : null} ); } export const MessageSearchItemMemo = React.memo(MessageSearchItem);