import { useRosettaColors } from "@/app/hooks/useRosettaColors"; import { useImageViewer } from "@/app/providers/ImageViewerProvider/useImageViewer"; import { AspectRatio, Button, Flex, Paper, Text } from "@mantine/core"; import { IconArrowDown } from "@tabler/icons-react"; import { useEffect, useRef, useState } from "react"; import { AttachmentProps } from "./MessageAttachments"; import { blurhashToBase64Image } from "@/app/utils/utils"; import { AnimatedRoundedProgress } from "../AnimatedRoundedProgress/AnimatedRoundedProgress"; import { ImageToView } from "@/app/providers/ImageViewerProvider/ImageViewerProvider"; import { DownloadStatus, useAttachment } from "@/app/providers/AttachmentProvider/useAttachment"; import { PopoverLockIconAvatar } from "../PopoverLockIconAvatar/PopoverLockIconAvatar"; import { useRosettaBreakpoints } from "@/app/hooks/useRosettaBreakpoints"; export function MessageAvatar(props: AttachmentProps) { const colors = useRosettaColors(); const { downloadPercentage, //uploadedPercentage, download, downloadStatus, getBlob, getPreview} = useAttachment(props.attachment, props.chacha_key_plain); const mainRef = useRef(null); const { open } = useImageViewer(); const preview = getPreview(); const [blob, setBlob] = useState(props.attachment.blob); const {lg} = useRosettaBreakpoints(); useEffect(() => { constructBlob(); }, [downloadStatus]); const constructBlob = async () => { let blob = await getBlob(); setBlob(blob); } const openImageViewer = () => { const images: ImageToView[] = [{ src: blob, caption: props.text, timestamp: props.timestamp }]; open(images, 0); } const onClick = () => { if (downloadStatus == DownloadStatus.DOWNLOADED) { openImageViewer(); return; } if (downloadStatus == DownloadStatus.NOT_DOWNLOADED) { download(); return; } } return ( {blob != "" && ( )} {downloadStatus != DownloadStatus.DOWNLOADED && downloadStatus != DownloadStatus.PENDING && preview.length >= 20 && ( <> )} Avatar An avatar image shared in the message. {downloadStatus != DownloadStatus.DOWNLOADED && ( {lg && Avatars are end-to-end encrypted} {downloadStatus == DownloadStatus.NOT_DOWNLOADED && } {downloadStatus == DownloadStatus.DOWNLOADING && } )} ); }