From a29c57e37afacc9fa6eaf6e2856e802b323a9a6c Mon Sep 17 00:00:00 2001 From: neodk2004 Date: Wed, 12 Aug 2026 14:23:00 +0200 Subject: [PATCH] feat(admin): hide posts without deleting (Gitea #10 Phase 3, part 1/4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds Post.hiddenAt (nullable, db push applied) plus MODERATOR+ admin mutations hidePost/unhidePost, each logging HIDE_POST/UNHIDE_POST to ModerationLog with the standard moderatorRole+ipAddress stamp. hidePost requires a non-empty reason (visible to nobody but audit trail); unhidePost is a plain reversal. The admin posts grid shows a "Hidden" overlay badge and swaps the delete-adjacent action button between hide/unhide based on hiddenAt. Every reader-facing post query now filters hiddenAt: null so a hidden post disappears everywhere without touching its row: feed (discovery candidates, Postgres fallback, and the Redis-postId lookup — the same place blocked-pet filtering already happens, so an already-fanned-out hidden post silently drops out at read time), feed backfill on new follows, explore trending, profile grid, hashtag search, and the milestones tab. Admin-facing queries (listPosts, analytics bucketing) are deliberately NOT filtered — moderators need to see hidden posts to unhide them, and volume analytics shouldn't be skewed by moderation actions. Gitea #10 --- prisma/schema.prisma | 9 +++- src/app/p/[secret]/posts/page.tsx | 89 ++++++++++++++++++++++++++++++- src/lib/feed-helpers.ts | 2 +- src/trpc/routers/admin.ts | 54 +++++++++++++++++++ src/trpc/routers/explore.ts | 2 +- src/trpc/routers/feed.ts | 3 ++ src/trpc/routers/milestones.ts | 2 +- src/trpc/routers/posts.ts | 1 + src/trpc/routers/search.ts | 1 + 9 files changed, 158 insertions(+), 5 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index a52d71a..89c80d5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -246,6 +246,13 @@ model Post { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt + // Moderation "hide without delete" (Gitea #10 Phase 3) — set by an admin + // HIDE_POST action, cleared by UNHIDE_POST. Data stays intact for record + // purposes; every reader-facing query (feed/explore/profile/search/ + // hashtag/milestones) filters hiddenAt: null. Admin views intentionally + // do NOT filter on this so moderators can still see + unhide. + hiddenAt DateTime? + // Denormalized engagement counters — kept in sync transactionally at each // reaction/comment/repost create+delete site (reactions.ts, comments.ts, // reposts.ts, admin.ts deleteComment). Avoids live _count aggregation on @@ -686,7 +693,7 @@ model AdRepost { model ModerationLog { id String @id @default(cuid()) - action String @db.VarChar(50) // DELETE_POST | DELETE_COMMENT | BAN_USER | UNBAN_USER | DELETE_IMAGE | DISMISS_REPORT | CREATE_AD | UPDATE_AD | DELETE_AD | GRANT_ROLE | REVOKE_ROLE | WARN_USER | VERIFY_PET | UNVERIFY_PET | DELETE_ACCOUNT | APPROVE_VERIFICATION_REQUEST | REJECT_VERIFICATION_REQUEST + action String @db.VarChar(50) // DELETE_POST | DELETE_COMMENT | BAN_USER | UNBAN_USER | DELETE_IMAGE | DISMISS_REPORT | CREATE_AD | UPDATE_AD | DELETE_AD | GRANT_ROLE | REVOKE_ROLE | WARN_USER | VERIFY_PET | UNVERIFY_PET | DELETE_ACCOUNT | APPROVE_VERIFICATION_REQUEST | REJECT_VERIFICATION_REQUEST | HIDE_POST | UNHIDE_POST targetType String @db.VarChar(20) // POST | COMMENT | USER | IMAGE | AD | REPORT | PET targetId String reason String? @db.VarChar(500) diff --git a/src/app/p/[secret]/posts/page.tsx b/src/app/p/[secret]/posts/page.tsx index 0f58704..6ae12b5 100644 --- a/src/app/p/[secret]/posts/page.tsx +++ b/src/app/p/[secret]/posts/page.tsx @@ -3,7 +3,7 @@ import { useEffect, useState } from "react"; import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useTRPC } from "@/trpc/client"; -import { Trash2, MessageSquare, Loader2, ChevronDown, Play, ImageOff, PawPrint } from "lucide-react"; +import { Trash2, MessageSquare, Loader2, ChevronDown, Play, ImageOff, PawPrint, EyeOff, Eye } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; @@ -45,7 +45,9 @@ export default function AdminPostsPage() { } const [commentsPostId, setCommentsPostId] = useState(null); const [deleteTarget, setDeleteTarget] = useState<{ id: string; type: "post" | "comment" } | null>(null); + const [hideTargetId, setHideTargetId] = useState(null); const [reason, setReason] = useState(""); + const [hideReason, setHideReason] = useState(""); const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } = useInfiniteQuery( trpc.admin.listPosts.infiniteQueryOptions( @@ -85,6 +87,29 @@ export default function AdminPostsPage() { }) ); + const hidePost = useMutation( + trpc.admin.hidePost.mutationOptions({ + onSuccess: () => { + void qc.invalidateQueries({ queryKey: trpc.admin.listPosts.queryKey() }); + setHideTargetId(null); + setHideReason(""); + }, + }) + ); + + const unhidePost = useMutation( + trpc.admin.unhidePost.mutationOptions({ + onSuccess: () => { + void qc.invalidateQueries({ queryKey: trpc.admin.listPosts.queryKey() }); + }, + }) + ); + + function confirmHide() { + if (!hideTargetId || !hideReason.trim()) return; + hidePost.mutate({ postId: hideTargetId, reason: hideReason.trim() }); + } + function confirmDelete() { if (!deleteTarget) return; if (deleteTarget.type === "post") { @@ -180,6 +205,14 @@ export default function AdminPostsPage() {