|
|
|
@ -1,15 +1,15 @@ |
|
|
|
import type { NDKEvent } from "@nostr-dev-kit/ndk"; |
|
|
|
import { NDKRelaySet, type NDKEvent } from "@nostr-dev-kit/ndk"; |
|
|
|
import { writable, type Unsubscriber, type Writable } from "svelte/store" |
|
|
|
import { writable, type Unsubscriber, type Writable } from "svelte/store" |
|
|
|
import { ndk } from "./ndk"; |
|
|
|
import { ndk } from "./ndk"; |
|
|
|
import type { User } from "$lib/components/users/type"; |
|
|
|
import type { User } from "$lib/components/users/type"; |
|
|
|
import { ensureUser } from "./users"; |
|
|
|
import { ensureUser } from "./users"; |
|
|
|
import { type PRFull, full_defaults, isPRStatus, type PRStatus } from "$lib/components/prs/type"; |
|
|
|
import { type PRFull, full_defaults, isPRStatus, type PRStatus } from "$lib/components/prs/type"; |
|
|
|
import { pr_kind, pr_status_kind } from "$lib/kinds"; |
|
|
|
import { pr_kind, pr_status_kind } from "$lib/kinds"; |
|
|
|
|
|
|
|
import { ensureSelectedRepo } from "./repo"; |
|
|
|
|
|
|
|
|
|
|
|
export let selected_pr_full: Writable<PRFull> = writable({ ...full_defaults }); |
|
|
|
export let selected_pr_full: Writable<PRFull> = writable({ ...full_defaults }); |
|
|
|
|
|
|
|
|
|
|
|
let selected_repo_id: string = ""; |
|
|
|
let selected_pr_repo_id: string = ""; |
|
|
|
let selected_pr_id: string = ""; |
|
|
|
let selected_pr_id: string = ""; |
|
|
|
let pr_summary_author_unsubsriber: Unsubscriber | undefined; |
|
|
|
let pr_summary_author_unsubsriber: Unsubscriber | undefined; |
|
|
|
|
|
|
|
|
|
|
|
@ -21,124 +21,144 @@ export let ensurePRFull = (repo_id: string, pr_id: string) => { |
|
|
|
if (selected_pr_id == pr_id) return; |
|
|
|
if (selected_pr_id == pr_id) return; |
|
|
|
if (pr_id == "") { |
|
|
|
if (pr_id == "") { |
|
|
|
selected_pr_full.set({ ...full_defaults }); |
|
|
|
selected_pr_full.set({ ...full_defaults }); |
|
|
|
|
|
|
|
selected_pr_replies.set([]); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
selected_repo_id = repo_id; |
|
|
|
selected_pr_repo_id = repo_id; |
|
|
|
selected_pr_id = pr_id; |
|
|
|
selected_pr_id = pr_id; |
|
|
|
selected_pr_status_date = 0; |
|
|
|
selected_pr_status_date = 0; |
|
|
|
selected_pr_replies.set([]); |
|
|
|
selected_pr_replies.set([]); |
|
|
|
|
|
|
|
|
|
|
|
selected_pr_full.update(full => { |
|
|
|
selected_pr_full.set({ |
|
|
|
return { |
|
|
|
...full_defaults, |
|
|
|
...full, |
|
|
|
summary: { |
|
|
|
summary: { |
|
|
|
...full_defaults.summary, |
|
|
|
...full.summary, |
|
|
|
id: pr_id, |
|
|
|
id: pr_id, |
|
|
|
repo_id: repo_id, |
|
|
|
repo_id: repo_id, |
|
|
|
|
|
|
|
loading: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
loading: true, |
|
|
|
loading: true, |
|
|
|
}; |
|
|
|
}, |
|
|
|
|
|
|
|
loading: true, |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (pr_summary_author_unsubsriber) pr_summary_author_unsubsriber(); |
|
|
|
if (pr_summary_author_unsubsriber) pr_summary_author_unsubsriber(); |
|
|
|
pr_summary_author_unsubsriber = undefined; |
|
|
|
pr_summary_author_unsubsriber = undefined; |
|
|
|
|
|
|
|
|
|
|
|
let sub = ndk.subscribe({ |
|
|
|
new Promise(async (r) => { |
|
|
|
ids: [pr_id], |
|
|
|
let repo = await ensureSelectedRepo(repo_id); |
|
|
|
limit: 1, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub.on("event", (event: NDKEvent) => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (event.kind == pr_kind |
|
|
|
|
|
|
|
&& event.getMatchingTags("r").find(t => t[1] === `r-${repo_id}`) |
|
|
|
|
|
|
|
&& event.id == pr_id |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selected_pr_full.update(full => { |
|
|
|
let sub = ndk.subscribe( |
|
|
|
return { |
|
|
|
{ |
|
|
|
...full, |
|
|
|
ids: [pr_id], |
|
|
|
pr_event: event, |
|
|
|
kinds: [pr_kind], |
|
|
|
summary: { |
|
|
|
'#r': [`r-${repo_id}`], |
|
|
|
...full.summary, |
|
|
|
limit: 50, |
|
|
|
title: event.tagValue("name") || "", |
|
|
|
}, |
|
|
|
descritpion: event.tagValue("description") || "", |
|
|
|
{}, |
|
|
|
created_at: event.created_at, |
|
|
|
NDKRelaySet.fromRelayUrls(repo.relays, ndk), |
|
|
|
comments: 0, |
|
|
|
); |
|
|
|
author: { |
|
|
|
|
|
|
|
hexpubkey: event.pubkey, |
|
|
|
sub.on("event", (event: NDKEvent) => { |
|
|
|
loading: true, |
|
|
|
try { |
|
|
|
npub: "", |
|
|
|
if (event.kind == pr_kind |
|
|
|
}, |
|
|
|
&& event.getMatchingTags("r").find(t => t[1] === `r-${repo_id}`) |
|
|
|
loading: false, |
|
|
|
&& event.id == pr_id |
|
|
|
} |
|
|
|
) { |
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pr_summary_author_unsubsriber = ensureUser(event.pubkey).subscribe((u: User) => { |
|
|
|
|
|
|
|
selected_pr_full.update(full => { |
|
|
|
selected_pr_full.update(full => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
...full, |
|
|
|
...full, |
|
|
|
|
|
|
|
pr_event: event, |
|
|
|
summary: { |
|
|
|
summary: { |
|
|
|
...full.summary, |
|
|
|
...full.summary, |
|
|
|
author: event.pubkey == u.hexpubkey ? u : full.summary.author, |
|
|
|
title: event.tagValue("name") || "", |
|
|
|
|
|
|
|
descritpion: event.tagValue("description") || "", |
|
|
|
|
|
|
|
created_at: event.created_at, |
|
|
|
|
|
|
|
comments: 0, |
|
|
|
|
|
|
|
author: { |
|
|
|
|
|
|
|
hexpubkey: event.pubkey, |
|
|
|
|
|
|
|
loading: true, |
|
|
|
|
|
|
|
npub: "", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
loading: false, |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch { } |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub.on("eose", () => { |
|
|
|
pr_summary_author_unsubsriber = ensureUser(event.pubkey).subscribe((u: User) => { |
|
|
|
selected_pr_full.update(full => { |
|
|
|
selected_pr_full.update(full => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
...full, |
|
|
|
...full, |
|
|
|
summary: { |
|
|
|
summary: { |
|
|
|
...full.summary, |
|
|
|
...full.summary, |
|
|
|
loading: false, |
|
|
|
author: event.pubkey == u.hexpubkey ? u : full.summary.author, |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch { } |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let sub_replies = ndk.subscribe({ |
|
|
|
sub.on("eose", () => { |
|
|
|
"#e": [pr_id], |
|
|
|
selected_pr_full.update(full => { |
|
|
|
}); |
|
|
|
let updated = { |
|
|
|
|
|
|
|
...full, |
|
|
|
|
|
|
|
summary: { |
|
|
|
|
|
|
|
...full.summary, |
|
|
|
|
|
|
|
loading: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if (full.loading === false) { |
|
|
|
|
|
|
|
r({ ...updated }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return updated; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let sub_replies = ndk.subscribe( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"#e": [pr_id], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{}, |
|
|
|
|
|
|
|
NDKRelaySet.fromRelayUrls(repo.relays, ndk), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub_replies.on("event", (event: NDKEvent) => { |
|
|
|
|
|
|
|
if (event.kind == pr_status_kind |
|
|
|
|
|
|
|
&& event.created_at && selected_pr_status_date < event.created_at |
|
|
|
|
|
|
|
&& event.getMatchingTags("t").length === 1 |
|
|
|
|
|
|
|
&& event.getMatchingTags("t")[0].length > 1 |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
let potential_status = event.getMatchingTags("t")[0][1]; |
|
|
|
|
|
|
|
|
|
|
|
sub_replies.on("event", (event: NDKEvent) => { |
|
|
|
if (isPRStatus(potential_status)) { |
|
|
|
if (event.kind == pr_status_kind |
|
|
|
selected_pr_status_date = event.created_at; |
|
|
|
&& event.created_at && selected_pr_status_date < event.created_at |
|
|
|
selected_pr_full.update(full => { |
|
|
|
&& event.getMatchingTags("t").length === 1 |
|
|
|
return { |
|
|
|
&& event.getMatchingTags("t")[0].length > 1 |
|
|
|
...full, |
|
|
|
) { |
|
|
|
status: potential_status as PRStatus, |
|
|
|
let potential_status = event.getMatchingTags("t")[0][1]; |
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
if (isPRStatus(potential_status)) { |
|
|
|
} |
|
|
|
selected_pr_status_date = event.created_at; |
|
|
|
|
|
|
|
selected_pr_full.update(full => { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
...full, |
|
|
|
|
|
|
|
status: potential_status as PRStatus, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
selected_pr_replies.update(replies => { |
|
|
|
selected_pr_replies.update(replies => { |
|
|
|
return [ |
|
|
|
return [ |
|
|
|
...replies, |
|
|
|
...replies, |
|
|
|
event, |
|
|
|
event, |
|
|
|
]; |
|
|
|
]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub.on("eose", () => { |
|
|
|
sub.on("eose", () => { |
|
|
|
selected_pr_full.update(full => { |
|
|
|
selected_pr_full.update(full => { |
|
|
|
return { |
|
|
|
let updated = { |
|
|
|
...full, |
|
|
|
...full, |
|
|
|
loading: false, |
|
|
|
loading: false, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
if (full.summary.loading === false) { |
|
|
|
|
|
|
|
r({ ...updated }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return updated; |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|