From b6e78ac71c8f7f6d84ba53b1076097a0680c9c1c Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Fri, 3 Oct 2025 18:29:14 +0530 Subject: [PATCH] fix: moderation - cell owner can not moderate themselves - moderation on a content is calculated by the latest message --- app/src/components/CommentCard.tsx | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/components/CommentCard.tsx b/app/src/components/CommentCard.tsx index ed100cc..73fa239 100644 --- a/app/src/components/CommentCard.tsx +++ b/app/src/components/CommentCard.tsx @@ -1,12 +1,12 @@ import React from 'react'; import { ArrowUp, ArrowDown, Clock, Shield, UserX } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; -import type { CommentMessage } from '@opchan/core'; +import type { Comment } from '@opchan/core'; import { Button } from '@/components/ui/button'; import { BookmarkButton } from '@/components/ui/bookmark-button'; import { AuthorDisplay } from '@/components/ui/author-display'; import { MarkdownRenderer } from '@/components/ui/markdown-renderer'; -import { useContent, useForum, usePermissions } from '@/hooks'; +import { useContent, useForum, usePermissions, useAuth } from '@/hooks'; import { Tooltip, TooltipContent, @@ -15,7 +15,7 @@ import { import { ShareButton } from '@/components/ui/ShareButton'; interface CommentCardProps { - comment: CommentMessage; + comment: Comment; postId: string; cellId?: string; canModerate: boolean; @@ -50,6 +50,7 @@ const CommentCard: React.FC = ({ }) => { const content = useContent(); const permissions = usePermissions(); + const { currentUser } = useAuth(); // Check if bookmarked const isBookmarked = content.bookmarks.some( @@ -60,11 +61,11 @@ const CommentCard: React.FC = ({ // Use library pending API const commentVotePending = content.pending.isPending(comment.id); - // Get user vote status from filtered comment data - const userUpvoted = Boolean((comment as unknown as { userUpvoted?: boolean }).userUpvoted); - const userDownvoted = Boolean((comment as unknown as { userDownvoted?: boolean }).userDownvoted); - const score = (comment as unknown as { voteScore?: number }).voteScore ?? 0; - const isModerated = Boolean((comment as unknown as { moderated?: boolean }).moderated); + const score = comment.voteScore ?? 0; + const isModerated = Boolean(comment.moderated); + const userDownvoted = Boolean(comment.downvotes.some(v => v.author === currentUser?.address)); + const userUpvoted = Boolean(comment.upvotes.some(v => v.author === currentUser?.address)); + const isOwnComment = currentUser?.address === comment.author; const handleVoteComment = async (isUpvote: boolean) => { await content.vote({ targetId: comment.id, isUpvote }); @@ -85,7 +86,7 @@ const CommentCard: React.FC = ({
- {canModerate && !isModerated && ( + {canModerate && !isModerated && !isOwnComment && (