0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Added logic to hide deleted comments without replies

This commit is contained in:
Simon Backx 2022-07-07 15:09:24 +02:00
parent 9e9cd270b9
commit d0633fb70e

View file

@ -1,5 +1,5 @@
import {formatRelativeTime} from '../utils/helpers'; import {formatRelativeTime} from '../utils/helpers';
import React, {useState} from 'react'; import React, {useContext, useState} from 'react';
import Avatar from './Avatar'; import Avatar from './Avatar';
import Like from './Like'; import Like from './Like';
import Reply from './Reply'; import Reply from './Reply';
@ -7,6 +7,7 @@ import More from './More';
import EditForm from './EditForm'; import EditForm from './EditForm';
import Replies from './Replies'; import Replies from './Replies';
import ReplyForm from './ReplyForm'; import ReplyForm from './ReplyForm';
import AppContext from '../AppContext';
const Comment = (props) => { const Comment = (props) => {
const [isInEditMode, setIsInEditMode] = useState(false); const [isInEditMode, setIsInEditMode] = useState(false);
@ -20,11 +21,18 @@ const Comment = (props) => {
setIsInReplyMode(current => !current); setIsInReplyMode(current => !current);
}; };
const {admin} = useContext(AppContext);
const comment = props.comment; const comment = props.comment;
const hasReplies = comment.replies && comment.replies.length > 0; const hasReplies = comment.replies && comment.replies.length > 0 && !!comment.replies.find(r => r.status === 'published');
const isNotPublished = comment.status !== 'published'; const isNotPublished = comment.status !== 'published';
const html = {__html: comment.html}; const html = {__html: comment.html};
// Hide a comment if it has been deleted by the user and has no replies
// But keep showing comments if hidden by admin and logged in as admin
if ((comment.status === 'deleted' && !hasReplies) || (comment.status === 'hidden' && !hasReplies && !admin)) {
return null;
}
if (isNotPublished) { if (isNotPublished) {
html.__html = '<i>This comment has been removed.</i>'; html.__html = '<i>This comment has been removed.</i>';
} }