diff --git a/packages/app/src/follows.ts b/packages/app/src/follows.ts index 15028f8..4549d7f 100644 --- a/packages/app/src/follows.ts +++ b/packages/app/src/follows.ts @@ -5,6 +5,7 @@ import {deriveEventsMapped, withGetter} from '@welshman/store' import {repository, load} from './core' import {collection} from './collection' import {ensurePlaintext} from './plaintext' +import {loadRelaySelections} from './relaySelections' export const follows = withGetter( deriveEventsMapped(repository, { @@ -27,6 +28,8 @@ export const { name: "follows", store: follows, getKey: follows => follows.event.pubkey, - load: (pubkey: string, request: Partial = {}) => - load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}), + load: async (pubkey: string, request: Partial = {}) => { + await loadRelaySelections(pubkey, request) + await load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}) + }, }) diff --git a/packages/app/src/handles.ts b/packages/app/src/handles.ts index 461796d..cbe6882 100644 --- a/packages/app/src/handles.ts +++ b/packages/app/src/handles.ts @@ -1,7 +1,7 @@ import {writable, derived} from 'svelte/store' import {withGetter} from '@welshman/store' import {type SubscribeRequest} from "@welshman/net" -import {ctx, fetchJson, uniq, batcher, postJson, last} from '@welshman/lib' +import {ctx, tryCatch, fetchJson, uniq, batcher, postJson, last} from '@welshman/lib' import {collection} from './collection' import {deriveProfile} from './profiles' @@ -49,14 +49,14 @@ export const fetchHandles = async (nip05s: string[]) => { // Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly if (base) { - const res: any = await postJson(`${base}/handle/info`, {handles: nip05s}) + const res: any = await tryCatch(async () => await postJson(`${base}/handle/info`, {handles: nip05s})) for (const {handle: nip05, info} of res?.data || []) { handlesByNip05.set(nip05, info) } } else { const results = await Promise.all( - nip05s.map(async nip05 => ({nip05, info: await queryProfile(nip05)})) + nip05s.map(async nip05 => ({nip05, info: await tryCatch(async () => await queryProfile(nip05))})) ) for (const {nip05, info} of results) { diff --git a/packages/app/src/mutes.ts b/packages/app/src/mutes.ts index 61e353b..ed0cb88 100644 --- a/packages/app/src/mutes.ts +++ b/packages/app/src/mutes.ts @@ -5,6 +5,7 @@ import {deriveEventsMapped, withGetter} from '@welshman/store' import {repository, load} from './core' import {collection} from './collection' import {ensurePlaintext} from './plaintext' +import {loadRelaySelections} from './relaySelections' export const mutes = withGetter( deriveEventsMapped(repository, { @@ -27,6 +28,8 @@ export const { name: "mutes", store: mutes, getKey: mute => mute.event.pubkey, - load: (pubkey: string, request: Partial = {}) => - load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}), + load: async (pubkey: string, request: Partial = {}) => { + await loadRelaySelections(pubkey, request) + await load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}) + }, }) diff --git a/packages/app/src/profiles.ts b/packages/app/src/profiles.ts index 26ed448..97648e6 100644 --- a/packages/app/src/profiles.ts +++ b/packages/app/src/profiles.ts @@ -6,6 +6,7 @@ import {deriveEventsMapped, withGetter} from '@welshman/store' import {repository, load} from './core' import {createSearch} from './util' import {collection} from './collection' +import {loadRelaySelections} from './relaySelections' export const profiles = withGetter( deriveEventsMapped(repository, { @@ -23,8 +24,10 @@ export const { name: "profiles", store: profiles, getKey: profile => profile.event.pubkey, - load: (pubkey: string, request: Partial = {}) => - load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}), + load: async (pubkey: string, request: Partial = {}) => { + await loadRelaySelections(pubkey, request) + await load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}) + }, }) export const profileSearch = derived(profiles, $profiles => diff --git a/packages/app/src/router.ts b/packages/app/src/router.ts index 10052f2..799a1e9 100644 --- a/packages/app/src/router.ts +++ b/packages/app/src/router.ts @@ -533,7 +533,8 @@ export const getFilterSelectionsForIndexedKinds = (state: FilterSelectionRuleSta } export const getFilterSelectionsForAuthors = (state: FilterSelectionRuleState) => { - if (!state.filter.authors) return false + // If we have a ton of authors, just use our indexers + if (!state.filter.authors || state.filter.authors.length > 30) return false const id = getFilterId(state.filter) const scenario = ctx.app.router.FromPubkeys(state.filter.authors!).update(assoc('value', id)) diff --git a/packages/app/src/zappers.ts b/packages/app/src/zappers.ts index fc33bf2..2ab61ef 100644 --- a/packages/app/src/zappers.ts +++ b/packages/app/src/zappers.ts @@ -15,7 +15,7 @@ export const fetchZappers = async (lnurls: string[]) => { // Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly if (base) { const hexUrls = lnurls.map(lnurl => tryCatch(() => bech32ToHex(lnurl))).filter(identity) - const res: any = await postJson(`${base}/zapper/info`, {lnurls: hexUrls}) + const res: any = await tryCatch(async () => await postJson(`${base}/zapper/info`, {lnurls: hexUrls})) for (const {lnurl, info} of res?.data || []) { tryCatch(() => zappersByLnurl.set(hexToBech32("lnurl", lnurl), info)) @@ -24,7 +24,7 @@ export const fetchZappers = async (lnurls: string[]) => { const results = await Promise.all( lnurls.map(async lnurl => { const hexUrl = tryCatch(() => bech32ToHex(lnurl)) - const info = hexUrl ? await fetchJson(hexUrl) : undefined + const info = hexUrl ? await tryCatch(async () => await fetchJson(hexUrl)) : undefined return {lnurl, hexUrl, info} }) diff --git a/packages/net/src/Subscribe.ts b/packages/net/src/Subscribe.ts index d3f2ea3..9394539 100644 --- a/packages/net/src/Subscribe.ts +++ b/packages/net/src/Subscribe.ts @@ -189,7 +189,7 @@ export const optimizeSubscriptions = (subs: Subscription[]) => { // This is sub-optimal, but because we're outsourcing filter/relay optimization // we can't make any assumptions about which caller subscriptions have completed // at any given time. - if (subIds.size === group.length) { + if (subIds.size === mergedSubs.length) { for (const sub of group) { sub.emitter.emit(type, ...args) }