feat: hide untrusted content button

This commit is contained in:
codytseng
2025-06-09 01:08:50 +08:00
parent 5913cc3b88
commit 963051e70d
12 changed files with 177 additions and 57 deletions

View File

@@ -25,7 +25,7 @@ export const useNotification = () => {
export function NotificationProvider({ children }: { children: React.ReactNode }) {
const { pubkey, notificationsSeenAt, updateNotificationsSeenAt } = useNostr()
const { isUserTrusted } = useUserTrust()
const { hideUntrustedNotifications, isUserTrusted } = useUserTrust()
const { mutePubkeys } = useMuteList()
const [newNotificationIds, setNewNotificationIds] = useState(new Set<string>())
const subCloserRef = useRef<SubCloser | null>(null)
@@ -66,7 +66,7 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
if (
evt.pubkey !== pubkey &&
!mutePubkeys.includes(evt.pubkey) &&
isUserTrusted(evt.pubkey)
(!hideUntrustedNotifications || isUserTrusted(evt.pubkey))
) {
setNewNotificationIds((prev) => new Set([...prev, evt.id]))
}

View File

@@ -1,11 +1,13 @@
import client from '@/services/client.service'
import storage from '@/services/local-storage.service'
import { createContext, useCallback, useContext, useEffect, useState } from 'react'
import { useNostr } from './NostrProvider'
import storage from '@/services/local-storage.service'
type TUserTrustContext = {
enabled: boolean
updateEnabled: (enabled: boolean) => void
hideUntrustedInteractions: boolean
hideUntrustedNotifications: boolean
updateHideUntrustedInteractions: (hide: boolean) => void
updateHideUntrustedNotifications: (hide: boolean) => void
isUserTrusted: (pubkey: string) => boolean
}
@@ -23,7 +25,12 @@ const wotSet = new Set<string>()
export function UserTrustProvider({ children }: { children: React.ReactNode }) {
const { pubkey: currentPubkey } = useNostr()
const [enabled, setEnabled] = useState(storage.getHideUntrustedEvents())
const [hideUntrustedInteractions, setHideUntrustedInteractions] = useState(() =>
storage.getHideUntrustedInteractions()
)
const [hideUntrustedNotifications, setHideUntrustedNotifications] = useState(() =>
storage.getHideUntrustedNotifications()
)
useEffect(() => {
if (!currentPubkey) return
@@ -43,19 +50,32 @@ export function UserTrustProvider({ children }: { children: React.ReactNode }) {
const isUserTrusted = useCallback(
(pubkey: string) => {
if (!currentPubkey || !enabled) return true
if (!currentPubkey) return true
return wotSet.has(pubkey)
},
[currentPubkey, enabled]
[currentPubkey]
)
const updateEnabled = (enabled: boolean) => {
setEnabled(enabled)
storage.setHideUntrustedEvents(enabled)
const updateHideUntrustedInteractions = (hide: boolean) => {
setHideUntrustedInteractions(hide)
storage.setHideUntrustedInteractions(hide)
}
const updateHideUntrustedNotifications = (hide: boolean) => {
setHideUntrustedNotifications(hide)
storage.setHideUntrustedNotifications(hide)
}
return (
<UserTrustContext.Provider value={{ enabled, updateEnabled, isUserTrusted }}>
<UserTrustContext.Provider
value={{
hideUntrustedInteractions,
hideUntrustedNotifications,
updateHideUntrustedInteractions,
updateHideUntrustedNotifications,
isUserTrusted
}}
>
{children}
</UserTrustContext.Provider>
)