Browse Source

fix: filter out non-root patches in proposal lists

prevent non-root patches from displaying on homepage where possible

via client side filter for non-root patches on repositories
that support the latest nip34 spec

on repository pages this is included in the relay subscription but when
we are getting patches for all repositories, like on the homepage,
we don't know ahead of time which ones support the latest spec
master
DanConwayDev 2 years ago
parent
commit
56631c1d5b
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 33
      src/lib/stores/Proposals.ts
  2. 15
      src/lib/stores/repos.ts

33
src/lib/stores/Proposals.ts

@ -19,6 +19,7 @@ import { @@ -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<ProposalSummaries> = writable({
id: '',
@ -106,7 +107,7 @@ export const ensureProposalSummaries = async (repo_id: string | undefined) => { @@ -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) => { @@ -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) => { @@ -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) => { @@ -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(

15
src/lib/stores/repos.ts

@ -17,6 +17,21 @@ export const repos: { @@ -17,6 +17,21 @@ export const repos: {
[unique_commit_or_identifier: string]: Writable<RepoCollection>
} = {}
export const returnRepoCollection = async (
unique_commit_or_identifier: string
): Promise<RepoCollection> => {
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<RepoCollection> => {

Loading…
Cancel
Save