import { ChatSidebar } from "../components/sidebar"; import { ChatMessageList } from "@app/chat/components/messageList"; import { ChatMessageForm } from "@app/chat/components/messages/form"; import { RelayContext } from "@shared/relayProvider"; import { useActiveAccount } from "@stores/accounts"; import { useChatMessages } from "@stores/chats"; import { READONLY_RELAYS } from "@stores/constants"; import { dateToUnix } from "@utils/date"; import { usePageContext } from "@utils/hooks/usePageContext"; import { useContext, useEffect } from "react"; import useSWRSubscription from "swr/subscription"; export function Page() { const pool: any = useContext(RelayContext); const account = useActiveAccount((state: any) => state.account); const pageContext = usePageContext(); const searchParams: any = pageContext.urlParsed.search; const pubkey = searchParams.pubkey; const [fetchMessages, addMessage, clear] = useChatMessages((state: any) => [ state.fetch, state.add, state.clear, ]); useSWRSubscription(account ? ["chat", pubkey] : null, ([, key]) => { const unsubscribe = pool.subscribe( [ { kinds: [4], authors: [key], "#p": [account.pubkey], since: dateToUnix(), }, ], READONLY_RELAYS, (event: any) => { addMessage({ receiver_pubkey: account.pubkey, sender_pubkey: event.pubkey, content: event.content, tags: event.tags, created_at: event.created_at, }); }, ); return () => { unsubscribe(); }; }); useEffect(() => { fetchMessages(account.pubkey, pubkey); return () => { clear(); }; }, [pubkey]); return (

Encrypted Chat

); }