mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +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
@@ -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