diff --git a/src/components/NoteList/index.tsx b/src/components/NoteList/index.tsx index 71c369b..aeafe41 100644 --- a/src/components/NoteList/index.tsx +++ b/src/components/NoteList/index.tsx @@ -19,6 +19,8 @@ import PullToRefresh from 'react-simple-pull-to-refresh' import NoteCard, { NoteCardLoadingSkeleton } from '../NoteCard' import { PictureNoteCardMasonry } from '../PictureNoteCardMasonry' import Tabs from '../Tabs' +import { useUserTrust } from '@/providers/UserTrustProvider' +import { useFeed } from '@/providers/FeedProvider' const LIMIT = 100 const ALGO_LIMIT = 500 @@ -60,14 +62,17 @@ export default function NoteList({ const [filterType, setFilterType] = useState>('posts') const bottomRef = useRef(null) const topRef = useRef(null) + const { isUserTrusted, hideUntrustedNotes } = useUserTrust() + const { feedInfo } = useFeed() const filteredNewEvents = useMemo(() => { return newEvents.filter((event: Event) => { return ( (!filterMutedNotes || !mutePubkeys.includes(event.pubkey)) && - (listMode !== 'posts' || !isReplyNoteEvent(event)) + (listMode !== 'posts' || !isReplyNoteEvent(event)) && + (!hideUntrustedNotes || isUserTrusted(event.pubkey)) ) }) - }, [newEvents, listMode, filterMutedNotes, mutePubkeys]) + }, [newEvents, listMode, filterMutedNotes, mutePubkeys, hideUntrustedNotes]) useEffect(() => { switch (listMode) { @@ -341,7 +346,11 @@ export default function NoteList({
{events .slice(0, showCount) - .filter((event: Event) => listMode !== 'posts' || !isReplyNoteEvent(event)) + .filter((event: Event) => + (listMode !== 'posts' || !isReplyNoteEvent(event)) && + (author + || (feedInfo.feedType !== 'relay' && feedInfo.feedType !== 'relays') + || !hideUntrustedNotes || isUserTrusted(event.pubkey))) .map((event) => ( { const { t, i18n } = useTranslation() const [language, setLanguage] = useState(i18n.language as TLanguage) const { themeSetting, setThemeSetting } = useTheme() const { autoplay, setAutoplay } = useAutoplay() + const { hideUntrustedNotes, updateHideUntrustedNotes } = useUserTrust() const handleLanguageChange = (value: TLanguage) => { i18n.changeLanguage(value) @@ -63,6 +65,12 @@ const GeneralSettingsPage = forwardRef(({ index }: { index?: number }, ref) => { + + + +
) diff --git a/src/providers/UserTrustProvider.tsx b/src/providers/UserTrustProvider.tsx index 8b2a0d9..f9e4f1e 100644 --- a/src/providers/UserTrustProvider.tsx +++ b/src/providers/UserTrustProvider.tsx @@ -6,8 +6,10 @@ import { useNostr } from './NostrProvider' type TUserTrustContext = { hideUntrustedInteractions: boolean hideUntrustedNotifications: boolean + hideUntrustedNotes: boolean updateHideUntrustedInteractions: (hide: boolean) => void updateHideUntrustedNotifications: (hide: boolean) => void + updateHideUntrustedNotes: (hide: boolean) => void isUserTrusted: (pubkey: string) => boolean } @@ -31,6 +33,9 @@ export function UserTrustProvider({ children }: { children: React.ReactNode }) { const [hideUntrustedNotifications, setHideUntrustedNotifications] = useState(() => storage.getHideUntrustedNotifications() ) + const [hideUntrustedNotes, setHideUntrustedNotes] = useState(() => + storage.getHideUntrustedNotes ? storage.getHideUntrustedNotes() : false + ) useEffect(() => { if (!currentPubkey) return @@ -66,13 +71,22 @@ export function UserTrustProvider({ children }: { children: React.ReactNode }) { storage.setHideUntrustedNotifications(hide) } + const updateHideUntrustedNotes = (hide: boolean) => { + setHideUntrustedNotes(hide) + if (storage.setHideUntrustedNotes) { + storage.setHideUntrustedNotes(hide) + } + } + return ( diff --git a/src/services/local-storage.service.ts b/src/services/local-storage.service.ts index f5154e0..c28942c 100644 --- a/src/services/local-storage.service.ts +++ b/src/services/local-storage.service.ts @@ -28,6 +28,7 @@ class LocalStorageService { private autoplay: boolean = true private hideUntrustedInteractions: boolean = false private hideUntrustedNotifications: boolean = false + private hideUntrustedNotes: boolean = false private translationServiceConfigMap: Record = {} constructor() { @@ -95,8 +96,9 @@ class LocalStorageService { window.localStorage.getItem(StorageKey.MEDIA_UPLOAD_SERVICE) ?? DEFAULT_NIP_96_SERVICE this.autoplay = window.localStorage.getItem(StorageKey.AUTOPLAY) !== 'false' + this.hideUntrustedNotes = window.localStorage.getItem(StorageKey.HIDE_UNTRUSTED_NOTES) === 'true' - const hideUntrustedEvents = + const hideUntrustedNotes = window.localStorage.getItem(StorageKey.HIDE_UNTRUSTED_EVENTS) === 'true' const storedHideUntrustedInteractions = window.localStorage.getItem( StorageKey.HIDE_UNTRUSTED_INTERACTIONS @@ -106,10 +108,11 @@ class LocalStorageService { ) this.hideUntrustedInteractions = storedHideUntrustedInteractions ? storedHideUntrustedInteractions === 'true' - : hideUntrustedEvents + : hideUntrustedNotes this.hideUntrustedNotifications = storedHideUntrustedNotifications ? storedHideUntrustedNotifications === 'true' - : hideUntrustedEvents + : hideUntrustedNotes + this.hideUntrustedNotes = hideUntrustedNotes const translationServiceConfigMapStr = window.localStorage.getItem( StorageKey.TRANSLATION_SERVICE_CONFIG_MAP @@ -301,6 +304,18 @@ class LocalStorageService { ) } + getHideUntrustedNotes() { + return this.hideUntrustedNotes + } + + setHideUntrustedNotes(hideUntrustedNotes: boolean) { + this.hideUntrustedNotes = hideUntrustedNotes + window.localStorage.setItem( + StorageKey.HIDE_UNTRUSTED_NOTES, + hideUntrustedNotes.toString() + ) + } + getTranslationServiceConfig(pubkey?: string | null) { return this.translationServiceConfigMap[pubkey ?? '_'] ?? { service: 'jumble' } }