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 */}
<Dropdown label={filterOptions.moderated}>
{Object.values(ModeratedFilter).map((item, index) => {
if (item === ModeratedFilter.Unmoderated_Fully) {
const isAdmin =
userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
const isAdmin =
userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
if (item === ModeratedFilter.Only_Blocked && !isAdmin) {
return null
}
if (item === ModeratedFilter.Unmoderated_Fully) {
const isOwnProfile =
author && userState.auth && userState.user?.pubkey === author

View File

@ -128,10 +128,19 @@ export const useFilteredMods = (
npubToHex(userState.user.npub as string) === author
const isUnmoderatedFully =
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"
// Allow "Unmoderated Fully" when author visits own profile
if (!((isAdmin || isOwner) && isUnmoderatedFully)) {
if (isOnlyBlocked && isAdmin) {
filtered = filtered.filter(
(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(
(mod) =>
!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')
}
// Check the lateast blog events
// Check the latest blog events
const fetchEventsResult = settled[1]
if (fetchEventsResult.status === 'fulfilled' && fetchEventsResult.value) {
// 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')
}
// Check the lateast blog events
// Check the latest blog events
const fetchEventsResult = settled[1]
if (fetchEventsResult.status === 'fulfilled' && fetchEventsResult.value) {
// Extract the blog card details from the events

View File

@ -767,6 +767,8 @@ const ProfileTabBlogs = () => {
userState.user?.pubkey && userState.user.pubkey === profilePubkey
const isUnmoderatedFully =
filterOptions.moderated === ModeratedFilter.Unmoderated_Fully
const isOnlyBlocked =
filterOptions.moderated === ModeratedFilter.Only_Blocked
// Add nsfw tag to blogs included in nsfwList
if (filterOptions.nsfw !== NSFWFilter.Hide_NSFW) {
@ -782,9 +784,16 @@ const ProfileTabBlogs = () => {
(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"
// Allow "Unmoderated Fully" when author visits own profile
if (!((isAdmin || isOwner) && isUnmoderatedFully)) {
if (isOnlyBlocked && isAdmin) {
_blogs = _blogs.filter(
(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(
(b) =>
!muteLists.admin.authors.includes(b.author!) &&

View File

@ -174,12 +174,15 @@ const Filters = React.memo(() => {
</button>
<div className='dropdown-menu dropdownMainMenu'>
{Object.values(ModeratedFilter).map((item, index) => {
if (item === ModeratedFilter.Unmoderated_Fully) {
const isAdmin =
userState.user?.npub ===
import.meta.env.VITE_REPORTING_NPUB
const isAdmin =
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 (
@ -439,9 +442,16 @@ const UsersResult = ({
const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB
const isUnmoderatedFully =
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 (!(isAdmin && isUnmoderatedFully)) {
if (isOnlyBlocked && isAdmin) {
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(
(profile) => !muteLists.admin.authors.includes(profile.pubkey as string)
)

View File

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