mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(board-replies): include pending and mod-queue account comments in 5-reply preview
This commit is contained in:
@@ -2,15 +2,33 @@ import { BOARD_REPLIES_PREVIEW_VISIBLE_COUNT } from '../constants';
|
||||
|
||||
export interface CommentLike {
|
||||
cid?: string | null;
|
||||
index?: number;
|
||||
pendingApproval?: boolean;
|
||||
state?: string;
|
||||
timestamp?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* From replies sorted by 'new' (newest first), returns the latest N in chronological
|
||||
* display order (oldest of those first). Handles fewer-than-N replies.
|
||||
* Returns the latest N replies in chronological display order (oldest first).
|
||||
*
|
||||
* `useReplies` can append local account comments to the end of the preview array,
|
||||
* so we normalize by reply recency first to keep pending/mod-queue items visible in
|
||||
* board previews.
|
||||
*/
|
||||
export function getPreviewDisplayReplies<T extends CommentLike>(replies: T[], visibleCount: number = BOARD_REPLIES_PREVIEW_VISIBLE_COUNT): T[] {
|
||||
const slice = replies.slice(0, visibleCount);
|
||||
return [...slice].reverse();
|
||||
const getRecency = (reply: T): number => {
|
||||
if (typeof reply?.timestamp === 'number') {
|
||||
return reply.timestamp;
|
||||
}
|
||||
// Pending/local account replies can be missing timestamp early on.
|
||||
if (typeof reply?.index === 'number' || reply?.pendingApproval || (reply?.state && reply.state !== 'succeeded')) {
|
||||
return Number.POSITIVE_INFINITY;
|
||||
}
|
||||
return Number.NEGATIVE_INFINITY;
|
||||
};
|
||||
|
||||
const newestFirst = [...replies].sort((a, b) => getRecency(b) - getRecency(a));
|
||||
return newestFirst.slice(0, visibleCount).reverse();
|
||||
}
|
||||
|
||||
export interface ComputeOmittedParams {
|
||||
|
||||
Reference in New Issue
Block a user