From 1a0bc9fda7b0ce83041519a1ea43f014b562b2be Mon Sep 17 00:00:00 2001 From: miko Date: Tue, 12 Nov 2024 19:48:51 +0200 Subject: [PATCH] Exclude top level replies to a comment from a deleted channel from the total comment count --- ui/component/comment/view.jsx | 5 +++-- ui/component/commentsList/view.jsx | 5 +++-- ui/component/commentsReplies/view.jsx | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ui/component/comment/view.jsx b/ui/component/comment/view.jsx index 85285f9614..96e30adae0 100644 --- a/ui/component/comment/view.jsx +++ b/ui/component/comment/view.jsx @@ -70,7 +70,7 @@ export type Props = {| threadLevel?: number, threadDepthLevel?: number, disabled?: boolean, - updateUiFilteredComments?: (commentId: string) => void, + updateUiFilteredComments?: (commentIds: Array) => void, |}; type StateProps = {| @@ -315,7 +315,8 @@ function CommentView(props: Props & StateProps & DispatchProps) { if (isCommenterChannelDeleted) { if (updateUiFilteredComments) { - updateUiFilteredComments(commentId); + const fetchedReplyIds = fetchedReplies.map((r) => r.comment_id); + updateUiFilteredComments([...fetchedReplyIds, commentId]); } return null; } diff --git a/ui/component/commentsList/view.jsx b/ui/component/commentsList/view.jsx index 1f1f63aa09..de8f139c83 100644 --- a/ui/component/commentsList/view.jsx +++ b/ui/component/commentsList/view.jsx @@ -151,9 +151,10 @@ export default function CommentList(props: Props & StateProps & DispatchProps) { const [debouncedUri, setDebouncedUri] = React.useState(); const [uiFilteredComments, setUiFilteredComments] = React.useState([]); - const updateUiFilteredComments = React.useCallback((commentId) => { + const updateUiFilteredComments = React.useCallback((commentIds) => { setUiFilteredComments((prevCommentIds) => { - return prevCommentIds.includes(commentId) ? prevCommentIds : [...prevCommentIds, commentId]; + const newCommentIds = commentIds.filter((id) => !prevCommentIds.includes(id)); + return newCommentIds.length > 0 ? [...prevCommentIds, ...newCommentIds] : prevCommentIds; }); }, []); diff --git a/ui/component/commentsReplies/view.jsx b/ui/component/commentsReplies/view.jsx index 4a999a4e53..eec427271b 100644 --- a/ui/component/commentsReplies/view.jsx +++ b/ui/component/commentsReplies/view.jsx @@ -18,7 +18,7 @@ export type Props = {| threadDepthLevel?: number, onShowMore?: () => void, threadLevel: number, - updateUiFilteredComments?: (commentId: string) => void, + updateUiFilteredComments?: (commentIds: Array) => void, |}; type StateProps = {|