Browse Source

feat: keep listening for repo and pr events

instead of closing connection on eose
master
DanConwayDev 2 years ago
parent
commit
1547662205
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 20
      src/lib/stores/PR.ts
  2. 12
      src/lib/stores/PRs.ts
  3. 11
      src/lib/stores/repo.ts

20
src/lib/stores/PR.ts

@ -1,4 +1,4 @@
import { NDKRelaySet, type NDKEvent } from "@nostr-dev-kit/ndk"; import { NDKRelaySet, type NDKEvent, NDKSubscription } 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";
@ -17,6 +17,10 @@ export let selected_pr_replies: Writable<NDKEvent[]> = writable([]);
let selected_pr_status_date = 0; let selected_pr_status_date = 0;
let sub: NDKSubscription;
let sub_replies: NDKSubscription;
export let ensurePRFull = (repo_id: string, pr_id: string) => { 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 == "") {
@ -46,14 +50,17 @@ export let ensurePRFull = (repo_id: string, pr_id: string) => {
new Promise(async (r) => { new Promise(async (r) => {
let repo = await ensureSelectedRepo(repo_id); let repo = await ensureSelectedRepo(repo_id);
let sub = ndk.subscribe( if (sub) sub.stop();
sub = ndk.subscribe(
{ {
ids: [pr_id], ids: [pr_id],
kinds: [pr_kind], kinds: [pr_kind],
'#r': [`r-${repo_id}`], '#r': [`r-${repo_id}`],
limit: 50, limit: 50,
}, },
{}, {
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(repo.relays, ndk), NDKRelaySet.fromRelayUrls(repo.relays, ndk),
); );
@ -114,11 +121,14 @@ export let ensurePRFull = (repo_id: string, pr_id: string) => {
}); });
}); });
let sub_replies = ndk.subscribe( if (sub_replies) sub_replies.stop();
sub_replies = ndk.subscribe(
{ {
"#e": [pr_id], "#e": [pr_id],
}, },
{}, {
closeOnEose: false
},
NDKRelaySet.fromRelayUrls(repo.relays, ndk), NDKRelaySet.fromRelayUrls(repo.relays, ndk),
); );

12
src/lib/stores/PRs.ts

@ -1,4 +1,4 @@
import { NDKRelaySet, type NDKEvent } from "@nostr-dev-kit/ndk"; import { NDKRelaySet, type NDKEvent, NDKSubscription } 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 { summary_defaults } from "$lib/components/prs/type"; import { summary_defaults } from "$lib/components/prs/type";
@ -19,6 +19,8 @@ let selected_repo_id: string = "";
let authors_unsubscribers: Unsubscriber[] = []; let authors_unsubscribers: Unsubscriber[] = [];
let sub: NDKSubscription;
export let ensurePRSummaries = async (repo_id: string) => { export let ensurePRSummaries = async (repo_id: string) => {
if (selected_repo_id == repo_id) return; if (selected_repo_id == repo_id) return;
if (repo_id == "") return pr_summaries.set({ if (repo_id == "") return pr_summaries.set({
@ -41,13 +43,17 @@ export let ensurePRSummaries = async (repo_id: string) => {
authors_unsubscribers.forEach(u => u()); authors_unsubscribers.forEach(u => u());
authors_unsubscribers = []; authors_unsubscribers = [];
let sub = ndk.subscribe( if (sub) sub.stop();
sub = ndk.subscribe(
{ {
kinds: [pr_kind], kinds: [pr_kind],
'#r': [`r-${repo_id}`], '#r': [`r-${repo_id}`],
limit: 50, limit: 50,
}, },
{}, {
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(repo.relays, ndk), NDKRelaySet.fromRelayUrls(repo.relays, ndk),
); );

11
src/lib/stores/repo.ts

@ -1,4 +1,4 @@
import { NDKRelaySet } from "@nostr-dev-kit/ndk"; import { NDKRelaySet, NDKSubscription } from "@nostr-dev-kit/ndk";
import { writable, type Unsubscriber, type Writable, get } from "svelte/store" import { writable, type Unsubscriber, type Writable, get } from "svelte/store"
import { base_relays, ndk } from "./ndk"; import { base_relays, ndk } from "./ndk";
import type { Repo } from "$lib/components/repo/type"; import type { Repo } from "$lib/components/repo/type";
@ -12,6 +12,7 @@ let selected_repo_id: string = "";
let maintainers_unsubscribers: Unsubscriber[] = []; let maintainers_unsubscribers: Unsubscriber[] = [];
let sub: NDKSubscription;
export let ensureSelectedRepo = async (repo_id: string): Promise<Repo> => { export let ensureSelectedRepo = async (repo_id: string): Promise<Repo> => {
if (selected_repo_id == repo_id) { if (selected_repo_id == repo_id) {
return new Promise(r => { return new Promise(r => {
@ -27,13 +28,17 @@ export let ensureSelectedRepo = async (repo_id: string): Promise<Repo> => {
}) })
} }
selected_repo_id = repo_id; selected_repo_id = repo_id;
let sub = ndk.subscribe(
if (sub) sub.stop();
sub = ndk.subscribe(
{ {
kinds: [repo_kind], kinds: [repo_kind],
'#d': [repo_id], '#d': [repo_id],
limit: 1, limit: 1,
}, },
{}, {
closeOnEose: false,
},
NDKRelaySet.fromRelayUrls(base_relays, ndk), NDKRelaySet.fromRelayUrls(base_relays, ndk),
); );

Loading…
Cancel
Save