mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
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:
@@ -27,13 +27,14 @@ describe('getThreadPostCountsByAuthor', () => {
|
||||
expect(counts.get('author-b')).toBe(2);
|
||||
});
|
||||
|
||||
it('skips comments missing a cid or short address', () => {
|
||||
it('uses cid fallback for 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('author-b')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Comment } from '@bitsocial/bitsocial-react-hooks';
|
||||
import type { Comment } from '@bitsocial/bitsocial-react-hooks';
|
||||
import { getCommentUserID } from './comment-user-id-utils';
|
||||
|
||||
export function getThreadPostCountsByAuthor(post: Comment | undefined, replies: Comment[] = []): Map<string, number> {
|
||||
const counts = new Map<string, number>();
|
||||
@@ -6,11 +7,11 @@ export function getThreadPostCountsByAuthor(post: Comment | undefined, replies:
|
||||
|
||||
for (const comment of [post, ...replies]) {
|
||||
const cid = comment?.cid;
|
||||
const shortAddress = comment?.author?.shortAddress;
|
||||
if (!cid || !shortAddress || seenCids.has(cid)) continue;
|
||||
const userID = getCommentUserID(comment);
|
||||
if (!cid || !userID || seenCids.has(cid)) continue;
|
||||
|
||||
seenCids.add(cid);
|
||||
counts.set(shortAddress, (counts.get(shortAddress) ?? 0) + 1);
|
||||
counts.set(userID, (counts.get(userID) ?? 0) + 1);
|
||||
}
|
||||
|
||||
return counts;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { Comment } from '@bitsocial/bitsocial-react-hooks';
|
||||
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 || '';
|
||||
}
|
||||
Reference in New Issue
Block a user