parent
e77b9928d0
commit
3ffcd1b2c5
@ -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<string>();
|
||||
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 (
|
||||
<div className={isMe ? "dm me" : "dm other"} ref={ref}>
|
||||
<div>
|
||||
{sender()}
|
||||
<Text id={msg.id} content={content} tags={[]} creator={otherPubkey} />
|
||||
{content ? <Text id={msg.id} content={content} tags={[]} creator={otherPubkey} /> : <FormattedMessage defaultMessage="Loading..." />}
|
||||
</div>
|
||||
<div>
|
||||
<NoteTime from={msg.created_at * 1000} fallback={formatMessage(messages.JustNow)} />
|
||||
|
Loading…
x
Reference in New Issue
Block a user