mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(post ids): avoid cid fallback for poster identity
This commit is contained in:
@@ -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('');
|
||||
});
|
||||
});
|
||||
@@ -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 || '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user