mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
18 lines
572 B
TypeScript
18 lines
572 B
TypeScript
import { Comment } from '@bitsocial/bitsocial-react-hooks';
|
|
|
|
export function getThreadPostCountsByAuthor(post: Comment | undefined, replies: Comment[] = []): Map<string, number> {
|
|
const counts = new Map<string, number>();
|
|
const seenCids = new Set<string>();
|
|
|
|
for (const comment of [post, ...replies]) {
|
|
const cid = comment?.cid;
|
|
const shortAddress = comment?.author?.shortAddress;
|
|
if (!cid || !shortAddress || seenCids.has(cid)) continue;
|
|
|
|
seenCids.add(cid);
|
|
counts.set(shortAddress, (counts.get(shortAddress) ?? 0) + 1);
|
|
}
|
|
|
|
return counts;
|
|
}
|