diff --git a/packages/app/src/Element/DM.tsx b/packages/app/src/Element/DM.tsx index 0c1b5ea0..cc0b9c3f 100644 --- a/packages/app/src/Element/DM.tsx +++ b/packages/app/src/Element/DM.tsx @@ -1,6 +1,6 @@ import "./DM.css"; import { useEffect, useState } from "react"; -import { useIntl } from "react-intl"; +import { FormattedMessage, useIntl } from "react-intl"; import { useInView } from "react-intersection-observer"; import useEventPublisher from "Feed/EventPublisher"; @@ -8,9 +8,9 @@ import NoteTime from "Element/NoteTime"; import Text from "Element/Text"; import useLogin from "Hooks/useLogin"; import { Chat, ChatMessage, ChatType, setLastReadIn } from "chat"; +import ProfileImage from "./ProfileImage"; import messages from "./messages"; -import ProfileImage from "./ProfileImage"; export interface DMProps { chat: Chat; @@ -21,9 +21,8 @@ export default function DM(props: DMProps) { const pubKey = useLogin().publicKey; const publisher = useEventPublisher(); const msg = props.data; - const [content, setContent] = useState(msg.needsDecryption ? "Loading..." : msg.content); - const [decrypted, setDecrypted] = useState(false); - const { ref, inView } = useInView(); + const [content, setContent] = useState(); + const { ref, inView } = useInView({ triggerOnce: true }); const { formatMessage } = useIntl(); const isMe = msg.from === pubKey; const otherPubkey = isMe ? pubKey : msg.from; @@ -46,17 +45,20 @@ export default function DM(props: DMProps) { } useEffect(() => { - if (!decrypted && inView && msg.needsDecryption) { - setDecrypted(true); - decrypt().catch(console.error); + if (inView) { + if (msg.needsDecryption) { + decrypt().catch(console.error); + } else { + setContent(msg.content); + } } - }, [inView, msg]); + }, [inView]); return (
{sender()} - + {content ? : }