Browse Source

fix(redirect): dont get issue or patch event twice

but instead pass event directly to ensureIssueFull() or
ensureProposalFull()
master
DanConwayDev 2 years ago
parent
commit
42fb8a21a2
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 44
      src/lib/stores/Issue.ts
  2. 43
      src/lib/stores/Proposal.ts
  3. 4
      src/routes/e/[nostr_ref]/+page.svelte

44
src/lib/stores/Issue.ts

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import { NDKRelaySet, type NDKEvent, NDKSubscription } from '@nostr-dev-kit/ndk'
import { NDKRelaySet, NDKEvent, NDKSubscription } from '@nostr-dev-kit/ndk'
import { writable, type Writable } from 'svelte/store'
import { base_relays, ndk } from './ndk'
import { type IssueFull, full_defaults } from '$lib/components/issues/type'
@ -28,7 +28,14 @@ let sub_replies: NDKSubscription @@ -28,7 +28,14 @@ let sub_replies: NDKSubscription
const sub_replies_to_replies: NDKSubscription[] = []
export const ensureIssueFull = (repo_a: string, issue_id: string) => {
export const ensureIssueFull = (
repo_a: string,
issue_id_or_event: string | NDKEvent
) => {
const issue_id =
typeof issue_id_or_event === 'string'
? issue_id_or_event
: issue_id_or_event.id
if (selected_issue_id == issue_id) return
if (issue_id == '') {
selected_issue_full.set({ ...full_defaults })
@ -64,20 +71,8 @@ export const ensureIssueFull = (repo_a: string, issue_id: string) => { @@ -64,20 +71,8 @@ export const ensureIssueFull = (repo_a: string, issue_id: string) => {
? repo.relays
: [...base_relays].concat(repo ? repo.relays : [])
sub = ndk.subscribe(
{
ids: [issue_id],
limit: 100,
},
{
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(relays_to_use, ndk)
)
sub.on('event', (event: NDKEvent) => {
const setEvent = (event: NDKEvent) => {
try {
if (event.id == issue_id) {
selected_issue_full.update((full) => {
return {
...full,
@ -93,8 +88,24 @@ export const ensureIssueFull = (repo_a: string, issue_id: string) => { @@ -93,8 +88,24 @@ export const ensureIssueFull = (repo_a: string, issue_id: string) => {
},
}
})
}
} catch {}
}
if (typeof issue_id_or_event !== 'string') {
setEvent(issue_id_or_event)
} else {
sub = ndk.subscribe(
{
ids: [issue_id],
limit: 100,
},
{
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(relays_to_use, ndk)
)
sub.on('event', (event: NDKEvent) => {
if (event.id == issue_id) setEvent(event)
})
sub.on('eose', () => {
@ -112,6 +123,7 @@ export const ensureIssueFull = (repo_a: string, issue_id: string) => { @@ -112,6 +123,7 @@ export const ensureIssueFull = (repo_a: string, issue_id: string) => {
return updated
})
})
}
sub_replies = ndk.subscribe(
{

43
src/lib/stores/Proposal.ts

@ -28,7 +28,14 @@ let sub_replies: NDKSubscription @@ -28,7 +28,14 @@ let sub_replies: NDKSubscription
const sub_replies_to_replies: NDKSubscription[] = []
export const ensureProposalFull = (repo_a: string, proposal_id: string) => {
export const ensureProposalFull = (
repo_a: string,
proposal_id_or_event: string | NDKEvent
) => {
const proposal_id =
typeof proposal_id_or_event === 'string'
? proposal_id_or_event
: proposal_id_or_event.id
if (selected_proposal_id == proposal_id) return
if (proposal_id == '') {
selected_proposal_full.set({ ...full_defaults })
@ -64,20 +71,8 @@ export const ensureProposalFull = (repo_a: string, proposal_id: string) => { @@ -64,20 +71,8 @@ export const ensureProposalFull = (repo_a: string, proposal_id: string) => {
? repo.relays
: [...base_relays].concat(repo ? repo.relays : [])
sub = ndk.subscribe(
{
ids: [proposal_id],
limit: 100,
},
{
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(relays_to_use, ndk)
)
sub.on('event', (event: NDKEvent) => {
const setEvent = (event: NDKEvent) => {
try {
if (event.id == proposal_id) {
selected_proposal_full.update((full) => {
return {
...full,
@ -98,8 +93,25 @@ export const ensureProposalFull = (repo_a: string, proposal_id: string) => { @@ -98,8 +93,25 @@ export const ensureProposalFull = (repo_a: string, proposal_id: string) => {
},
}
})
}
} catch {}
}
if (typeof proposal_id_or_event !== 'string') {
setEvent(proposal_id_or_event)
} else {
sub = ndk.subscribe(
{
ids: [proposal_id],
limit: 100,
},
{
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(relays_to_use, ndk)
)
sub.on('event', (event: NDKEvent) => {
if (event.id == proposal_id) setEvent(event)
})
sub.on('eose', () => {
@ -117,6 +129,7 @@ export const ensureProposalFull = (repo_a: string, proposal_id: string) => { @@ -117,6 +129,7 @@ export const ensureProposalFull = (repo_a: string, proposal_id: string) => {
return updated
})
})
}
sub_replies = ndk.subscribe(
{

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

@ -45,10 +45,10 @@ @@ -45,10 +45,10 @@
)
} else {
if (event.kind === issue_kind) {
ensureIssueFull(a, id)
ensureIssueFull(a, event)
goto(`/r/${aToNaddr(a)}/issues/${nip19.noteEncode(id)}`)
} else if (event.kind === patch_kind) {
ensureProposalFull(a, id)
ensureProposalFull(a, event)
goto(`/r/${aToNaddr(a)}/proposals/${nip19.noteEncode(id)}`)
} else {
showError()

Loading…
Cancel
Save