Browse Source

feat: use relays from naddr and nevent

to find repo events and proposals not default relays
master
DanConwayDev 2 years ago
parent
commit
46d94eaac7
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 5
      src/lib/stores/repo.ts
  2. 21
      src/lib/stores/repos.ts
  3. 4
      src/lib/wrappers/RepoPageWrapper.svelte
  4. 9
      src/routes/e/[nostr_ref]/+page.svelte

5
src/lib/stores/repo.ts

@ -35,13 +35,14 @@ let selected_repo_a: string = '' @@ -35,13 +35,14 @@ let selected_repo_a: string = ''
let selected_unsubscriber: Unsubscriber
export const ensureSelectedRepoCollection = (
a: string
a: string,
naddr_relays: string[] | undefined = undefined,
): Writable<RepoCollection> => {
if (selected_repo_a !== a) {
let loading = true
selected_repo_a = a
if (selected_unsubscriber) selected_unsubscriber()
selected_unsubscriber = ensureRepoCollection(a).subscribe(
selected_unsubscriber = ensureRepoCollection(a, naddr_relays).subscribe(
(repo_collection) => {
selected_repo_collection.set({ ...repo_collection })
if (loading && !repo_collection.loading) {

21
src/lib/stores/repos.ts

@ -24,7 +24,10 @@ export const repo_collections: { @@ -24,7 +24,10 @@ export const repo_collections: {
[a: string]: Writable<RepoCollection>
} = {}
export const ensureRepo = (a: string | NDKEvent): Writable<RepoEvent> => {
export const ensureRepo = (
a: string | NDKEvent,
naddr_relays: string[] | undefined = undefined,
): Writable<RepoEvent> => {
if (typeof a !== 'string') {
const repo_event = eventToRepoEvent(a)
if (repo_event) {
@ -62,7 +65,7 @@ export const ensureRepo = (a: string | NDKEvent): Writable<RepoEvent> => { @@ -62,7 +65,7 @@ export const ensureRepo = (a: string | NDKEvent): Writable<RepoEvent> => {
groupableDelay: 200,
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(base_relays, ndk)
NDKRelaySet.fromRelayUrls([...base_relays, ...(naddr_relays || [])], ndk)
)
sub.on('event', (event: NDKEvent) => {
const repo_event = eventToRepoEvent(event)
@ -102,9 +105,12 @@ export const ensureRepo = (a: string | NDKEvent): Writable<RepoEvent> => { @@ -102,9 +105,12 @@ export const ensureRepo = (a: string | NDKEvent): Writable<RepoEvent> => {
return repos[a]
}
export const returnRepo = async (a: string): Promise<RepoEvent> => {
export const returnRepo = async (
a: string,
naddr_relays: string[] | undefined = undefined,
): Promise<RepoEvent> => {
return new Promise((r) => {
const unsubscriber = ensureRepo(a).subscribe((c) => {
const unsubscriber = ensureRepo(a, naddr_relays).subscribe((c) => {
if (!c.loading) {
setTimeout(() => {
if (unsubscriber) unsubscriber()
@ -115,7 +121,10 @@ export const returnRepo = async (a: string): Promise<RepoEvent> => { @@ -115,7 +121,10 @@ export const returnRepo = async (a: string): Promise<RepoEvent> => {
})
}
export const ensureRepoCollection = (a: string): Writable<RepoCollection> => {
export const ensureRepoCollection = (
a: string,
naddr_relays: string[] | undefined = undefined,
): Writable<RepoCollection> => {
if (!repo_collections[a]) {
const base: RepoCollection = {
...collection_defaults,
@ -130,7 +139,7 @@ export const ensureRepoCollection = (a: string): Writable<RepoCollection> => { @@ -130,7 +139,7 @@ export const ensureRepoCollection = (a: string): Writable<RepoCollection> => {
const { pubkey, identifier } = a_ref
returnRepo(a).then(async (repo_event) => {
returnRepo(a, naddr_relays).then(async (repo_event) => {
if (get(repo_collections[a]).events.length > 0) return
repo_collections[a].update((collection) => {
return {

4
src/lib/wrappers/RepoPageWrapper.svelte

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
import { ensureProposalSummaries } from '$lib/stores/Proposals'
import { ensureIssueSummaries } from '$lib/stores/Issues'
import type { RepoPage } from '$lib/components/repo/type'
import { naddrToRepoA } from '$lib/components/repo/utils'
import { naddrToPointer, naddrToRepoA } from '$lib/components/repo/utils'
import AlertError from '$lib/components/AlertError.svelte'
export let repo_naddr = ''
@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
if (a_result) {
a = a_result
invalid_naddr = false
ensureSelectedRepoCollection(a)
ensureSelectedRepoCollection(a, naddrToPointer(repo_naddr)?.relays)
ensureProposalSummaries(a)
ensureIssueSummaries(a)
} else {

9
src/routes/e/[nostr_ref]/+page.svelte

@ -23,7 +23,10 @@ @@ -23,7 +23,10 @@
waited = true
}
let lookupEvent = (id: string) => {
let lookupEvent = (
id: string,
relays: string[] | undefined = undefined,
) => {
let sub = ndk.subscribe(
{
ids: [id],
@ -32,7 +35,7 @@ @@ -32,7 +35,7 @@
{
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(base_relays, ndk)
NDKRelaySet.fromRelayUrls([ ...base_relays, ...(relays || [])] ndk)
)
sub.on('event', (event: NDKEvent) => {
@ -82,7 +85,7 @@ @@ -82,7 +85,7 @@
[patch_kind, issue_kind].includes(decoded.data.kind)
)
) {
lookupEvent(decoded.data.id)
lookupEvent(decoded.data.id, decoded.data.relays)
} else {
showError()
}

Loading…
Cancel
Save