|
|
|
@ -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 { writable, type Writable } from 'svelte/store' |
|
|
|
import { base_relays, ndk } from './ndk' |
|
|
|
import { base_relays, ndk } from './ndk' |
|
|
|
import { type IssueFull, full_defaults } from '$lib/components/issues/type' |
|
|
|
import { type IssueFull, full_defaults } from '$lib/components/issues/type' |
|
|
|
@ -28,7 +28,14 @@ let sub_replies: NDKSubscription |
|
|
|
|
|
|
|
|
|
|
|
const sub_replies_to_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 (selected_issue_id == issue_id) return |
|
|
|
if (issue_id == '') { |
|
|
|
if (issue_id == '') { |
|
|
|
selected_issue_full.set({ ...full_defaults }) |
|
|
|
selected_issue_full.set({ ...full_defaults }) |
|
|
|
@ -64,54 +71,59 @@ export const ensureIssueFull = (repo_a: string, issue_id: string) => { |
|
|
|
? repo.relays |
|
|
|
? repo.relays |
|
|
|
: [...base_relays].concat(repo ? repo.relays : []) |
|
|
|
: [...base_relays].concat(repo ? repo.relays : []) |
|
|
|
|
|
|
|
|
|
|
|
sub = ndk.subscribe( |
|
|
|
const setEvent = (event: NDKEvent) => { |
|
|
|
{ |
|
|
|
|
|
|
|
ids: [issue_id], |
|
|
|
|
|
|
|
limit: 100, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
closeOnEose: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
NDKRelaySet.fromRelayUrls(relays_to_use, ndk) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub.on('event', (event: NDKEvent) => { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
if (event.id == issue_id) { |
|
|
|
selected_issue_full.update((full) => { |
|
|
|
selected_issue_full.update((full) => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
...full, |
|
|
|
...full, |
|
|
|
issue_event: event, |
|
|
|
issue_event: event, |
|
|
|
summary: { |
|
|
|
summary: { |
|
|
|
...full.summary, |
|
|
|
...full.summary, |
|
|
|
title: extractIssueTitle(event.content), |
|
|
|
title: extractIssueTitle(event.content), |
|
|
|
descritpion: extractIssueDescription(event.content), |
|
|
|
descritpion: extractIssueDescription(event.content), |
|
|
|
created_at: event.created_at, |
|
|
|
created_at: event.created_at, |
|
|
|
comments: 0, |
|
|
|
comments: 0, |
|
|
|
author: event.pubkey, |
|
|
|
author: event.pubkey, |
|
|
|
loading: false, |
|
|
|
loading: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch {} |
|
|
|
} 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', () => { |
|
|
|
sub.on('eose', () => { |
|
|
|
selected_issue_full.update((full) => { |
|
|
|
selected_issue_full.update((full) => { |
|
|
|
const updated = { |
|
|
|
const updated = { |
|
|
|
...full, |
|
|
|
...full, |
|
|
|
summary: { |
|
|
|
summary: { |
|
|
|
...full.summary, |
|
|
|
...full.summary, |
|
|
|
loading: false, |
|
|
|
loading: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
if (full.loading === false) { |
|
|
|
if (full.loading === false) { |
|
|
|
r({ ...updated }) |
|
|
|
r({ ...updated }) |
|
|
|
} |
|
|
|
} |
|
|
|
return updated |
|
|
|
return updated |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sub_replies = ndk.subscribe( |
|
|
|
sub_replies = ndk.subscribe( |
|
|
|
{ |
|
|
|
{ |
|
|
|
|