diff --git a/packages/app/src/relayLists.ts b/packages/app/src/relayLists.ts index 7f9f86b..f684852 100644 --- a/packages/app/src/relayLists.ts +++ b/packages/app/src/relayLists.ts @@ -8,6 +8,7 @@ import { getRelaysFromList, RelayMode, Filter, + isPlainReplaceableKind, } from "@welshman/util" import { deriveItemsByKey, @@ -55,7 +56,7 @@ export const deriveRelayList = makeDeriveItem(relayListsByPubkey, loadRelayList) // Outbox loader export const loadUsingOutbox = async (kind: number, pubkey: string, filter: Filter = {}) => { - const filters = [{...filter, kinds: [kind], authors: [pubkey], limit: 1}] + const filters = [{...filter, kinds: [kind], authors: [pubkey]}] const writeRelays = getRelaysFromList(await loadRelayList(pubkey), RelayMode.Write) const allRelays = Router.get() .FromRelays(writeRelays) @@ -63,6 +64,10 @@ export const loadUsingOutbox = async (kind: number, pubkey: string, filter: Filt .limit(8) .getUrls() + if (isPlainReplaceableKind(kind)) { + filters[0].limit = 1 + } + for (const relays of chunk(2, allRelays)) { const events = await load({filters, relays}) @@ -73,7 +78,7 @@ export const loadUsingOutbox = async (kind: number, pubkey: string, filter: Filt } export const makeOutboxLoader = - (kind: number, filter: Filter = {}) => + (kind: number, filter: Filter = {}, limit = 1) => async (pubkey: string, relayHints: string[] = []) => { const filters = [{...filter, kinds: [kind], authors: [pubkey]}] const relays = Router.get().FromRelays(relayHints).getUrls() diff --git a/packages/feeds/src/request.ts b/packages/feeds/src/request.ts index b4b3648..ba04b64 100644 --- a/packages/feeds/src/request.ts +++ b/packages/feeds/src/request.ts @@ -64,7 +64,7 @@ export const requestPage = async ({ onEvent, relays, filters, - threshold: 0.8, + threshold: 0.5, autoClose, }), ), diff --git a/packages/lib/src/Tools.ts b/packages/lib/src/Tools.ts index 9396ae2..15900fd 100644 --- a/packages/lib/src/Tools.ts +++ b/packages/lib/src/Tools.ts @@ -57,6 +57,26 @@ export const always = */ export const not = (x: any, ...args: unknown[]) => !x +/** + * Bind function + * @param f - Function to bind + * @returns bound function + */ +export const bind = any>(f: F, ...args: Parameters) => + f.bind(null, ...args) + +/** + * Runs the provided function on the given value and returns the value + * @param f - Function to call + * @returns tapped function + */ +export const tap = + unknown>(f: F) => + (x: T) => { + f(x) + return x + } + /** * Deep equality comparison * @param a - First value