Skip to content

Commit

Permalink
Pass each relay's latest as its since
Browse files Browse the repository at this point in the history
  • Loading branch information
alopatindev committed Jul 7, 2024
1 parent e998c23 commit e49411d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"idb": "^7.1.1",
"light-bolt11-decoder": "^3.0.0",
"nano-markdown": "^1.2.2",
"nostr-tools": "^2.4.0",
"nostr-tools": "^2.7.0",
"solid-element": "^1.7.1",
"solid-js": "^1.8.5"
}
Expand Down
8 changes: 5 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { decode } from "nostr-tools/nip19";
import { finalizeEvent, getPublicKey } from "nostr-tools/pure";
import { Filter } from "nostr-tools/filter";
import { AggregateEvent, NoteEvent, eventToNoteEvent } from "./util/models.ts";
import { SubCloser } from "nostr-tools";
import { SubCloser } from "nostr-tools/pool";

const ZapThreads = (props: { [key: string]: string; }) => {
createComputed(() => {
Expand Down Expand Up @@ -211,12 +211,14 @@ const ZapThreads = (props: { [key: string]: string; }) => {

console.log('[zapthreads] subscribing to', _anchor.value);

const since = await getRelayLatestForFilter(_anchor, _relays);
const relayToSince = await getRelayLatestForFilter(_anchor);
const request = (url: string) => [url, [{ ..._filter, kinds, since: relayToSince[url] || 0 }]];

const newLikeIds = new Set<string>();
const newZaps: { [id: string]: string; } = {};

sub = pool.subscribeMany(_relays, [{ ..._filter, kinds, since }],
sub = pool.subscribeManyMap(
Object.fromEntries(_relays.map(request)),
{
onevent(e) {
if (e.kind === 1 || e.kind === 9802) {
Expand Down
1 change: 1 addition & 0 deletions src/util/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createMutable } from "solid-js/store";

// Global data (for now)
export const pool = new SimplePool();
pool.trackRelays = true;

export const store = createMutable<PreferencesStore>({
rootEventIds: [],
Expand Down
8 changes: 2 additions & 6 deletions src/util/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ export const updateProfiles = async (pubkeys: string[], relays: string[], profil
}
};

export const getRelayLatest = async (anchor: Anchor, relayNames: string[]) => {
export const getRelayLatest = async (anchor: Anchor) => {
const relaysForAnchor = await findAll('relays', anchor.value, { index: 'a' });
const relaysLatest = relaysForAnchor.filter(r => relayNames.includes(r.n)).map(t => t.l);

// TODO Do not use the common minimum, pass each relay's latest as its since
// (but we need to stop using this pool)
return relaysLatest.length > 0 ? Math.min(...relaysLatest) + 1 : 0;
return Object.fromEntries(relaysForAnchor.map(r => [r.n, r.l + 1]));
};

// Calculate and save latest created_at to be used as `since`
Expand Down

0 comments on commit e49411d

Please sign in to comment.