diff --git a/src/App.tsx b/src/App.tsx index 07da0ea..88f0bf2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,7 +11,7 @@ import { TooltipProvider } from "@/components/ui/tooltip"; import { NostrLoginProvider } from '@nostrify/react/login'; import { AppProvider } from '@/components/AppProvider'; import { NWCProvider } from '@/contexts/NWCContext'; -import { DMProvider } from '@/contexts/DMContext'; +import { DMProvider, type DMConfig } from '@/contexts/DMContext'; import { AppConfig } from '@/contexts/AppContext'; import { PROTOCOL_MODE } from '@/lib/dmConstants'; import AppRouter from './AppRouter'; @@ -44,7 +44,7 @@ const presetRelays = [ { url: 'wss://relay.primal.net', name: 'Primal' }, ]; -const dmSettings = { +const dmConfig: DMConfig = { // Enable or disable DMs entirely enabled: true, // Set to false to completely disable messaging functionality @@ -63,7 +63,7 @@ export function App() { - + diff --git a/src/contexts/DMContext.tsx b/src/contexts/DMContext.tsx index c30e107..d613bff 100644 --- a/src/contexts/DMContext.tsx +++ b/src/contexts/DMContext.tsx @@ -185,22 +185,27 @@ export function useConversationMessages(conversationId: string) { }; } -interface DMProviderProps { - children: ReactNode; - protocolMode?: ProtocolMode; +export interface DMConfig { enabled?: boolean; + protocolMode?: ProtocolMode; } -export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY, enabled = true }: DMProviderProps) { +interface DMProviderProps { + children: ReactNode; + config?: DMConfig; +} + +export function DMProvider({ children, config }: DMProviderProps) { + const { enabled = true, protocolMode = PROTOCOL_MODE.NIP17_ONLY } = config || {}; const { user } = useCurrentUser(); const { nostr } = useNostr(); const { sendNIP4Message, sendNIP17Message } = useSendDM(); - const { config } = useAppContext(); + const { config: appConfig } = useAppContext(); const userPubkey = useMemo(() => user?.pubkey, [user?.pubkey]); // Track relay URL to detect changes - const previousRelayUrl = useRef(config.relayUrl); + const previousRelayUrl = useRef(appConfig.relayUrl); // Determine if NIP-17 is enabled based on protocol mode const enableNIP17 = protocolMode !== PROTOCOL_MODE.NIP04_ONLY; @@ -1070,13 +1075,13 @@ export function DMProvider({ children, protocolMode = PROTOCOL_MODE.NIP17_ONLY, // Detect relay changes and reload messages useEffect(() => { - const relayChanged = previousRelayUrl.current !== config.relayUrl; - previousRelayUrl.current = config.relayUrl; + const relayChanged = previousRelayUrl.current !== appConfig.relayUrl; + previousRelayUrl.current = appConfig.relayUrl; if (relayChanged && enabled && userPubkey && hasInitialLoadCompleted) { clearCacheAndReload(); } - }, [enabled, userPubkey, config.relayUrl, hasInitialLoadCompleted, clearCacheAndReload]); + }, [enabled, userPubkey, appConfig.relayUrl, hasInitialLoadCompleted, clearCacheAndReload]); // Conversations summary const conversations = useMemo(() => {