MCPcopy Create free account
hub / github.com/block/buzz / handleGetForumPosts

Function handleGetForumPosts

desktop/src/testing/e2eBridge.ts:3381–3415  ·  view source on GitHub ↗
(args: {
  channelId: string;
  limit?: number | null;
  before?: number | null;
})

Source from the content-addressed store, hash-verified

3379}
3380
3381async function handleGetForumPosts(args: {
3382 channelId: string;
3383 limit?: number | null;
3384 before?: number | null;
3385}): Promise<RawForumPostsResponse> {
3386 const events = getMockMessageStore(args.channelId);
3387 const posts = events
3388 .filter((event) => event.kind === 45001)
3389 .filter((event) => (args.before ? event.created_at < args.before : true))
3390 .sort((left, right) => right.created_at - left.created_at)
3391 .slice(0, args.limit ?? 50)
3392 .map((event) => {
3393 const replies = events.filter((candidate) => {
3394 if (candidate.kind !== 45003) {
3395 return false;
3396 }
3397
3398 const thread = getThreadReferenceFromTags(candidate.tags);
3399 return (thread.rootEventId ?? thread.parentEventId) === event.id;
3400 });
3401
3402 return toRawForumPost(event, args.channelId, {
3403 reply_count: replies.length,
3404 descendant_count: replies.length,
3405 last_reply_at:
3406 replies.length > 0 ? replies[replies.length - 1].created_at : null,
3407 participants: [...new Set(replies.map((reply) => reply.pubkey))],
3408 });
3409 });
3410
3411 return {
3412 messages: posts,
3413 next_cursor: null,
3414 };
3415}
3416
3417async function handleGetForumThread(args: {
3418 channelId: string;

Callers 1

handleMockCommandFunction · 0.85

Calls 3

getMockMessageStoreFunction · 0.85
toRawForumPostFunction · 0.85

Tested by

no test coverage detected