fix(post ids): fall back to comment cid for missing ids (#1167)

* fix(post ids): fall back to comment cid for missing ids

* fix(post ids): count cid-resolved account replies
This commit is contained in:
Tommaso Casaburi
2026-06-09 19:08:02 +07:00
committed by GitHub
parent 9de2e6a851
commit c0f1a77958
8 changed files with 208 additions and 68 deletions
+20 -20
View File
@@ -24,15 +24,15 @@ import useScrollToReply from '../../hooks/use-scroll-to-reply';
import useSafeAccountComment from '../../hooks/use-safe-account-comment';
import { useCurrentTime } from '../../hooks/use-current-time';
import { useBoardPseudonymityMode } from '../../hooks/use-board-pseudonymity-mode';
import CommentContent from '../comment-content';
import CommentMedia, { MediaLoadFailureInfo } from '../comment-media';
import CommentContent from '../comment-content/comment-content';
import CommentMedia, { MediaLoadFailureInfo } from '../comment-media/comment-media';
import FailedPublishNotice from '../failed-publish-notice';
import LoadingEllipsis from '../loading-ellipsis';
import LoadingEllipsis from '../loading-ellipsis/loading-ellipsis';
import PostAuthorFlags from '../post-author-flags';
import PostFlashTag from '../post-flash-tag';
import PostMenuMobile from './post-menu-mobile';
import ReplyQuotePreview from '../reply-quote-preview';
import Tooltip from '../tooltip';
import PostMenuMobile from './post-menu-mobile/post-menu-mobile';
import ReplyQuotePreview from '../reply-quote-preview/reply-quote-preview';
import Tooltip from '../tooltip/tooltip';
import TimeAgoTooltip from '../time-ago-tooltip';
import { PostProps } from '../../views/post/post';
import capitalize from 'lodash/capitalize';
@@ -58,6 +58,7 @@ import { getThreadTopNavigationState, scrollThreadContainerToTop } from '../../l
import useDeleteFailedPost from '../../hooks/use-delete-failed-post';
import { getThreadPostCountsByAuthor } from '../../lib/utils/author-post-counts';
import { withResolvedCommentCommunityAddress } from '../../lib/utils/comment-utils';
import { getCommentUserID } from '../../lib/utils/comment-user-id-utils';
import { getFeedPostHeightEstimate, getReplyHeightEstimates, reportReplyHeightAuditSample } from '../../lib/utils/pretext-height-estimates';
import { getAuthorBadge } from '../../lib/utils/author-display-utils';
import { hasCommentFlagsForDirectory } from '../../lib/comment-flag-selection';
@@ -100,7 +101,7 @@ const PostInfoAndMedia = ({
: undefined;
const isReply = parentCid;
const title = post?.title?.trim();
const { address, shortAddress } = author || {};
const { address } = author || {};
const displayName = author?.displayName?.trim();
const authorBadge = getAuthorBadge({ address, role: roles?.[address]?.role });
@@ -220,17 +221,17 @@ const PostInfoAndMedia = ({
const pseudonymityMode = useBoardPseudonymityMode(communityAddress);
const showUserID = pseudonymityMode === 'per-post';
const userID = getCommentUserID(resolvedPost);
const handleUserAddressClick = useAuthorAddressClick();
const numberOfPostsByAuthor = (() => {
if (!showUserID || deleted || removed || purged || !shortAddress || !postCid) {
if (!showUserID || deleted || removed || purged || !userID || !postCid) {
return 0;
}
return Math.max(postsByAuthorInThread?.get(shortAddress) ?? 0, 1);
return Math.max(postsByAuthorInThread?.get(userID) ?? 0, 1);
})();
const userID = address ? getShortAddress(address) : shortAddress;
const userIDBackgroundColor = hashStringToColor(userID);
const userIDTextColor = getTextColorForBackground(userIDBackgroundColor);
@@ -532,17 +533,20 @@ const Reply = ({
disableDeferredLayout,
}: PostProps & { directRepliesByParentCid?: Map<string, Comment[]>; postsByAuthorInThread?: Map<string, number>; disableDeferredLayout?: boolean }) => {
const accountReply = useSafeAccountComment({
commentCid: reply?.cid,
commentIndex: typeof reply?.index === 'number' ? reply.index : undefined,
});
const hasReplyIndex = typeof reply?.index === 'number';
let post = hasReplyIndex && accountReply?.index === reply.index ? accountReply : reply;
const isAccountReply = (hasReplyIndex && accountReply?.index === reply.index) || (!!reply?.cid && accountReply?.cid === reply.cid);
let post = isAccountReply ? accountReply : reply;
// handle pending mod or author edit
const { editedComment } = useEditedComment({ comment: post });
if (editedComment) {
post = editedComment;
}
post = withResolvedCommentCommunityAddress(post);
const { author, cid, deleted, postCid, reason, removed, communityAddress } = post || {};
const { cid, deleted, postCid, reason, removed, communityAddress } = post || {};
const userID = getCommentUserID(post);
const purged = post?.commentModeration?.purged;
const directories = useDirectories();
const boardPath = communityAddress ? getBoardPath(communityAddress, directories) : undefined;
@@ -565,12 +569,7 @@ const Reply = ({
return (
<div className={`${styles.replyMobile} ${disableDeferredLayout ? styles.pretextVirtualizedReply : ''}`}>
<div className={styles.reply}>
<div
className={`${styles.replyContainer} ${isRouteLinkToReply && styles.highlight}`}
data-cid={cid}
data-author-address={author?.shortAddress}
data-post-cid={postCid}
>
<div className={`${styles.replyContainer} ${isRouteLinkToReply && styles.highlight}`} data-cid={cid} data-author-address={userID} data-post-cid={postCid}>
<PostInfoAndMedia
onMediaLoadFailureChange={setFailedMediaUrl}
post={post}
@@ -608,7 +607,8 @@ const PostMobile = ({
}: PostProps) => {
const { t } = useTranslation();
const resolvedPost = withResolvedCommentCommunityAddress(post);
const { author, cid, parentCid, postCid, replyCount, state, communityAddress } = resolvedPost || {};
const { cid, parentCid, postCid, replyCount, state, communityAddress } = resolvedPost || {};
const userID = getCommentUserID(resolvedPost);
const params = useParams();
const location = useLocation();
const navigationType = useNavigationType();
@@ -866,7 +866,7 @@ const PostMobile = ({
className={`${styles.postOp} ${shouldShowSnow() ? styles.xmasHatWrapper : ''}`}
data-thread-container-cid={cid}
data-cid={cid}
data-author-address={author?.shortAddress}
data-author-address={userID}
data-post-cid={postCid}
>
{shouldShowSnow() && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}