import { Component, h } from "https://esm.sh/preact@10.17.1"; import { SingleRelayConnection } from "../../libs/nostr.ts/relay-single.ts"; import { emitFunc, EventBus } from "../event-bus.ts"; import { UI_Interaction_Event } from "./app_update.tsx"; import { setState } from "./_helper.ts"; import { ProfileGetter } from "./search.tsx"; import { RelayRecordGetter } from "../database.ts"; import { NewMessageChecker } from "./conversation-list.tsx"; import { ConversationListRetriever } from "./conversation-list.tsx"; import { NostrAccountContext } from "../../libs/nostr.ts/nostr.ts"; import { MessagePanel } from "./message-panel.tsx"; import { PublicKey } from "../../libs/nostr.ts/key.ts"; import { ChatMessage } from "./message.ts"; import { func_GetEventByID } from "./message-list.tsx"; import { Filter, FilterContent } from "./filter.tsx"; import { NoteID } from "../../libs/nostr.ts/nip19.ts"; export type Public_Model = { relaySelectedChannel: Map; }; export type func_IsUserBlocked = (pubkey: PublicKey) => boolean; type Props = { ctx: NostrAccountContext; relay: SingleRelayConnection; bus: EventBus; messages: ChatMessage[]; getters: { profileGetter: ProfileGetter; convoListRetriever: ConversationListRetriever; newMessageChecker: NewMessageChecker; relayRecordGetter: RelayRecordGetter; isUserBlocked: func_IsUserBlocked; getEventByID: func_GetEventByID; }; } & Public_Model; type State = { currentSelectedChannel: string /*channel name*/ | undefined; currentEditor: { text: string; }; filter: FilterContent | undefined; }; export class PublicMessageContainer extends Component { state: State = { currentSelectedChannel: "general", currentEditor: { text: "", }, filter: undefined, }; async componentDidMount() { for await (const e of this.props.bus.onChange()) { if (e.type == "FilterContent") { await setState(this, { filter: e, }); } } } render(props: Props, state: State) { let msgs = props.messages; const filter = this.state.filter; if (filter) { msgs = filter_messages(this.props.messages, filter); } return (
{this.state.currentSelectedChannel ? (
{ }
) : undefined}
); } } function TopBar(props: { currentSelected: string | undefined; emit: emitFunc; }) { return (
{props.currentSelected}
); } function filter_messages(msgs: ChatMessage[], filter: FilterContent) { const filter_string = filter.content.trim().toLocaleLowerCase(); const pubkey = PublicKey.FromBech32(filter_string); const is_pubkey = pubkey instanceof PublicKey; const noteID = NoteID.FromBech32(filter_string); const is_note = noteID instanceof NoteID; msgs = msgs.filter((msg) => { if (is_pubkey) { if (msg.author.hex == pubkey.hex) { return true; } } if (is_note) { if (msg.event.id == noteID.hex) { return true; } } if (msg.content.toLocaleLowerCase().indexOf(filter_string) != -1) { return true; } return false; }); return msgs; }