feat: hide notifications from untrusted users
This commit is contained in:
@@ -5,6 +5,7 @@ import { SubCloser } from 'nostr-tools/abstract-pool'
|
||||
import { createContext, useContext, useEffect, useRef, useState } from 'react'
|
||||
import { useMuteList } from './MuteListProvider'
|
||||
import { useNostr } from './NostrProvider'
|
||||
import { useUserTrust } from './UserTrustProvider'
|
||||
|
||||
type TNotificationContext = {
|
||||
hasNewNotification: boolean
|
||||
@@ -24,6 +25,7 @@ export const useNotification = () => {
|
||||
|
||||
export function NotificationProvider({ children }: { children: React.ReactNode }) {
|
||||
const { pubkey, notificationsSeenAt, updateNotificationsSeenAt } = useNostr()
|
||||
const { isUserTrusted } = useUserTrust()
|
||||
const { mutePubkeys } = useMuteList()
|
||||
const [newNotificationIds, setNewNotificationIds] = useState(new Set<string>())
|
||||
const subCloserRef = useRef<SubCloser | null>(null)
|
||||
@@ -61,7 +63,11 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
|
||||
{
|
||||
onevent: (evt) => {
|
||||
// Only show notification if not from self and not muted
|
||||
if (evt.pubkey !== pubkey && !mutePubkeys.includes(evt.pubkey)) {
|
||||
if (
|
||||
evt.pubkey !== pubkey &&
|
||||
!mutePubkeys.includes(evt.pubkey) &&
|
||||
isUserTrusted(evt.pubkey)
|
||||
) {
|
||||
setNewNotificationIds((prev) => new Set([...prev, evt.id]))
|
||||
}
|
||||
},
|
||||
|
||||
@@ -23,7 +23,7 @@ const wotSet = new Set<string>()
|
||||
|
||||
export function UserTrustProvider({ children }: { children: React.ReactNode }) {
|
||||
const { pubkey: currentPubkey } = useNostr()
|
||||
const [enabled, setEnabled] = useState(storage.getHideUntrustedReplies())
|
||||
const [enabled, setEnabled] = useState(storage.getHideUntrustedEvents())
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentPubkey) return
|
||||
@@ -43,7 +43,7 @@ export function UserTrustProvider({ children }: { children: React.ReactNode }) {
|
||||
|
||||
const updateEnabled = (enabled: boolean) => {
|
||||
setEnabled(enabled)
|
||||
storage.setHideUntrustedReplies(enabled)
|
||||
storage.setHideUntrustedEvents(enabled)
|
||||
}
|
||||
|
||||
const isUserTrusted = (pubkey: string) => {
|
||||
|
||||
Reference in New Issue
Block a user