WoT implemented, plus other fixes #160

Merged
freakoverse merged 36 commits from staging into master 2024-11-20 16:39:08 +00:00
4 changed files with 27 additions and 10 deletions
Showing only changes of commit 54ab35e78c - Show all commits

View File

@ -110,7 +110,7 @@ export const ModFilter = React.memo(
data-bs-toggle='dropdown' data-bs-toggle='dropdown'
type='button' type='button'
> >
{filterOptions.wot} Trust: {filterOptions.wot}
</button> </button>
<div className='dropdown-menu dropdownMainMenu'> <div className='dropdown-menu dropdownMainMenu'>
{Object.values(WOTFilterOptions).map((item, index) => { {Object.values(WOTFilterOptions).map((item, index) => {

View File

@ -54,18 +54,29 @@ export const useFilteredMods = (
} }
const wotFilter = (mods: ModDetails[]) => { 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) { switch (filterOptions.wot) {
case WOTFilterOptions.None: 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: case WOTFilterOptions.Site_Only:
return mods.filter((mod) => return mods.filter((mod) =>
isInWoT(siteWot, siteWotLevel, mod.author) isInWoT(siteWot, siteWotLevel, mod.author)
) )
case WOTFilterOptions.Mine_Only: case WOTFilterOptions.Mine_Only:
return mods.filter((mod) => // Only admins can choose Mine_Only, use siteWoT for others
isInWoT(userWot, userWotLevel, mod.author) return isWoTNpub
) ? mods.filter((mod) => isInWoT(userWot, userWotLevel, mod.author))
: mods.filter((mod) => isInWoT(siteWot, siteWotLevel, mod.author))
case WOTFilterOptions.Site_And_Mine: case WOTFilterOptions.Site_And_Mine:
return mods.filter( return mods.filter(
(mod) => (mod) =>
@ -112,6 +123,7 @@ export const useFilteredMods = (
return filtered return filtered
}, [ }, [
userState.auth,
userState.user?.npub, userState.user?.npub,
filterOptions.sort, filterOptions.sort,
filterOptions.moderated, filterOptions.moderated,

View File

@ -4,9 +4,9 @@ import { useAppDispatch, useAppSelector, useNDKContext } from 'hooks'
import { kinds, UnsignedEvent, Event } from 'nostr-tools' import { kinds, UnsignedEvent, Event } from 'nostr-tools'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { setUserWotLevel } from 'store/reducers/wot' import { setSiteWotLevel, setUserWotLevel } from 'store/reducers/wot'
import { UserRelaysType } from 'types' import { UserRelaysType } from 'types'
import { log, LogType, now } from 'utils' import { log, LogType, now, npubToHex } from 'utils'
// todo: use components from Input.tsx // todo: use components from Input.tsx
export const PreferencesSetting = () => { export const PreferencesSetting = () => {
@ -92,6 +92,13 @@ export const PreferencesSetting = () => {
) )
dispatch(setUserWotLevel(wotLevel)) 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) => { .catch((err) => {
console.error(err) console.error(err)

View File

@ -98,9 +98,7 @@ export const findFollowsAndMuteUsers = async (
follows.add(f) follows.add(f)
}) })
} }
})
events.forEach((event) => {
if (event.kind === NDKKind.MuteList) { if (event.kind === NDKKind.MuteList) {
filterValidPTags(event.tags).forEach((f) => { filterValidPTags(event.tags).forEach((f) => {
muted.add(f) muted.add(f)