mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
use a config object for DM provider
This commit is contained in:
1 parent
92eb50f8d2
commit
ed80d74824
2 files changed
+17
-12
No files matched your search
+3
-3
@@ -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() {
|
||||
<NostrLoginProvider storageKey='nostr:login'>
|
||||
<NostrProvider>
|
||||
<NWCProvider>
|
||||
<DMProvider enabled={dmSettings.enabled} protocolMode={dmSettings.protocolMode}>
|
||||
<DMProvider config={dmConfig}>
|
||||
<TooltipProvider>
|
||||
<Toaster />
|
||||
<Suspense>
|
||||
|
||||
@@ -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<string>(config.relayUrl);
|
||||
const previousRelayUrl = useRef<string>(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(() => {
|
||||
|
||||
Reference in new issue
Block a user