feat(filter): add only moderation filter to mods

Closes #188
This commit is contained in:
enes 2025-01-21 11:54:00 +01:00
parent 09dda039da
commit e5dd28c23c
7 changed files with 52 additions and 19 deletions

View File

@ -48,10 +48,14 @@ export const ModFilter = React.memo(
{/* moderation filter options */} {/* moderation filter options */}
<Dropdown label={filterOptions.moderated}> <Dropdown label={filterOptions.moderated}>
{Object.values(ModeratedFilter).map((item, index) => { {Object.values(ModeratedFilter).map((item, index) => {
if (item === ModeratedFilter.Unmoderated_Fully) { const isAdmin =
const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
if (item === ModeratedFilter.Only_Blocked && !isAdmin) {
return null
}
if (item === ModeratedFilter.Unmoderated_Fully) {
const isOwnProfile = const isOwnProfile =
author && userState.auth && userState.user?.pubkey === author author && userState.auth && userState.user?.pubkey === author

View File

@ -128,10 +128,19 @@ export const useFilteredMods = (
npubToHex(userState.user.npub as string) === author npubToHex(userState.user.npub as string) === author
const isUnmoderatedFully = const isUnmoderatedFully =
filterOptions.moderated === ModeratedFilter.Unmoderated_Fully filterOptions.moderated === ModeratedFilter.Unmoderated_Fully
const isOnlyBlocked =
filterOptions.moderated === ModeratedFilter.Only_Blocked
// Only apply filtering if the user is not an admin or the admin has not selected "Unmoderated Fully" if (isOnlyBlocked && isAdmin) {
// Allow "Unmoderated Fully" when author visits own profile filtered = filtered.filter(
if (!((isAdmin || isOwner) && isUnmoderatedFully)) { (mod) =>
muteLists.admin.authors.includes(mod.author) ||
muteLists.admin.replaceableEvents.includes(mod.aTag)
)
} else if (isUnmoderatedFully && (isAdmin || isOwner)) {
// Only apply filtering if the user is not an admin or the admin has not selected "Unmoderated Fully"
// Allow "Unmoderated Fully" when author visits own profile
} else {
filtered = filtered.filter( filtered = filtered.filter(
(mod) => (mod) =>
!muteLists.admin.authors.includes(mod.author) && !muteLists.admin.authors.includes(mod.author) &&

View File

@ -119,7 +119,7 @@ export const blogRouteLoader =
throw new Error('We are unable to find the blog on the relays') throw new Error('We are unable to find the blog on the relays')
} }
// Check the lateast blog events // Check the latest blog events
const fetchEventsResult = settled[1] const fetchEventsResult = settled[1]
if (fetchEventsResult.status === 'fulfilled' && fetchEventsResult.value) { if (fetchEventsResult.status === 'fulfilled' && fetchEventsResult.value) {
// Extract the blog card details from the events // Extract the blog card details from the events

View File

@ -129,7 +129,7 @@ export const modRouteLoader =
throw new Error('We are unable to find the mod on the relays') throw new Error('We are unable to find the mod on the relays')
} }
// Check the lateast blog events // Check the latest blog events
const fetchEventsResult = settled[1] const fetchEventsResult = settled[1]
if (fetchEventsResult.status === 'fulfilled' && fetchEventsResult.value) { if (fetchEventsResult.status === 'fulfilled' && fetchEventsResult.value) {
// Extract the blog card details from the events // Extract the blog card details from the events

View File

@ -767,6 +767,8 @@ const ProfileTabBlogs = () => {
userState.user?.pubkey && userState.user.pubkey === profilePubkey userState.user?.pubkey && userState.user.pubkey === profilePubkey
const isUnmoderatedFully = const isUnmoderatedFully =
filterOptions.moderated === ModeratedFilter.Unmoderated_Fully filterOptions.moderated === ModeratedFilter.Unmoderated_Fully
const isOnlyBlocked =
filterOptions.moderated === ModeratedFilter.Only_Blocked
// Add nsfw tag to blogs included in nsfwList // Add nsfw tag to blogs included in nsfwList
if (filterOptions.nsfw !== NSFWFilter.Hide_NSFW) { if (filterOptions.nsfw !== NSFWFilter.Hide_NSFW) {
@ -782,9 +784,16 @@ const ProfileTabBlogs = () => {
(b) => !(b.nsfw && filterOptions.nsfw === NSFWFilter.Hide_NSFW) (b) => !(b.nsfw && filterOptions.nsfw === NSFWFilter.Hide_NSFW)
) )
// Only apply filtering if the user is not an admin or the admin has not selected "Unmoderated Fully" if (isOnlyBlocked && isAdmin) {
// Allow "Unmoderated Fully" when author visits own profile _blogs = _blogs.filter(
if (!((isAdmin || isOwner) && isUnmoderatedFully)) { (b) =>
muteLists.admin.authors.includes(b.author!) ||
muteLists.admin.replaceableEvents.includes(b.aTag!)
)
} else if (isUnmoderatedFully && (isAdmin || isOwner)) {
// Only apply filtering if the user is not an admin or the admin has not selected "Unmoderated Fully"
// Allow "Unmoderated Fully" when author visits own profile
} else {
_blogs = _blogs.filter( _blogs = _blogs.filter(
(b) => (b) =>
!muteLists.admin.authors.includes(b.author!) && !muteLists.admin.authors.includes(b.author!) &&

View File

@ -174,12 +174,15 @@ const Filters = React.memo(() => {
</button> </button>
<div className='dropdown-menu dropdownMainMenu'> <div className='dropdown-menu dropdownMainMenu'>
{Object.values(ModeratedFilter).map((item, index) => { {Object.values(ModeratedFilter).map((item, index) => {
if (item === ModeratedFilter.Unmoderated_Fully) { const isAdmin =
const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
userState.user?.npub ===
import.meta.env.VITE_REPORTING_NPUB
if (!isAdmin) return null if (item === ModeratedFilter.Only_Blocked && !isAdmin) {
return null
}
if (item === ModeratedFilter.Unmoderated_Fully && !isAdmin) {
return null
} }
return ( return (
@ -439,9 +442,16 @@ const UsersResult = ({
const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
const isUnmoderatedFully = const isUnmoderatedFully =
moderationFilter === ModeratedFilter.Unmoderated_Fully moderationFilter === ModeratedFilter.Unmoderated_Fully
const isOnlyBlocked = moderationFilter === ModeratedFilter.Only_Blocked
// Only apply filtering if the user is not an admin or the admin has not selected "Unmoderated Fully" if (isOnlyBlocked && isAdmin) {
if (!(isAdmin && isUnmoderatedFully)) { filtered = filtered.filter((profile) =>
muteLists.admin.authors.includes(profile.pubkey as string)
)
} else if (isUnmoderatedFully && isAdmin) {
// Only apply filtering if the user is not an admin
// or the admin has not selected "Unmoderated Fully"
} else {
filtered = filtered.filter( filtered = filtered.filter(
(profile) => !muteLists.admin.authors.includes(profile.pubkey as string) (profile) => !muteLists.admin.authors.includes(profile.pubkey as string)
) )

View File

@ -14,7 +14,8 @@ export enum NSFWFilter {
export enum ModeratedFilter { export enum ModeratedFilter {
Moderated = 'Moderated', Moderated = 'Moderated',
Unmoderated = 'Unmoderated', Unmoderated = 'Unmoderated',
Unmoderated_Fully = 'Unmoderated Fully' Unmoderated_Fully = 'Unmoderated Fully',
Only_Blocked = 'Only Moderated'
} }
export enum WOTFilterOptions { export enum WOTFilterOptions {