/** @jsx h */ import { h } from "https://esm.sh/preact@10.17.1"; import { tw } from "https://esm.sh/twind@0.16.16"; import { DirectMessagePanelUpdate, MessagePanel } from "./message-panel.tsx"; import { Model } from "./app_model.ts"; import { NostrAccountContext } from "../lib/nostr-ts/nostr.ts"; import { Database_Contextual_View } from "../database.ts"; import { EventEmitter } from "../event-bus.ts"; import { AllUsersInformation, getUserInfoFromPublicKey } from "./contact-list.ts"; import { EventSyncer } from "./event_syncer.ts"; import { PrimaryTextColor } from "./style/colors.ts"; import { EditorEvent } from "./editor.tsx"; import { PinContact, UnpinContact } from "../nostr.ts"; import { CenterClass, LinearGradientsClass } from "./components/tw.ts"; import { ProfilesSyncer } from "../features/profile.ts"; export type SocialUpdates = | SocialFilterChanged_content | SocialFilterChanged_authors | SocialFilterChanged_adding_author | SocialFilterChanged_remove_author; type SocialFilterChanged_content = { type: "SocialFilterChanged_content"; content: string; }; type SocialFilterChanged_authors = { type: "SocialFilterChanged_authors"; }; type SocialFilterChanged_adding_author = { type: "SocialFilterChanged_adding_author"; value: string; }; type SocialFilterChanged_remove_author = { type: "SocialFilterChanged_remove_author"; value: string; }; export function SocialPanel(props: { focusedContent: any; model: Model; ctx: NostrAccountContext; db: Database_Contextual_View; eventEmitter: EventEmitter< SocialUpdates | EditorEvent | DirectMessagePanelUpdate | PinContact | UnpinContact >; profileSyncer: ProfilesSyncer; eventSyncer: EventSyncer; allUsersInfo: AllUsersInformation; }) { const t = Date.now(); const model = props.model; const messages = []; // todo: can move this logic to update to speed up for (const thread of model.social.threads) { // content if (!thread.root.content.toLowerCase().includes(model.social.filter.content.toLowerCase())) { continue; } // authors let matched_at_least_one_author = false; for (const author of model.social.filter.author) { const userInfo = getUserInfoFromPublicKey( thread.root.event.publicKey, props.allUsersInfo.userInfos, ); if (userInfo && userInfo.profile?.profile.name?.toLowerCase().includes(author.toLowerCase())) { matched_at_least_one_author = true; break; } } if (model.social.filter.author.size > 0 && !matched_at_least_one_author) { continue; } messages.push(thread); } console.log("SocialPanel:filter threads", Date.now() - t, model.social.threads.length); const messagePanel = ( ); console.log("SocialPanel:MessagePanel", Date.now() - t); return (
{Filter(props)}
{messagePanel}
); } function Filter( props: { eventEmitter: EventEmitter; model: Model; }, ) { const authors = []; for (const author of props.model.social.filter.author) { authors.push(

{author}

, ); } return (

Filter

Content

{ props.eventEmitter.emit({ type: "SocialFilterChanged_content", content: e.currentTarget.value, }); }} value={props.model.social.filter.content} >

Authors

{authors} { props.eventEmitter.emit({ type: "SocialFilterChanged_adding_author", value: e.currentTarget.value, }); }} value={props.model.social.filter.adding_author} >
); }