Get rid of loadOne since it only works for id-based filters, not addresses
This commit is contained in:
@@ -4,7 +4,7 @@ import {indexBy, type Maybe, now} from '@welshman/lib'
|
|||||||
import {getIdFilters} from '@welshman/util'
|
import {getIdFilters} from '@welshman/util'
|
||||||
import type {TrustedEvent} from '@welshman/util'
|
import type {TrustedEvent} from '@welshman/util'
|
||||||
import {withGetter, deriveEvents} from '@welshman/store'
|
import {withGetter, deriveEvents} from '@welshman/store'
|
||||||
import {repository, loadOne} from './core'
|
import {repository, load} from './core'
|
||||||
import {getFreshness, setFreshness} from './freshness'
|
import {getFreshness, setFreshness} from './freshness'
|
||||||
|
|
||||||
export const collection = <T, LoadArgs extends any[]>({
|
export const collection = <T, LoadArgs extends any[]>({
|
||||||
@@ -71,7 +71,7 @@ export const deriveEvent = (idOrAddress: string, request: Partial<SubscribeReque
|
|||||||
deriveEvents(repository, {filters, includeDeleted: true}),
|
deriveEvents(repository, {filters, includeDeleted: true}),
|
||||||
(events: TrustedEvent[]) => {
|
(events: TrustedEvent[]) => {
|
||||||
if (!attempted && events.length === 0) {
|
if (!attempted && events.length === 0) {
|
||||||
loadOne({...request, filters})
|
load({...request, filters})
|
||||||
attempted = true
|
attempted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,17 +79,3 @@ export const load = (request: PartialSubscribeRequest) =>
|
|||||||
sub.emitter.on("event", (url: string, e: TrustedEvent) => events.push(e))
|
sub.emitter.on("event", (url: string, e: TrustedEvent) => events.push(e))
|
||||||
sub.emitter.on("complete", () => resolve(events))
|
sub.emitter.on("complete", () => resolve(events))
|
||||||
})
|
})
|
||||||
|
|
||||||
export const loadOne = (request: PartialSubscribeRequest) =>
|
|
||||||
new Promise<TrustedEvent | null>(resolve => {
|
|
||||||
const sub = subscribe({closeOnEose: true, timeout: AppContext.requestTimeout, ...request})
|
|
||||||
|
|
||||||
sub.emitter.on("event", (url: string, event: TrustedEvent) => {
|
|
||||||
resolve(event)
|
|
||||||
sub.close()
|
|
||||||
})
|
|
||||||
|
|
||||||
sub.emitter.on("complete", () => {
|
|
||||||
resolve(null)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {FOLLOWS, asDecryptedEvent, readList} from '@welshman/util'
|
|||||||
import {type TrustedEvent, type PublishedList} from '@welshman/util'
|
import {type TrustedEvent, type PublishedList} from '@welshman/util'
|
||||||
import {type SubscribeRequest} from "@welshman/net"
|
import {type SubscribeRequest} from "@welshman/net"
|
||||||
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
||||||
import {repository, loadOne} from './core'
|
import {repository, load} from './core'
|
||||||
import {collection} from './collection'
|
import {collection} from './collection'
|
||||||
import {ensurePlaintext} from './plaintext'
|
import {ensurePlaintext} from './plaintext'
|
||||||
|
|
||||||
@@ -28,5 +28,5 @@ export const {
|
|||||||
store: follows,
|
store: follows,
|
||||||
getKey: follows => follows.event.pubkey,
|
getKey: follows => follows.event.pubkey,
|
||||||
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||||
loadOne({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}),
|
load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {MUTES, asDecryptedEvent, readList} from '@welshman/util'
|
|||||||
import {type TrustedEvent, type PublishedList} from '@welshman/util'
|
import {type TrustedEvent, type PublishedList} from '@welshman/util'
|
||||||
import {type SubscribeRequest} from "@welshman/net"
|
import {type SubscribeRequest} from "@welshman/net"
|
||||||
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
||||||
import {repository, loadOne} from './core'
|
import {repository, load} from './core'
|
||||||
import {collection} from './collection'
|
import {collection} from './collection'
|
||||||
import {ensurePlaintext} from './plaintext'
|
import {ensurePlaintext} from './plaintext'
|
||||||
|
|
||||||
@@ -28,5 +28,5 @@ export const {
|
|||||||
store: mutes,
|
store: mutes,
|
||||||
getKey: mute => mute.event.pubkey,
|
getKey: mute => mute.event.pubkey,
|
||||||
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||||
loadOne({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}),
|
load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {readProfile, displayProfile, displayPubkey, PROFILE} from '@welshman/uti
|
|||||||
import {type SubscribeRequest} from "@welshman/net"
|
import {type SubscribeRequest} from "@welshman/net"
|
||||||
import {type PublishedProfile} from "@welshman/util"
|
import {type PublishedProfile} from "@welshman/util"
|
||||||
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
||||||
import {repository, loadOne} from './core'
|
import {repository, load} from './core'
|
||||||
import {createSearch} from './util'
|
import {createSearch} from './util'
|
||||||
import {collection} from './collection'
|
import {collection} from './collection'
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ export const {
|
|||||||
store: profiles,
|
store: profiles,
|
||||||
getKey: profile => profile.event.pubkey,
|
getKey: profile => profile.event.pubkey,
|
||||||
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||||
loadOne({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}),
|
load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const profileSearch = derived(profiles, $profiles =>
|
export const profileSearch = derived(profiles, $profiles =>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {INBOX_RELAYS, RELAYS, getRelayTags, normalizeRelayUrl, type TrustedEvent} from '@welshman/util'
|
import {INBOX_RELAYS, RELAYS, getRelayTags, normalizeRelayUrl, type TrustedEvent} from '@welshman/util'
|
||||||
import {type SubscribeRequest} from "@welshman/net"
|
import {type SubscribeRequest} from "@welshman/net"
|
||||||
import {deriveEvents, withGetter} from '@welshman/store'
|
import {deriveEvents, withGetter} from '@welshman/store'
|
||||||
import {loadOne, repository} from './core'
|
import {load, repository} from './core'
|
||||||
import {collection} from './collection'
|
import {collection} from './collection'
|
||||||
|
|
||||||
export const getRelayUrls = (event?: TrustedEvent): string[] =>
|
export const getRelayUrls = (event?: TrustedEvent): string[] =>
|
||||||
@@ -29,7 +29,7 @@ export const {
|
|||||||
store: relaySelections,
|
store: relaySelections,
|
||||||
getKey: relaySelections => relaySelections.pubkey,
|
getKey: relaySelections => relaySelections.pubkey,
|
||||||
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||||
loadOne({...request, filters: [{kinds: [RELAYS], authors: [pubkey]}]}),
|
load({...request, filters: [{kinds: [RELAYS], authors: [pubkey]}]}),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const inboxRelaySelections = withGetter(deriveEvents(repository, {filters: [{kinds: [RELAYS]}]}))
|
export const inboxRelaySelections = withGetter(deriveEvents(repository, {filters: [{kinds: [RELAYS]}]}))
|
||||||
@@ -43,5 +43,5 @@ export const {
|
|||||||
store: inboxRelaySelections,
|
store: inboxRelaySelections,
|
||||||
getKey: inboxRelaySelections => inboxRelaySelections.pubkey,
|
getKey: inboxRelaySelections => inboxRelaySelections.pubkey,
|
||||||
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||||
loadOne({...request, filters: [{kinds: [INBOX_RELAYS], authors: [pubkey]}]}),
|
load({...request, filters: [{kinds: [INBOX_RELAYS], authors: [pubkey]}]}),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user