import { Avatar, Box, Flex, HStack, Text } from "@chakra-ui/react"; import { MessageType } from "@strata-foundation/chat"; import { truncatePubkey } from "@strata-foundation/react"; import React, { useMemo } from "react"; import { useAsync } from "react-async-hook"; import { IMessageWithPending } from "../../hooks/useMessages"; import { useUsernameFromIdentifierCertificate } from "../../hooks/useUsernameFromIdentifierCertificate"; import { useWalletProfile } from "../../hooks/useWalletProfile"; const STYLE = { color: "gray.500", _hover: { cursor: "pointer", color: "black", _dark: { color: "white", }, }, }; const BEFORE_STYLE = { content: `""`, position: "absolute", left: "50%", top: "8px", width: "2px", height: "12px", bg: "gray.300", }; const AFTER_STYLE = { content: `""`, position: "absolute", left: "50%", top: "8px", width: "20px", height: "2px", bg: "gray.300", }; export function DisplayReply({ reply, scrollToMessage, }: { reply: IMessageWithPending; scrollToMessage: (id: string) => void; }) { const { result: decodedMessage } = useAsync(reply.getDecodedMessage, []); const { info: profile } = useWalletProfile(reply.sender); const { username, loading: loadingUsername } = useUsernameFromIdentifierCertificate( profile?.identifierCertificateMint, reply.sender ); const name = useMemo( () => username || (reply.sender && truncatePubkey(reply.sender)), [username, reply?.sender?.toBase58()] ); return ( scrollToMessage(reply.id)} {...STYLE} > {name} {decodedMessage ? ( // successfully decoded <> {reply.type === MessageType.Text ? ( {decodedMessage.text} ) : reply.type === MessageType.Html ? ( {decodedMessage.html?.replace(/<[^>]*>?/gm, "")} ) : ( Click to see attachment )} ) : ( // need to fetch more messages Click to find reply )} ); }