fix(post ids): avoid cid fallback for poster identity

This commit is contained in:
Tommaso Casaburi
2026-06-13 17:56:15 +07:00
parent fb03957835
commit cdb1d13bef
6 changed files with 21 additions and 8 deletions
@@ -549,7 +549,7 @@ describe('post community address compatibility', () => {
expect(container.textContent).toContain('ID: ReplyKid'); expect(container.textContent).toContain('ID: ReplyKid');
}); });
it('falls back to the reply cid when published reply author metadata is missing', async () => { it('shows a pending ID while published reply author metadata is missing', async () => {
testState.pseudonymityMode = 'per-post'; testState.pseudonymityMode = 'per-post';
const post = makeLegacyThread(); const post = makeLegacyThread();
const reply = post.replies?.pages?.new?.comments?.[0]; const reply = post.replies?.pages?.new?.comments?.[0];
@@ -560,10 +560,10 @@ describe('post community address compatibility', () => {
reply.author = {}; reply.author = {};
await renderWithRoute(createElement(PostDesktop, { post, showAllReplies: true }), '/mu/thread/post-1'); await renderWithRoute(createElement(PostDesktop, { post, showAllReplies: true }), '/mu/thread/post-1');
expect(container.textContent).toContain('ID: Qmb4NxbR'); expect(container.textContent).toContain('ID: Pending');
await renderWithRoute(createElement(PostMobile, { post, showAllReplies: true }), '/mu/thread/post-1'); await renderWithRoute(createElement(PostMobile, { post, showAllReplies: true }), '/mu/thread/post-1');
expect(container.textContent).toContain('ID: Qmb4NxbR'); expect(container.textContent).toContain('ID: Pending');
}); });
it('forwards Pretext-backed reply estimates into Virtuoso for desktop and mobile thread views', async () => { it('forwards Pretext-backed reply estimates into Virtuoso for desktop and mobile thread views', async () => {
+1 -1
View File
@@ -387,7 +387,7 @@ const PostInfo = ({
t('removed') t('removed')
) : purged ? ( ) : purged ? (
t('purged') t('purged')
) : !cid && pseudonymityMode ? ( ) : !userID && pseudonymityMode ? (
<span className={styles.pendingCid}>{hasFailedState ? '?' : capitalize(t('pending'))}</span> <span className={styles.pendingCid}>{hasFailedState ? '?' : capitalize(t('pending'))}</span>
) : ( ) : (
<Tooltip <Tooltip
+1 -1
View File
@@ -321,7 +321,7 @@ const PostInfoAndMedia = ({
lowerCase(t('deleted')) lowerCase(t('deleted'))
) : purged ? ( ) : purged ? (
lowerCase(t('purged')) lowerCase(t('purged'))
) : !cid && pseudonymityMode ? ( ) : !userID && pseudonymityMode ? (
<span className={styles.pendingCid}>{hasFailedState ? '?' : capitalize(t('pending'))}</span> <span className={styles.pendingCid}>{hasFailedState ? '?' : capitalize(t('pending'))}</span>
) : ( ) : (
<Tooltip <Tooltip
@@ -27,14 +27,14 @@ describe('getThreadPostCountsByAuthor', () => {
expect(counts.get('author-b')).toBe(2); expect(counts.get('author-b')).toBe(2);
}); });
it('uses cid fallback for comments without author metadata', () => { it('skips comments without author metadata', () => {
const counts = getThreadPostCountsByAuthor( const counts = getThreadPostCountsByAuthor(
{ cid: 'post-1', author: { shortAddress: 'author-a' } } as any, { cid: 'post-1', author: { shortAddress: 'author-a' } } as any,
[{ cid: 'reply-1' }, { author: { shortAddress: 'author-b' } }] as any[], [{ cid: 'reply-1' }, { author: { shortAddress: 'author-b' } }] as any[],
); );
expect(counts.get('author-a')).toBe(1); expect(counts.get('author-a')).toBe(1);
expect(counts.get('reply-1')).toBe(1); expect(counts.has('reply-1')).toBe(false);
expect(counts.has('author-b')).toBe(false); expect(counts.has('author-b')).toBe(false);
}); });
}); });
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest';
import { getCommentUserID } from '../comment-user-id-utils';
describe('getCommentUserID', () => {
it('uses resolved author identity data for per-post user IDs', () => {
expect(getCommentUserID({ author: { address: 'poster.bso', shortAddress: 'short-poster' } } as any)).toBe('poster.bso');
expect(getCommentUserID({ author: { shortAddress: 'short-poster' } } as any)).toBe('short-poster');
});
it('does not fall back to the comment cid while author metadata is missing', () => {
expect(getCommentUserID({ cid: 'QmQU6BiPkB77b3rAkdj973ptTp5A6X77tfPrwTvCQDL9cq' } as any)).toBe('');
});
});
+1 -1
View File
@@ -3,5 +3,5 @@ import getShortAddress from '../get-short-address';
export function getCommentUserID(comment: Comment | undefined): string { export function getCommentUserID(comment: Comment | undefined): string {
const { address, shortAddress } = comment?.author || {}; const { address, shortAddress } = comment?.author || {};
return (address ? getShortAddress(address) : '') || shortAddress || comment?.cid || ''; return (address ? getShortAddress(address) : '') || shortAddress || '';
} }