|
|
|
@ -11,7 +11,7 @@ import { useContentPolicy } from './ContentPolicyProvider' |
|
|
|
import { useMuteList } from './MuteListProvider' |
|
|
|
import { useMuteList } from './MuteListProvider' |
|
|
|
import { useNostr } from './NostrProvider' |
|
|
|
import { useNostr } from './NostrProvider' |
|
|
|
import { useUserTrust } from './UserTrustProvider' |
|
|
|
import { useUserTrust } from './UserTrustProvider' |
|
|
|
import { useInterestList } from './InterestListProvider' |
|
|
|
// import { useInterestList } from './InterestListProvider' // No longer needed
|
|
|
|
|
|
|
|
|
|
|
|
type TNotificationContext = { |
|
|
|
type TNotificationContext = { |
|
|
|
hasNewNotification: boolean |
|
|
|
hasNewNotification: boolean |
|
|
|
@ -37,7 +37,7 @@ export function NotificationProvider({ children }: { children: React.ReactNode } |
|
|
|
const { hideUntrustedNotifications, isUserTrusted } = useUserTrust() |
|
|
|
const { hideUntrustedNotifications, isUserTrusted } = useUserTrust() |
|
|
|
const { mutePubkeySet } = useMuteList() |
|
|
|
const { mutePubkeySet } = useMuteList() |
|
|
|
const { hideContentMentioningMutedUsers } = useContentPolicy() |
|
|
|
const { hideContentMentioningMutedUsers } = useContentPolicy() |
|
|
|
const { getSubscribedTopics } = useInterestList() |
|
|
|
// const { getSubscribedTopics } = useInterestList() // No longer needed since we subscribe to all discussions
|
|
|
|
const [newNotifications, setNewNotifications] = useState<NostrEvent[]>([]) |
|
|
|
const [newNotifications, setNewNotifications] = useState<NostrEvent[]>([]) |
|
|
|
const [readNotificationIdSet, setReadNotificationIdSet] = useState<Set<string>>(new Set()) |
|
|
|
const [readNotificationIdSet, setReadNotificationIdSet] = useState<Set<string>>(new Set()) |
|
|
|
const filteredNewNotifications = useMemo(() => { |
|
|
|
const filteredNewNotifications = useMemo(() => { |
|
|
|
@ -109,30 +109,36 @@ export function NotificationProvider({ children }: { children: React.ReactNode } |
|
|
|
const relayList = await client.fetchRelayList(pubkey) |
|
|
|
const relayList = await client.fetchRelayList(pubkey) |
|
|
|
const notificationRelays = relayList.read.length > 0 ? relayList.read.slice(0, 5) : BIG_RELAY_URLS |
|
|
|
const notificationRelays = relayList.read.length > 0 ? relayList.read.slice(0, 5) : BIG_RELAY_URLS |
|
|
|
|
|
|
|
|
|
|
|
// Subscribe to subscribed topics (kind 11 discussions)
|
|
|
|
// Subscribe to discussion notifications (kind 11)
|
|
|
|
const subscribedTopics = getSubscribedTopics() |
|
|
|
// Subscribe to all discussions, not just subscribed topics
|
|
|
|
if (subscribedTopics.length > 0) { |
|
|
|
let discussionEosed = false |
|
|
|
let topicEosed = false |
|
|
|
const discussionSubCloser = client.subscribe( |
|
|
|
const topicSubCloser = client.subscribe( |
|
|
|
|
|
|
|
notificationRelays, |
|
|
|
notificationRelays, |
|
|
|
[ |
|
|
|
[ |
|
|
|
{ |
|
|
|
{ |
|
|
|
kinds: [11], // Discussion threads
|
|
|
|
kinds: [11], // Discussion threads
|
|
|
|
'#t': subscribedTopics, |
|
|
|
limit: 20 |
|
|
|
limit: 10 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
], |
|
|
|
], |
|
|
|
{ |
|
|
|
{ |
|
|
|
oneose: (e) => { |
|
|
|
oneose: (e) => { |
|
|
|
if (e) { |
|
|
|
if (e) { |
|
|
|
topicEosed = e |
|
|
|
discussionEosed = e |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
onevent: (evt) => { |
|
|
|
onevent: (evt) => { |
|
|
|
// Don't notify about our own threads
|
|
|
|
// Don't notify about our own threads
|
|
|
|
if (evt.pubkey !== pubkey) { |
|
|
|
if (evt.pubkey !== pubkey) { |
|
|
|
|
|
|
|
console.log('📢 Discussion notification received:', { |
|
|
|
|
|
|
|
id: evt.id, |
|
|
|
|
|
|
|
pubkey: evt.pubkey, |
|
|
|
|
|
|
|
kind: evt.kind, |
|
|
|
|
|
|
|
content: evt.content.substring(0, 50) + '...', |
|
|
|
|
|
|
|
topics: evt.tags.filter(tag => tag[0] === 't').map(tag => tag[1]) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
setNewNotifications((prev) => { |
|
|
|
setNewNotifications((prev) => { |
|
|
|
if (!topicEosed) { |
|
|
|
if (!discussionEosed) { |
|
|
|
return [evt, ...prev] |
|
|
|
return [evt, ...prev] |
|
|
|
} |
|
|
|
} |
|
|
|
if (prev.length && compareEvents(prev[0], evt) >= 0) { |
|
|
|
if (prev.length && compareEvents(prev[0], evt) >= 0) { |
|
|
|
@ -146,8 +152,7 @@ export function NotificationProvider({ children }: { children: React.ReactNode } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
topicSubCloserRef.current = topicSubCloser |
|
|
|
topicSubCloserRef.current = discussionSubCloser |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Regular notifications subscription
|
|
|
|
// Regular notifications subscription
|
|
|
|
const subCloser = client.subscribe( |
|
|
|
const subCloser = client.subscribe( |
|
|
|
@ -180,7 +185,6 @@ export function NotificationProvider({ children }: { children: React.ReactNode } |
|
|
|
}, |
|
|
|
}, |
|
|
|
onevent: (evt) => { |
|
|
|
onevent: (evt) => { |
|
|
|
if (evt.pubkey !== pubkey) { |
|
|
|
if (evt.pubkey !== pubkey) { |
|
|
|
|
|
|
|
|
|
|
|
setNewNotifications((prev) => { |
|
|
|
setNewNotifications((prev) => { |
|
|
|
if (!eosed) { |
|
|
|
if (!eosed) { |
|
|
|
return [evt, ...prev] |
|
|
|
return [evt, ...prev] |
|
|
|
@ -243,7 +247,7 @@ export function NotificationProvider({ children }: { children: React.ReactNode } |
|
|
|
topicSubCloserRef.current = null |
|
|
|
topicSubCloserRef.current = null |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, [pubkey, getSubscribedTopics]) |
|
|
|
}, [pubkey]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const newNotificationCount = filteredNewNotifications.length |
|
|
|
const newNotificationCount = filteredNewNotifications.length |
|
|
|
|