mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(replies): hide author-deleted replies from thread views
This commit is contained in:
@@ -47,7 +47,7 @@ import { usePublishCommentModeration } from '@bitsocialnet/bitsocial-react-hooks
|
||||
import useQuotedByMap from '../../hooks/use-quoted-by-map';
|
||||
import useProgressiveRender from '../../hooks/use-progressive-render';
|
||||
import { BOARD_REPLIES_PREVIEW_FETCH_SIZE, BOARD_REPLIES_PREVIEW_VISIBLE_COUNT, REPLIES_PER_PAGE } from '../../lib/constants';
|
||||
import { computeOmittedCount, getPreviewDisplayReplies, getTotalReplyCount } from '../../lib/utils/replies-preview-utils';
|
||||
import { computeOmittedCount, filterRepliesForDisplay, getPreviewDisplayReplies, getTotalReplyCount } from '../../lib/utils/replies-preview-utils';
|
||||
|
||||
const { addChallenge } = useChallengesStore.getState();
|
||||
|
||||
@@ -892,8 +892,8 @@ const PostDesktop = ({
|
||||
const commentMediaInfo = useCommentMediaInfo(link, thumbnailUrl, linkWidth, linkHeight);
|
||||
const hasThumbnail = getHasThumbnail(commentMediaInfo, link);
|
||||
|
||||
// Filter out deleted replies with no children for both virtuoso and non-virtuoso rendering
|
||||
const filteredReplies = repliesForRender.filter((reply) => !(reply.deleted && (reply.replyCount === 0 || !reply.replyCount)));
|
||||
// Author-deleted replies are hidden from thread replies; moderator removals still render their placeholder.
|
||||
const filteredReplies = filterRepliesForDisplay(repliesForRender);
|
||||
const directRepliesByParentCid = (() => {
|
||||
const map = new Map<string, Comment[]>();
|
||||
for (const reply of filteredReplies) {
|
||||
|
||||
@@ -41,7 +41,7 @@ import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-util
|
||||
import useQuotedByMap from '../../hooks/use-quoted-by-map';
|
||||
import useProgressiveRender from '../../hooks/use-progressive-render';
|
||||
import { BOARD_REPLIES_PREVIEW_FETCH_SIZE, BOARD_REPLIES_PREVIEW_VISIBLE_COUNT, REPLIES_PER_PAGE } from '../../lib/constants';
|
||||
import { getPreviewDisplayReplies } from '../../lib/utils/replies-preview-utils';
|
||||
import { filterRepliesForDisplay, getPreviewDisplayReplies } from '../../lib/utils/replies-preview-utils';
|
||||
|
||||
const { addChallenge } = useChallengesStore.getState();
|
||||
|
||||
@@ -628,8 +628,8 @@ const PostMobile = ({
|
||||
const hasFailedState = state === 'failed';
|
||||
const isReply = !!parentCid;
|
||||
|
||||
// Filter out deleted replies with no children for both virtuoso and non-virtuoso rendering
|
||||
const filteredReplies = repliesForRender.filter((reply) => !(reply.deleted && (reply.replyCount === 0 || !reply.replyCount)));
|
||||
// Author-deleted replies are hidden from thread replies; moderator removals still render their placeholder.
|
||||
const filteredReplies = filterRepliesForDisplay(repliesForRender);
|
||||
const previewDisplayReplies = getPreviewDisplayReplies(filteredReplies, BOARD_REPLIES_PREVIEW_VISIBLE_COUNT);
|
||||
|
||||
const directRepliesByParentCid = (() => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { copyToClipboard } from '../clipboard-utils';
|
||||
import { hashStringToColor, getTextColorForBackground, removeMarkdown } from '../post-utils';
|
||||
import { preloadThemeAssets } from '../preload-utils';
|
||||
import { computeOmittedCount, getPreviewDisplayReplies, getTotalReplyCount } from '../replies-preview-utils';
|
||||
import { computeOmittedCount, filterRepliesForDisplay, getPreviewDisplayReplies, getTotalReplyCount } from '../replies-preview-utils';
|
||||
import { getQuotedCidsFromContent, mergeQuotedCids } from '../reply-quote-utils';
|
||||
import { formatUserIDForDisplay, truncateWithEllipsisInMiddle } from '../string-utils';
|
||||
import { getFormattedDate, getFormattedTimeAgo, isChristmas } from '../time-utils';
|
||||
@@ -120,6 +120,11 @@ describe('misc utils', () => {
|
||||
});
|
||||
|
||||
it('builds reply previews, omitted counts, and fallback reply totals', () => {
|
||||
expect(filterRepliesForDisplay([{ cid: 'visible' }, { cid: 'deleted', deleted: true }, { cid: 'removed', deleted: false }])).toEqual([
|
||||
{ cid: 'visible' },
|
||||
{ cid: 'removed', deleted: false },
|
||||
]);
|
||||
|
||||
expect(
|
||||
getPreviewDisplayReplies(
|
||||
[
|
||||
|
||||
@@ -2,12 +2,17 @@ import { BOARD_REPLIES_PREVIEW_VISIBLE_COUNT } from '../constants';
|
||||
|
||||
interface CommentLike {
|
||||
cid?: string | null;
|
||||
deleted?: boolean;
|
||||
index?: number;
|
||||
pendingApproval?: boolean;
|
||||
state?: string;
|
||||
timestamp?: number;
|
||||
}
|
||||
|
||||
export function filterRepliesForDisplay<T extends CommentLike>(replies: T[]): T[] {
|
||||
return replies.filter((reply) => !reply.deleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the latest N replies in chronological display order (oldest first).
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user