import CancelSvg from '@/assets/icons/svg/cancel.svg'; import ChatSvg from "@/assets/icons/svg/chat.svg"; import DownloadSvg from '@/assets/icons/svg/download.svg'; import MoreSvg from "@/assets/icons/svg/more.svg"; import { Message, Video } from "@/types/ask"; import { MaterialItem } from "@/types/personal-info"; import { TFunction } from "i18next"; import React from 'react'; import { Image, Pressable, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import ContextMenu from "../gusture/contextMenu"; import { ThemedText } from "../ThemedText"; import SelectModel from "./selectModel"; import SingleContentModel from "./singleContentModel"; import Loading from './threeCircle'; import { mergeArrays, saveMediaToGallery } from "./utils"; interface RenderMessageProps { insets: { top: number }; item: Message; sessionId: string; setModalVisible: React.Dispatch>; modalVisible: { visible: boolean, data: Video | MaterialItem }; setModalDetailsVisible: React.Dispatch>; modalDetailsVisible: { visible: boolean, content: any }; setSelectedImages: React.Dispatch>; selectedImages: string[]; t: TFunction; setCancel: React.Dispatch>; cancel: boolean; } const MessageItem = ({ setCancel, cancel = true, t, insets, item, sessionId, setModalVisible, modalVisible, setModalDetailsVisible, modalDetailsVisible, setSelectedImages, selectedImages }: RenderMessageProps) => { const isUser = item.role === 'User'; return ( {!isUser && } 0 || item.content.image_material_infos && item.content.image_material_infos.length > 0) ? '!rounded-t-3xl !rounded-b-2xl' : '!rounded-3xl'}`} style={[ styles.messageBubble, isUser ? styles.userBubble : styles.aiBubble, { marginRight: item.content.text == "正在寻找,请稍等..." ? 0 : isUser ? 0 : 10 } ]} > {!isUser ? sessionId ? item.content.text : item.content.text == "正在寻找,请稍等..." ? : item.content.text : item.content.text } {(mergeArrays(item.content.image_material_infos || [], item.content.video_material_infos || [])?.length || 0 > 0) && ( {mergeArrays(item.content.image_material_infos || [], item.content.video_material_infos || [])?.slice(0, 3)?.map((image) => ( { setModalVisible({ visible: true, data: image }); }} style={{ width: '32%', aspectRatio: 1, marginBottom: 8, }} > , label: t("ask:ask.save"), onPress: () => { const imageUrl = image?.preview_file_info?.url || image.video?.preview_file_info?.url; if (imageUrl) { saveMediaToGallery(imageUrl, t); } }, textStyle: { color: '#4C320C' } }, { svg: , label: t("ask:ask.cancel"), onPress: () => { setCancel(true); }, textStyle: { color: 'red' } } ]} cancel={cancel} menuStyle={{ backgroundColor: 'white', borderRadius: 8, padding: 8, minWidth: 150, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 4, elevation: 5, }} > ))} { ((item.content.video_material_infos?.length || 0) + (item.content.image_material_infos?.length || 0)) > 3 && { setSelectedImages([]) setModalDetailsVisible({ visible: true, content: item.content }); }}> {((item.content.video_material_infos?.length || 0) + (item.content.image_material_infos?.length || 0))} } )} { item.content.text == "正在寻找,请稍等..." && {t("ask:ask.think")} } {/* {item.askAgain && item.askAgain.length > 0 && ( {item.askAgain.map((suggestion, index, array) => ( {suggestion.text} ))} )} */} {/* 单个图片弹窗 */} {/* 全部图片详情弹窗 */} ); }; export default MessageItem; const styles = StyleSheet.create({ imageGridContainer: { flexDirection: 'row', flexWrap: 'nowrap', width: '100%', marginTop: 8, }, video: { width: '100%', height: '100%', }, imageContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', width: '100%', maxHeight: '60%', }, fullWidthImage: { width: '100%', height: "54%", marginBottom: 8, }, gridImage: { aspectRatio: 1, marginBottom: 8, }, background: { ...StyleSheet.absoluteFillObject, backgroundColor: 'rgba(0, 0, 0, 0.5)', }, centeredView: { flex: 1, justifyContent: 'center', alignItems: 'center', }, modalView: { borderRadius: 20, alignItems: 'center', height: '100%', width: "100%", justifyContent: 'center', alignSelf: 'center', }, container: { flex: 1, backgroundColor: '#f5f5f5', }, userAvatar: { width: 30, height: 30, borderRadius: 15, }, messageList: { padding: 16, }, messageBubble: { paddingHorizontal: 16, paddingVertical: 12, fontWeight: "600" }, userBubble: { alignSelf: 'flex-end', backgroundColor: '#FFB645', marginLeft: '20%', }, aiBubble: { alignSelf: 'flex-start', backgroundColor: '#fff', marginRight: '20%', borderWidth: 1, borderColor: '#e5e5ea', }, userText: { color: '#4C320C', fontSize: 16, lineHeight: 24, }, aiText: { color: '#000', fontSize: 16, lineHeight: 24, }, });