();
return new Set([...content.matchAll(/(?/\w])>>(\d+)(?![\d/])/g)].map((m) => parseInt(m[1], 10)));
}, [content]);
const relevantQuotedCids = useMemo(() => {
const cids = quotedCids ? [...quotedCids] : [];
if (parentCid) {
cids.push(parentCid);
}
return cids;
}, [quotedCids, parentCid]);
const cidToNumber = useScopedCidToNumber(relevantQuotedCids);
const filteredQuotedCids = useMemo(() => {
if (!quotedCids?.length) return [];
return quotedCids.filter((cid: string) => {
const num = cidToNumber[cid];
if (num === undefined) return false;
return !contentNumbers.has(num);
});
}, [quotedCids, cidToNumber, contentNumbers]);
const parentNumber = parentCid ? cidToNumber[parentCid] : undefined;
const shouldShowReplyingToReply = isReplyingToReply && parentNumber !== undefined && !contentNumbers.has(parentNumber);
const stateString = useStateString(resolvedPost);
const hasFailedState = state === 'failed';
const loadingString = (
{!hasFailedState ? : stateString || capitalize(t('failed'))}
);
return (
{prependContent && (
<>
{prependContent}
>
)}
{isReply &&
!hasFailedState &&
!(deleted || removed || purged) &&
(filteredQuotedCids.length > 0
? filteredQuotedCids.map((cid: string) => )
: shouldShowReplyingToReply && )}
{purged ? (
{capitalize(t('this_post_was_purged'))}
) : removed ? (
reason ? (
<>
({t('this_post_was_removed')})
{`${capitalize(t('reason'))}: "${reason}"`}
>
) : (
{capitalize(t('this_post_was_removed'))}.
)
) : deleted ? (
reason ? (
<>
{t('user_deleted_this_post')}{' '}
{`${capitalize(t('reason'))}: "${reason}"`}
>
) : (
{t('user_deleted_this_post')}
)
) : (
<>
{!showOriginal && }
{pendingApproval && (
<>
({t('pending_mod_approval')})
>
)}
{((!isInPostView && content?.length > 1000 && !showFullComment) || (isInPostView && content?.length > 2000 && !showFullComment)) && (
{
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
setShowFullComment(true);
}
}}
onClick={() => setShowFullComment(true)}
/>
),
}}
/>
)}
{edit && original?.content !== content && (
{showOriginal && }
),
}}
/>{' '}
{reason && <>{t('reason_reason', { reason: reason, interpolation: { escapeValue: false } })} >}
{showOriginal ? (
{
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
setShowOriginal(!showOriginal);
}
}}
onClick={() => setShowOriginal(!showOriginal)}
/>
),
}}
/>
) : (
{
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
setShowOriginal(!showOriginal);
}
}}
onClick={() => setShowOriginal(!showOriginal)}
/>
),
}}
/>
)}
)}
>
)}
{banned && (
{`(${t('user_banned')})`}
)}
{!cid && (
<>
{loadingString}
>
)}
);
};
export default CommentContent;