From c0754728ce8a04b12345f2e7696917fa52faa083 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 7 Feb 2024 16:33:58 +0000 Subject: [PATCH] feat(RepoPage): display nip34 patches as prs with nip34 in its current state there is no way to identify the root patch without first requesting all patches and client side filtering out the ones with `[ PATCH n/n ]` in the content this commit doesn't do that filtering --- src/lib/components/RepoSummaryCard.svelte | 5 +- src/lib/stores/PRs.ts | 88 ++++++++++++++++------- src/routes/repo/[repo_id]/+page.ts | 2 +- 3 files changed, 65 insertions(+), 30 deletions(-) diff --git a/src/lib/components/RepoSummaryCard.svelte b/src/lib/components/RepoSummaryCard.svelte index 1d51175..8b2b77e 100644 --- a/src/lib/components/RepoSummaryCard.svelte +++ b/src/lib/components/RepoSummaryCard.svelte @@ -22,8 +22,9 @@
{:else} - {short_name}{short_name} {#if short_descrption.length > 0}

diff --git a/src/lib/stores/PRs.ts b/src/lib/stores/PRs.ts index c73afeb..b179298 100644 --- a/src/lib/stores/PRs.ts +++ b/src/lib/stores/PRs.ts @@ -6,8 +6,9 @@ import type { User } from '$lib/components/users/type' import { ensureUser } from './users' import type { PRStatus, PRSummaries } from '$lib/components/prs/type' import { ensureSelectedRepo } from './repo' -import { pr_status_kind } from '$lib/kinds' +import { patch_kind, pr_kind, pr_status_kind, repo_kind } from '$lib/kinds' import type { Repo } from '$lib/components/repo/type' +import { extractPatchMessage } from '$lib/components/events/content/utils' export const pr_summaries: Writable = writable({ id: '', @@ -15,8 +16,6 @@ export const pr_summaries: Writable = writable({ loading: false, }) -const pr_kind: number = 318 - let selected_repo_id: string = '' let authors_unsubscribers: Unsubscriber[] = [] @@ -41,23 +40,58 @@ export const ensurePRSummaries = async (repo_id: string) => { const repo = await ensureSelectedRepo(repo_id) sub = ndk.subscribe( + [ + { + kinds: [pr_kind], + '#a': repo.maintainers.map( + (m) => `${repo_kind}:${m.hexpubkey}:${repo.repo_id}` + ), + limit: 50, + }, + { + kinds: [patch_kind], + '#a': repo.maintainers.map( + (m) => `${repo_kind}:${m.hexpubkey}:${repo.repo_id}` + ), + limit: 50, + }, + ], { - kinds: [pr_kind], - '#r': [`r-${repo_id}`], - limit: 50, + closeOnEose: true, }, - { - closeOnEose: false, - }, - NDKRelaySet.fromRelayUrls(repo.relays, ndk) + repo.relays.length > 0 + ? NDKRelaySet.fromRelayUrls(repo.relays, ndk) + : undefined ) sub.on('event', (event: NDKEvent) => { try { - if ( - event.kind == pr_kind && - event.getMatchingTags('r').find((t) => t[1] === `r-${repo_id}`) - ) { + if (event.kind == patch_kind && event.content.length > 0) { + pr_summaries.update((prs) => { + return { + ...prs, + summaries: [ + ...prs.summaries, + { + ...summary_defaults, + id: event.id, + repo_id: repo_id, + title: extractPatchMessage(event.content) || '', + descritpion: event.tagValue('description') || '', + created_at: event.created_at, + comments: 0, + author: { + hexpubkey: event.pubkey, + loading: true, + npub: '', + }, + loading: false, + }, + ], + } + }) + } + if (event.kind == pr_kind) { pr_summaries.update((prs) => { return { ...prs, @@ -81,21 +115,21 @@ export const ensurePRSummaries = async (repo_id: string) => { ], } }) + } - authors_unsubscribers.push( - ensureUser(event.pubkey).subscribe((u: User) => { - pr_summaries.update((prs) => { - return { - ...prs, - summaries: prs.summaries.map((o) => ({ - ...o, - author: u, - })), - } - }) + authors_unsubscribers.push( + ensureUser(event.pubkey).subscribe((u: User) => { + pr_summaries.update((prs) => { + return { + ...prs, + summaries: prs.summaries.map((o) => ({ + ...o, + author: event.pubkey === o.author.hexpubkey ? u : o.author, + })), + } }) - ) - } + }) + ) } catch {} }) sub.on('eose', () => { diff --git a/src/routes/repo/[repo_id]/+page.ts b/src/routes/repo/[repo_id]/+page.ts index 6afa119..4559657 100644 --- a/src/routes/repo/[repo_id]/+page.ts +++ b/src/routes/repo/[repo_id]/+page.ts @@ -1,5 +1,5 @@ export const load = ({ params }) => { return { - repo_id: params.repo_id, + repo_id: decodeURIComponent(params.repo_id), } }