diff --git a/src/lib/stores/Proposals.ts b/src/lib/stores/Proposals.ts index e772d37..40f9bde 100644 --- a/src/lib/stores/Proposals.ts +++ b/src/lib/stores/Proposals.ts @@ -19,6 +19,7 @@ import { } from '$lib/kinds' import { extractPatchMessage } from '$lib/components/events/content/utils' import { selectRepoFromCollection } from '$lib/components/repo/utils' +import { returnRepoCollection } from './repos' export const proposal_summaries: Writable = writable({ id: '', @@ -106,7 +107,7 @@ export const ensureProposalSummaries = async (repo_id: string | undefined) => { NDKRelaySet.fromRelayUrls(relays_to_use, ndk) ) - sub.on('event', (event: NDKEvent) => { + sub.on('event', async (event: NDKEvent) => { try { if ( event.kind == patch_kind && @@ -117,6 +118,9 @@ export const ensureProposalSummaries = async (repo_id: string | undefined) => { // link to proposal will not work as it requires an identifier return } + const repo_identifier = + extractRepoIdentiferFromProposalEvent(event) || repo_id || '' + proposal_summaries.update((proposals) => { return { ...proposals, @@ -125,8 +129,7 @@ export const ensureProposalSummaries = async (repo_id: string | undefined) => { { ...summary_defaults, id: event.id, - repo_identifier: - extractRepoIdentiferFromProposalEvent(event) || repo_id || '', + repo_identifier, title: ( event.tagValue('name') || event.tagValue('description') || @@ -146,6 +149,30 @@ export const ensureProposalSummaries = async (repo_id: string | undefined) => { ], } }) + + // filter out non root proposals if repo event supports nip34+ features + if (!repo_id && repo_identifier.length > 0) { + const repo_collection = await returnRepoCollection(repo_identifier) + if (repo_collection.unique_commit) { + proposal_summaries.update((proposals) => { + return { + ...proposals, + summaries: [ + ...proposals.summaries.filter( + (summary) => + (event.tags.some( + (t) => t.length > 1 && t[1] === 'root' + ) && + !event.tags.some( + (t) => t.length > 1 && t[1] === 'revision-root' + )) || + event.id !== summary.id + ), + ], + } + }) + } + } } authors_unsubscribers.push( diff --git a/src/lib/stores/repos.ts b/src/lib/stores/repos.ts index 2205bde..3c4d4cc 100644 --- a/src/lib/stores/repos.ts +++ b/src/lib/stores/repos.ts @@ -17,6 +17,21 @@ export const repos: { [unique_commit_or_identifier: string]: Writable } = {} +export const returnRepoCollection = async ( + unique_commit_or_identifier: string +): Promise => { + return new Promise((r) => { + const unsubscriber = ensureRepoCollection( + unique_commit_or_identifier + ).subscribe((c) => { + if (!c.loading) { + unsubscriber() + r(c) + } + }) + }) +} + export const ensureRepoCollection = ( unique_commit_or_identifier: string ): Writable => {