--- import Image from 'astro/components/Image.astro' import { Icon } from 'astro-icon/components' import { Markdown } from 'astro-remote' import { Schema } from 'astro-seo-schema' import { actions } from 'astro:actions' import { karmaUnlocksById } from '../constants/karmaUnlocks' import { getServiceUserRoleInfo } from '../constants/serviceUserRoles' import { cn } from '../lib/cn' import { makeCommentUrl, MAX_COMMENT_DEPTH, type CommentWithRepliesPopulated, } from '../lib/commentsWithReplies' import { computeKarmaUnlocks } from '../lib/karmaUnlocks' import { formatDateShort } from '../lib/timeAgo' import BadgeSmall from './BadgeSmall.astro' import CommentModeration from './CommentModeration.astro' import CommentReply from './CommentReply.astro' import TimeFormatted from './TimeFormatted.astro' import Tooltip from './Tooltip.astro' import type { HTMLAttributes } from 'astro/types' type Props = HTMLAttributes<'div'> & { comment: CommentWithRepliesPopulated depth?: number showPending?: boolean highlightedCommentId: number | null serviceSlug: string itemReviewedId: string } const { comment, depth = 0, showPending = false, highlightedCommentId = null, serviceSlug, itemReviewedId, class: className, ...htmlProps } = Astro.props const user = Astro.locals.user const userCommentsDisabled = user ? user.karmaUnlocks.commentsDisabled : false const authorUnlocks = computeKarmaUnlocks(comment.author.totalKarma) function checkIsHighlightParent(c: CommentWithRepliesPopulated, highlight: number | null): boolean { if (!highlight) return false if (c.id === highlight) return true if (!c.replies?.length) return false return c.replies.some((r) => checkIsHighlightParent(r, highlight)) } const isHighlightParent = checkIsHighlightParent(comment, highlightedCommentId) const isHighlighted = comment.id === highlightedCommentId // Get user's current vote if any const userVote = user ? comment.votes.find((v) => v.userId === user.id) : null const isAuthor = user?.id === comment.author.id const isAdminOrVerifier = !!user && (user.admin || user.verifier) const isAuthorOrPrivileged = isAuthor || isAdminOrVerifier // Check if user is new (less than 1 week old) const isNewUser = new Date().getTime() - new Date(comment.author.createdAt).getTime() < 7 * 24 * 60 * 60 * 1000 const isRatingActive = comment.rating !== null && !comment.parentId && comment.ratingActive && !comment.suspicious && (comment.status === 'APPROVED' || comment.status === 'VERIFIED') // Skip rendering if comment is not approved/verified and user is not the author or admin/verifier const shouldShow = comment.status === 'APPROVED' || comment.status === 'VERIFIED' || ((showPending || isHighlightParent || isHighlighted) && comment.status === 'PENDING') || ((showPending || isHighlightParent || isHighlighted) && comment.status === 'HUMAN_PENDING') || ((isHighlightParent || isHighlighted) && comment.status === 'REJECTED') || isAuthorOrPrivileged if (!shouldShow) return null const commentUrl = makeCommentUrl({ serviceSlug, commentId: comment.id, origin: Astro.url.origin }) ---