import { ReactNode } from 'react'; import { NPool, NostrMetadata } from '@nostrify/nostrify'; import { EventTemplate } from 'nostr-tools/core'; import { default as Fuse } from 'fuse.js'; import { MessagingConfig, MessagingState, NewMessageSoundOption, NewMessageSoundPref, NotifyOptions, ConversationRelayInfo } from './types'; import { Signer, FileAttachment } from './lib/dmLib'; import { ProtocolMode, MessageProtocol, DMPhase } from './constants'; export type { FileAttachment } from './lib/dmLib'; interface SubscriptionStatus { isNIP4Connected: boolean; isNIP17Connected: boolean; } interface ScanProgress { current: number; status: string; } interface ScanProgressState { nip4: ScanProgress | null; nip17: ScanProgress | null; } interface SearchableMessage { message: Message; conversationId: string; senderPubkey: string; content: string; timestamp: number; } interface SearchableConversation { conversationId: string; participantPubkeys: string[]; participantNames: string[]; lastActivity: number; } export interface MessageSearchResult { message: Message; conversationId: string; score?: number; matches?: readonly Fuse.FuseResultMatch[]; } export interface ConversationSearchResult { conversationId: string; participantPubkeys: string[]; score?: number; matches?: readonly Fuse.FuseResultMatch[]; } interface MessagingContext { messagingState: MessagingState | null; isLoading: boolean; timing: Record; phase: DMPhase | null; messageSearchIndex: Fuse | null; conversationSearchIndex: Fuse | null; } export interface DMContextValue extends MessagingContext { sendMessage: (params: { recipientPubkey: string; content: string; protocol: MessageProtocol; attachments?: FileAttachment[]; subject?: string; }) => Promise; protocolMode: ProtocolMode; getConversationRelays: (conversationId: string) => ConversationRelayInfo[]; clearCacheAndRefetch: () => Promise; subscriptions: SubscriptionStatus; scanProgress: ScanProgressState; isDoingInitialLoad: boolean; reloadAfterSettingsChange: () => Promise; searchMessages: (query: string, conversationId?: string) => MessageSearchResult[]; searchConversations: (query: string) => ConversationSearchResult[]; markConversationAsRead: (conversationId: string) => void; /** Unread count for active (known) conversations only */ unreadActive: number; /** Unread count for request conversations only */ unreadRequests: number; /** Unread across active + requests */ unreadTotal: number; user: { pubkey: string; signer: Signer; } | null; onNotify: (options: NotifyOptions) => void; getDisplayName: (pubkey: string, metadata?: NostrMetadata) => string; getAuthor: (pubkey: string) => { data?: { metadata?: NostrMetadata; }; isLoading: boolean; }; getAuthorsBatch: (pubkeys: string[]) => { data: Map; }; uploadFile: (file: File) => Promise; isMobile: boolean; follows: string[]; appConfig: { discoveryRelays: string[]; relayMode: RelayMode; renderInlineMedia?: boolean; devMode?: boolean; appName?: string; appDescription?: string; }; /** When true, show shorts strip in conversation list (NIP-71). Requires nostr and publishEvent. */ showShorts?: boolean; /** When true, show search input in conversation list. Default true. */ showSearch?: boolean; /** When true, show the app name/description header in conversation list. Default true. */ showHeader?: boolean; /** Sound options for new message notification (from provider config). */ newMessageSoundOptions: NewMessageSoundOption[]; newMessageSoundPref: NewMessageSoundPref; setNewMessageSoundPref: (pref: NewMessageSoundPref) => void; previewNewMessageSound: (sound: NewMessageSoundOption) => void; nostr: NPool; publishEvent: (event: EventTemplate) => Promise; /** True when the browser reports network online. Package tracks this internally. */ isOnline: boolean; /** Whether messaging is currently enabled (from config). */ messagingEnabled: boolean; } export interface DMProviderDeps { nostr: NPool; user: { pubkey: string; signer: Signer; } | null; onNotify: (options: NotifyOptions) => void; getDisplayName: (pubkey: string, metadata?: NostrMetadata) => string; fetchAuthorsBatch: (pubkeys: string[]) => { data?: Map; }; publishEvent: (event: EventTemplate) => Promise; uploadFile: (file: File) => Promise; follows: string[]; onReconnected?: () => void; onHardRefresh?: () => Promise | void; messagingConfig: MessagingConfig; ui?: { showShorts?: boolean; showSearch?: boolean; showHeader?: boolean; isMobile?: boolean; }; } /** Single props type for DMProvider. No separate "deps" vs "config". */ export interface DMProviderProps extends DMProviderDeps { children: ReactNode; } export declare const DMProvider: (props: DMProviderProps) => import("react/jsx-runtime").JSX.Element; export declare const useDMContext: () => DMContextValue; export declare function useConversationMessages(conversationId: string): { loadEarlierMessages: () => void; messages: import('./types').Message[]; hasMoreMessages: boolean; totalCount: number; };