/** @jsx h */ import { Fragment, h } from "https://esm.sh/preact@10.17.1"; import { tw } from "https://esm.sh/twind@0.16.16"; import { Avatar } from "./components/avatar.tsx"; import { CenterClass, IconButtonClass, LinearGradientsClass } from "./components/tw.ts"; import { sortUserInfo, UserInfo } from "./contact-list.ts"; import { emitFunc } from "../event-bus.ts"; import { PinIcon, UnpinIcon } from "./icons/mod.tsx"; import { SearchUpdate } from "./search_model.ts"; import { PublicKey } from "../lib/nostr-ts/key.ts"; import { PinContact, UnpinContact } from "../nostr.ts"; import { AddIcon } from "./icons2/add-icon.tsx"; import { PrimaryTextColor } from "./style/colors.ts"; export interface ConversationListRetriever { getContacts: () => Iterable; getStrangers: () => Iterable; } export type ConversationGroup = "Contacts" | "Strangers"; export type ContactUpdate = SelectConversationGroup | SearchUpdate | PinContact | UnpinContact; export type SelectConversationGroup = { type: "SelectConversationGroup"; group: ConversationGroup; }; type Props = { emit: emitFunc; convoListRetriever: ConversationListRetriever; currentSelected: PublicKey | undefined; selectedContactGroup: ConversationGroup; hasNewMessages: Set; }; export function ConversationList(props: Props) { const t = Date.now(); let contacts = Array.from(props.convoListRetriever.getContacts()); let strangers = Array.from(props.convoListRetriever.getStrangers()); const listToRender = props.selectedContactGroup == "Contacts" ? contacts : strangers; const contactsToRender = []; for (const contact of listToRender) { contactsToRender.push({ userInfo: contact, isMarked: props.hasNewMessages.has(contact.pubkey.hex), }); } return (
  • { props.emit({ type: "SelectConversationGroup", group: "Contacts", }); }} > Contacts: {contacts.length}
  • { props.emit({ type: "SelectConversationGroup", group: "Strangers", }); }} > Strangers: {strangers.length}
); } type ConversationListProps = { contacts: { userInfo: UserInfo; isMarked: boolean }[]; currentSelected: PublicKey | undefined; emit: emitFunc; }; function ContactGroup(props: ConversationListProps) { const t = Date.now(); props.contacts.sort((a, b) => { return sortUserInfo(a.userInfo, b.userInfo); }); const pinned = []; const unpinned = []; for (const contact of props.contacts) { if (contact.userInfo.pinEvent && contact.userInfo.pinEvent.content.type == "PinContact") { pinned.push(contact); } else { unpinned.push(contact); } } // console.log("ContactGroup", Date.now() - t); return (
    {pinned.map((contact) => { return (
  • { props.emit({ type: "SelectConversation", pubkey: contact.userInfo.pubkey, }); }} >
  • ); })} {unpinned.map((contact) => { return (
  • { props.emit({ type: "SelectConversation", pubkey: contact.userInfo.pubkey, }); }} >
  • ); })}
); } type ListItemProps = { userInfo: UserInfo; isMarked: boolean; }; function ConversationListItem(props: ListItemProps) { return (

{props.userInfo.profile?.profile.name || props.userInfo.pubkey.bech32()}

{props.userInfo.newestEventReceivedByMe !== undefined ? (

{new Date( props.userInfo.newestEventReceivedByMe .created_at * 1000, ).toLocaleString()}

) : undefined} {props.isMarked ? ( ) : undefined} {props.userInfo.pinEvent != undefined && props.userInfo.pinEvent.content.type == "PinContact" ? ( ) : undefined}
); }