From 4b6926b0b90422699c113611a77bf1488b06e0a6 Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 19 Nov 2024 13:08:27 +0100 Subject: [PATCH 1/4] refactor(wot): single loop only --- src/utils/wot.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/utils/wot.ts b/src/utils/wot.ts index be3b481..fa8bcd0 100644 --- a/src/utils/wot.ts +++ b/src/utils/wot.ts @@ -98,9 +98,7 @@ export const findFollowsAndMuteUsers = async ( follows.add(f) }) } - }) - events.forEach((event) => { if (event.kind === NDKKind.MuteList) { filterValidPTags(event.tags).forEach((f) => { muted.add(f) From 2936d6d53b8fa5a275e2cb6876c132d5dbc84f27 Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 19 Nov 2024 13:09:12 +0100 Subject: [PATCH 2/4] refactor(wot): add Trust label to wot filter --- src/components/ModsFilter.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ModsFilter.tsx b/src/components/ModsFilter.tsx index 806fabe..6e0342d 100644 --- a/src/components/ModsFilter.tsx +++ b/src/components/ModsFilter.tsx @@ -110,7 +110,7 @@ export const ModFilter = React.memo( data-bs-toggle='dropdown' type='button' > - {filterOptions.wot} + Trust: {filterOptions.wot}
{Object.values(WOTFilterOptions).map((item, index) => { From 8b5b9a6e3059fefeda34bfd1a7d44b4d154c30c0 Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 19 Nov 2024 13:11:50 +0100 Subject: [PATCH 3/4] refactor(wot): ignore filter selection based on ruleset --- src/hooks/useFilteredMods.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/hooks/useFilteredMods.ts b/src/hooks/useFilteredMods.ts index 7c46c76..fd64adb 100644 --- a/src/hooks/useFilteredMods.ts +++ b/src/hooks/useFilteredMods.ts @@ -54,18 +54,29 @@ export const useFilteredMods = ( } const wotFilter = (mods: ModDetails[]) => { - // Determine the filtering logic based on the WOT filter option + // Determine the filtering logic based on the WOT filter option and user state + // when user is not logged in use Site_Only + if (!userState.auth) { + return mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author)) + } + // when user is logged, allow other filter selections + const isWoTNpub = + userState.user?.npub === import.meta.env.VITE_SITE_WOT_NPUB switch (filterOptions.wot) { case WOTFilterOptions.None: - return mods + // Only admins can choose None, use siteWoT for others + return isWoTNpub + ? mods + : mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author)) case WOTFilterOptions.Site_Only: return mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author) ) case WOTFilterOptions.Mine_Only: - return mods.filter((mod) => - isInWoT(userWot, userWotLevel, mod.author) - ) + // Only admins can choose Mine_Only, use siteWoT for others + return isWoTNpub + ? mods.filter((mod) => isInWoT(userWot, userWotLevel, mod.author)) + : mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author)) case WOTFilterOptions.Site_And_Mine: return mods.filter( (mod) => From 02a81213a21a1d7ee378458f5f3ff13eb6fb627c Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 19 Nov 2024 16:23:42 +0100 Subject: [PATCH 4/4] refactor(wot): update redux wot level if admin wot npub changes level --- src/hooks/useFilteredMods.ts | 1 + src/pages/settings/preference.tsx | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/hooks/useFilteredMods.ts b/src/hooks/useFilteredMods.ts index fd64adb..5530b0d 100644 --- a/src/hooks/useFilteredMods.ts +++ b/src/hooks/useFilteredMods.ts @@ -123,6 +123,7 @@ export const useFilteredMods = ( return filtered }, [ + userState.auth, userState.user?.npub, filterOptions.sort, filterOptions.moderated, diff --git a/src/pages/settings/preference.tsx b/src/pages/settings/preference.tsx index cb41186..69e3d12 100644 --- a/src/pages/settings/preference.tsx +++ b/src/pages/settings/preference.tsx @@ -4,9 +4,9 @@ import { useAppDispatch, useAppSelector, useNDKContext } from 'hooks' import { kinds, UnsignedEvent, Event } from 'nostr-tools' import { useEffect, useState } from 'react' import { toast } from 'react-toastify' -import { setUserWotLevel } from 'store/reducers/wot' +import { setSiteWotLevel, setUserWotLevel } from 'store/reducers/wot' import { UserRelaysType } from 'types' -import { log, LogType, now } from 'utils' +import { log, LogType, now, npubToHex } from 'utils' // todo: use components from Input.tsx export const PreferencesSetting = () => { @@ -92,6 +92,13 @@ export const PreferencesSetting = () => { ) dispatch(setUserWotLevel(wotLevel)) + + // If wot admin, update site wot level too + const SITE_WOT_NPUB = import.meta.env.VITE_SITE_WOT_NPUB + const siteWotPubkey = npubToHex(SITE_WOT_NPUB) + if (siteWotPubkey === hexPubkey) { + dispatch(setSiteWotLevel(wotLevel)) + } }) .catch((err) => { console.error(err)