import "./DmWindow.css"; import { useMemo } from "react"; import ProfileImage from "Element/ProfileImage"; import DM from "Element/DM"; import NoteToSelf from "Element/NoteToSelf"; import useLogin from "Hooks/useLogin"; import WriteMessage from "Element/WriteMessage"; import { Chat, ChatParticipant, useChatSystem } from "chat"; import { Nip4ChatSystem } from "chat/nip4"; import { FormattedMessage } from "react-intl"; export default function DmWindow({ id }: { id: string }) { const pubKey = useLogin().publicKey; const dms = useChatSystem(); const chat = dms.find(a => a.id === id) ?? Nip4ChatSystem.createChatObj(id, []); function participant(p: ChatParticipant) { if (p.id === pubKey) { return ; } if (p.type === "pubkey") { return ; } if (p?.profile) { return ; } return ; } function sender() { if (chat.participants.length === 1) { return participant(chat.participants[0]); } else { return (
{chat.participants.map(v => ( ))} {chat.title ?? }
); } } return (
{sender()}
{chat && }
); } function DmChatSelected({ chat }: { chat: Chat }) { const { publicKey: myPubKey } = useLogin(); const sortedDms = useMemo(() => { const myDms = chat?.messages; if (myPubKey && myDms) { // filter dms in this chat, or dms to self return [...myDms].sort((a, b) => a.created_at - b.created_at); } return []; }, [chat, myPubKey]); return ( <> {sortedDms.map(a => ( ))} ); }