import type { Component } from "solid-js"; import { Show, createMemo } from "solid-js"; import { AtSign } from "lucide-solid"; import { activeDMConversation, dmMessages, dmTypingPeers, } from "../../stores/dms"; import { onlinePeerIds } from "../../stores/members"; import MessageList from "../chat/MessageList"; import MessageInput from "../chat/MessageInput"; import TypingIndicator from "../chat/TypingIndicator"; import Avatar from "../common/Avatar"; import type { ChatMessage } from "../../lib/types"; interface DMChatAreaProps { onSendDM: (content: string) => void; onTyping: () => void; } const DMChatArea: Component = (props) => { const dm = () => activeDMConversation(); // adapt DirectMessage[] to ChatMessage[] so the existing MessageList works const adaptedMessages = createMemo((): ChatMessage[] => dmMessages().map((m) => ({ id: m.id, channel_id: `dm_${m.from_peer === dm()?.peer_id ? m.from_peer : m.to_peer}`, author_id: m.from_peer, author_name: m.from_display_name, content: m.content, timestamp: m.timestamp, edited: false, })), ); // derive peer online status from the members store or directory const peerStatus = createMemo(() => { const peerId = dm()?.peer_id; if (!peerId) return "offline"; if (onlinePeerIds().has(peerId)) return "online"; return "offline"; }); // typing indicator names const typingNames = createMemo(() => { const typing = dmTypingPeers(); if (typing.length === 0) return []; const peer = dm(); if (!peer) return []; // for dms there's only ever one person who can be typing return typing.includes(peer.peer_id) ? [peer.display_name] : []; }); return (
{/* dm header */}
{dm()!.display_name} {peerStatus()}
{/* conversation history */} 0} fallback={

{dm()!.display_name}

this is the beginning of your conversation with{" "} {dm()!.display_name}

} >
{/* typing indicator */} 0}> {/* message input */}
); }; export default DMChatArea;