You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
1009 B

import { type TRepliesMap } from '@/lib/reply-index'
import { useReplyOptional } from '@/providers/ReplyProvider'
import { useThreadReplyOptional } from '@/providers/ThreadReplyProvider'
import type { Event } from 'nostr-tools'
const noopAddReplies = (_replies: Event[]) => {}
const EMPTY_REPLIES_MAP: TRepliesMap = new Map()
const REPLY_INGRESS_FALLBACK = {
repliesMap: EMPTY_REPLIES_MAP,
addReplies: noopAddReplies,
scoped: false as const
}
/**
* Reply map ingress for the open note panel: prefers per-thread storage when
* {@link ThreadReplyProvider} wraps the note page (avoids cross-thread pollution).
*/
export function useReplyIngress() {
const thread = useThreadReplyOptional()
if (thread) {
return { repliesMap: thread.repliesMap, addReplies: thread.addReplies, scoped: true as const }
}
const global = useReplyOptional()
if (global) {
return { repliesMap: global.repliesMap, addReplies: global.addReplies, scoped: false as const }
}
return REPLY_INGRESS_FALLBACK
}