From cdf23c7fac8b56f4b2be158cdc68e77371e3efec Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 16 Jan 2025 12:56:46 +0100 Subject: [PATCH] feat(mutelist): add post warnings to blog/mod + fix: block/unblock string --- src/components/PostWarning.tsx | 22 ++++++++++++++++++++++ src/pages/blog/index.tsx | 4 +++- src/pages/blog/loader.ts | 28 ++++++++++++++++++++++++++-- src/pages/mod/index.tsx | 5 ++++- src/pages/mod/loader.ts | 26 ++++++++++++++++++++++++-- src/types/blog.ts | 1 + src/types/mod.ts | 1 + 7 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 src/components/PostWarning.tsx diff --git a/src/components/PostWarning.tsx b/src/components/PostWarning.tsx new file mode 100644 index 0000000..f476c67 --- /dev/null +++ b/src/components/PostWarning.tsx @@ -0,0 +1,22 @@ +interface PostWarningsProps { + type: 'user' | 'admin' +} + +export const PostWarnings = ({ type }: PostWarningsProps) => ( +
+

+ {type === 'admin' ? ( + <> + Warning: This post has been blocked/hidden by the site for one of the + following reasons: +
+ Malware, Not a Mod, Illegal, Spam, Verified Report of Unauthorized + Repost. +
+ + ) : ( + <>Notice: You have blocked this post + )} +

+
+) diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 60927ff..47d5cd6 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -18,6 +18,7 @@ import { toast } from 'react-toastify' import { useAppSelector, useBodyScrollDisable } from 'hooks' import { ReportPopup } from 'components/ReportPopup' import { Viewer } from 'components/Markdown/Viewer' +import { PostWarnings } from 'components/PostWarning' const BLOG_REPORT_REASONS = [ { label: 'Actually CP', key: 'actuallyCP' }, @@ -29,7 +30,7 @@ const BLOG_REPORT_REASONS = [ ] export const BlogPage = () => { - const { blog, latest, isAddedToNSFW, isBlocked } = + const { blog, latest, isAddedToNSFW, isBlocked, postWarning } = useLoaderData() as BlogPageLoaderResult const userState = useAppSelector((state) => state.user) const isAdmin = @@ -84,6 +85,7 @@ export const BlogPage = () => { <>
+ {postWarning && }
{ - const { mod } = useLoaderData() as ModPageLoaderResult + const { mod, postWarning } = useLoaderData() as ModPageLoaderResult // We can get author right away from naddr, no need to wait for mod data const { naddr } = useParams() @@ -98,6 +99,7 @@ export const ModPage = () => { <>
+ {postWarning && } {

Mod Download

+ {postWarning && } {mod.downloadUrls.length > 0 && (
diff --git a/src/pages/mod/loader.ts b/src/pages/mod/loader.ts index e490e65..38e6c55 100644 --- a/src/pages/mod/loader.ts +++ b/src/pages/mod/loader.ts @@ -50,6 +50,7 @@ export const modRouteLoader = const userState = store.getState().user const loggedInUserPubkey = (userState?.user?.pubkey as string | undefined) || getFallbackPubkey() + const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB // Check if editing and the user is the original author // Redirect if NOT @@ -146,10 +147,33 @@ export const modRouteLoader = if (muteLists.status === 'fulfilled' && muteLists.value) { if (muteLists && muteLists.value) { if (result.mod && result.mod.aTag) { + // Show user or admin post warning if any mute list includes either post or author + if ( + muteLists.value.user.replaceableEvents.includes( + result.mod.aTag + ) || + muteLists.value.user.authors.includes(result.mod.author) + ) { + result.postWarning = 'user' + } + if ( muteLists.value.admin.replaceableEvents.includes( result.mod.aTag ) || + muteLists.value.admin.authors.includes(result.mod.author) + ) { + result.postWarning = 'admin' + } + + if ( + isAdmin && + muteLists.value.admin.replaceableEvents.includes(result.mod.aTag) + ) { + result.isBlocked = true + } + if ( + !isAdmin && muteLists.value.user.replaceableEvents.includes(result.mod.aTag) ) { result.isBlocked = true @@ -157,8 +181,6 @@ export const modRouteLoader = } // Moderate the latest - const isAdmin = - userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB const isOwner = userState.user?.pubkey && userState.user.pubkey === pubkey const isUnmoderatedFully = diff --git a/src/types/blog.ts b/src/types/blog.ts index 813c76c..7e7fc18 100644 --- a/src/types/blog.ts +++ b/src/types/blog.ts @@ -39,6 +39,7 @@ export interface BlogPageLoaderResult { latest: Partial[] isAddedToNSFW: boolean isBlocked: boolean + postWarning?: 'user' | 'admin' } export interface BlogsFilterOptions { diff --git a/src/types/mod.ts b/src/types/mod.ts index 1b4ae53..a62fe5b 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -66,6 +66,7 @@ export interface ModPageLoaderResult { isAddedToNSFW: boolean isBlocked: boolean isRepost: boolean + postWarning?: 'user' | 'admin' } export type SubmitModActionResult =