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
@@ -27,14 +27,14 @@ describe('getThreadPostCountsByAuthor', () => {
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(
{ cid: 'post-1', author: { shortAddress: 'author-a' } } as any,
[{ cid: 'reply-1' }, { author: { shortAddress: 'author-b' } }] as any[],
);
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);
});
});
@@ -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 {
const { address, shortAddress } = comment?.author || {};
return (address ? getShortAddress(address) : '') || shortAddress || comment?.cid || '';
return (address ? getShortAddress(address) : '') || shortAddress || '';
}