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

Function buildMockChannelThreadSummary

desktop/src/testing/e2eBridge.ts:3769–3813  ·  view source on GitHub ↗
(
  channelId: string,
  root: RelayEvent,
  events: RelayEvent[],
)

Source from the content-addressed store, hash-verified

3767}
3768
3769function buildMockChannelThreadSummary(
3770 channelId: string,
3771 root: RelayEvent,
3772 events: RelayEvent[],
3773): RelayEvent | null {
3774 const replies = events.filter((event) => {
3775 const thread = getThreadReferenceFromTags(event.tags);
3776 return thread.rootEventId === root.id;
3777 });
3778 if (replies.length === 0) return null;
3779
3780 const directReplies = replies.filter(
3781 (event) => getThreadReferenceFromTags(event.tags).parentEventId === root.id,
3782 );
3783 const participants = [
3784 ...new Set(
3785 replies
3786 .sort(
3787 (left, right) =>
3788 right.created_at - left.created_at ||
3789 left.id.localeCompare(right.id),
3790 )
3791 .map((event) => event.pubkey),
3792 ),
3793 ].slice(0, 10);
3794 const lastReplyAt = Math.max(...replies.map((event) => event.created_at));
3795 return {
3796 id: `mock-window-summary-${root.id}`,
3797 pubkey: DEFAULT_MOCK_IDENTITY.pubkey,
3798 created_at: Math.floor(Date.now() / 1000),
3799 kind: KIND_CHANNEL_THREAD_SUMMARY,
3800 tags: [
3801 ["e", root.id],
3802 ["d", root.id],
3803 ["h", channelId],
3804 ],
3805 content: JSON.stringify({
3806 reply_count: directReplies.length,
3807 descendant_count: replies.length,
3808 last_reply_at: lastReplyAt,
3809 participants,
3810 }),
3811 sig: "mocksig".repeat(20).slice(0, 128),
3812 };
3813}
3814
3815/**
3816 * Build the single kind-39006 bounds event a channel window response must carry.

Callers 1

executeFunction · 0.85

Calls 1

Tested by

no test coverage detected