This commit is contained in:
Jon Staab
2025-04-09 11:35:09 -07:00
parent 5f3624b8f3
commit 728ad1fba0
37 changed files with 1039 additions and 2183 deletions
+23 -15
View File
@@ -1,17 +1,25 @@
import {get, derived} from 'svelte/store'
import {batch, fromPairs} from '@welshman/lib'
import {PROFILE, FOLLOWS, MUTES, RELAYS, INBOX_RELAYS, getPubkeyTagValues, getListTags} from '@welshman/util'
import {throttled, withGetter} from '@welshman/store'
import {RepositoryUpdate} from '@welshman/relay'
import {getAll, bulkPut, bulkDelete} from './storage.js'
import {relays} from './relays.js'
import {handles, onHandle} from './handles.js'
import {zappers, onZapper} from './zappers.js'
import {plaintext} from './plaintext.js'
import {freshness} from './freshness.js'
import {repository} from './core.js'
import {sessions} from './session.js'
import {userFollows} from './user.js'
import {derived} from "svelte/store"
import {batch, fromPairs} from "@welshman/lib"
import {
PROFILE,
FOLLOWS,
MUTES,
RELAYS,
INBOX_RELAYS,
getPubkeyTagValues,
getListTags,
} from "@welshman/util"
import {throttled, withGetter} from "@welshman/store"
import {RepositoryUpdate} from "@welshman/relay"
import {getAll, bulkPut, bulkDelete} from "./storage.js"
import {relays} from "./relays.js"
import {handles, onHandle} from "./handles.js"
import {zappers, onZapper} from "./zappers.js"
import {plaintext} from "./plaintext.js"
import {freshness} from "./freshness.js"
import {repository} from "./core.js"
import {sessions} from "./session.js"
import {userFollows} from "./user.js"
export const defaultStorageAdapters = {
relays: {
@@ -70,7 +78,7 @@ export const defaultStorageAdapters = {
init: async () => repository.load(await getAll("events")),
sync: () => {
const userFollowPubkeys = withGetter(
derived(userFollows, l => new Set(getPubkeyTagValues(getListTags(l))))
derived(userFollows, l => new Set(getPubkeyTagValues(getListTags(l)))),
)
const onUpdate = async ({added, removed}: RepositoryUpdate) => {
+3 -1
View File
@@ -33,7 +33,9 @@ export const requestDVM = async ({kind, onEvent, ...request}: DVMOpts) => {
const tags = request.tags || []
const $signer = signer.get() || new Nip01Signer(makeSecret())
const pubkey = await $signer.getPubkey()
const relays = request.relays || Router.get().FromPubkeys(getPubkeyTagValues(tags)).policy(addMinimalFallbacks).getUrls()
const relays =
request.relays ||
Router.get().FromPubkeys(getPubkeyTagValues(tags)).policy(addMinimalFallbacks).getUrls()
if (!tags.some(nthEq(0, "expiration"))) {
tags.push(["expiration", String(now() + 60)])
-2
View File
@@ -1,9 +1,7 @@
import {FOLLOWS, asDecryptedEvent, readList} from "@welshman/util"
import {TrustedEvent, PublishedList} from "@welshman/util"
import {MultiRequestOptions, load} from "@welshman/net"
import {deriveEventsMapped} from "@welshman/store"
import {repository} from "./core.js"
import {Router} from "./router.js"
import {collection} from "./collection.js"
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
-1
View File
@@ -1,5 +1,4 @@
import {writable, derived} from "svelte/store"
import {MultiRequestOptions} from "@welshman/net"
import {tryCatch, fetchJson, uniq, batcher, postJson, last} from "@welshman/lib"
import {collection} from "./collection.js"
import {deriveProfile} from "./profiles.js"
-2
View File
@@ -1,9 +1,7 @@
import {MUTES, asDecryptedEvent, readList} from "@welshman/util"
import {TrustedEvent, PublishedList} from "@welshman/util"
import {load, MultiRequestOptions} from "@welshman/net"
import {deriveEventsMapped} from "@welshman/store"
import {repository} from "./core.js"
import {Router} from "./router.js"
import {collection} from "./collection.js"
import {ensurePlaintext} from "./plaintext.js"
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
-2
View File
@@ -1,9 +1,7 @@
import {PINS, asDecryptedEvent, readList} from "@welshman/util"
import {TrustedEvent, PublishedList} from "@welshman/util"
import {load, MultiRequestOptions} from "@welshman/net"
import {deriveEventsMapped} from "@welshman/store"
import {repository} from "./core.js"
import {Router} from "./router.js"
import {collection} from "./collection.js"
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
+1 -3
View File
@@ -1,10 +1,8 @@
import {derived, readable} from "svelte/store"
import {readProfile, displayProfile, displayPubkey, PROFILE} from "@welshman/util"
import {load, MultiRequestOptions} from "@welshman/net"
import {PublishedProfile} from "@welshman/util"
import {deriveEventsMapped, withGetter} from "@welshman/store"
import {repository} from "./core.js"
import {Router} from "./router.js"
import {collection} from "./collection.js"
import {loadWithAsapMetaRelayUrls} from "./relaySelections.js"
@@ -25,7 +23,7 @@ export const {
store: profiles,
getKey: profile => profile.event.pubkey,
load: (pubkey: string, relays: string[]) =>
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [PROFILE], authors: [pubkey]}])
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [PROFILE], authors: [pubkey]}]),
})
export const displayProfileByPubkey = (pubkey: string | undefined) =>
+11 -7
View File
@@ -10,10 +10,10 @@ import {
getRelayTagValues,
} from "@welshman/util"
import {TrustedEvent, Filter, PublishedList, List} from "@welshman/util"
import {load, MultiRequestOptions} from "@welshman/net"
import {load} from "@welshman/net"
import {deriveEventsMapped} from "@welshman/store"
import {repository} from "./core.js"
import {Router, addNoFallbacks} from "./router.js"
import {Router} from "./router.js"
import {collection} from "./collection.js"
export const getRelayUrls = (list?: List): string[] =>
@@ -51,13 +51,15 @@ export const {
const router = Router.get()
await load({
relays: router.merge([router.Index(), router.FromRelays(relays), router.FromPubkey(pubkey)]).getUrls(),
relays: router
.merge([router.Index(), router.FromRelays(relays), router.FromPubkey(pubkey)])
.getUrls(),
filters: [{kinds: [RELAYS], authors: [pubkey]}],
})
},
})
export const loadWithAsapMetaRelayUrls = <T>(pubkey: string, relays: string[], filters: Filter[]) => {
export const loadWithAsapMetaRelayUrls = (pubkey: string, relays: string[], filters: Filter[]) => {
const router = Router.get()
return new Promise(resolve => {
@@ -69,8 +71,10 @@ export const loadWithAsapMetaRelayUrls = <T>(pubkey: string, relays: string[], f
}
}
load({filters, relays: router.merge([router.Index(), router.FromRelays(relays)]).getUrls()})
.then(onLoad)
load({
filters,
relays: router.merge([router.Index(), router.FromRelays(relays)]).getUrls(),
}).then(onLoad)
loadRelaySelections(pubkey, relays)
.then(() => load({filters, relays: router.FromPubkey(pubkey).getUrls()}))
@@ -93,5 +97,5 @@ export const {
store: inboxRelaySelections,
getKey: inboxRelaySelections => inboxRelaySelections.event.pubkey,
load: (pubkey: string, relays: string[]) =>
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [INBOX_RELAYS], authors: [pubkey]}])
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [INBOX_RELAYS], authors: [pubkey]}]),
})
+5 -3
View File
@@ -14,7 +14,6 @@ import {
MINUTE,
HOUR,
DAY,
WEEK,
} from "@welshman/lib"
import {
getFilterId,
@@ -242,7 +241,8 @@ export class Router {
FromPubkey = (pubkey: string) => this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Write))
PubkeyInbox = (pubkey: string) => this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Inbox))
PubkeyInbox = (pubkey: string) =>
this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Inbox))
ForPubkeys = (pubkeys: string[]) => this.merge(pubkeys.map(pubkey => this.ForPubkey(pubkey)))
@@ -493,7 +493,9 @@ export const getFilterSelections = (
const result = []
for (const [id, filter] of filtersById.entries()) {
const scenario = Router.get().merge(scenariosById.get(id) || []).policy(addMinimalFallbacks)
const scenario = Router.get()
.merge(scenariosById.get(id) || [])
.policy(addMinimalFallbacks)
result.push({filters: [filter], relays: scenario.getUrls()})
}
+3 -6
View File
@@ -1,12 +1,9 @@
import {openDB, deleteDB} from "idb"
import {IDBPDatabase} from "idb"
import {writable} from "svelte/store"
import {Unsubscriber, Writable} from "svelte/store"
import {indexBy, call, equals, throttle, fromPairs} from "@welshman/lib"
import {TrustedEvent} from "@welshman/util"
import {Repository} from "@welshman/relay"
import {Tracker} from "@welshman/net"
import {withGetter, adapter, throttled, custom} from "@welshman/store"
import {Unsubscriber} from "svelte/store"
import {call} from "@welshman/lib"
import {withGetter} from "@welshman/store"
export type StorageAdapterOptions = {
throttle?: number
+16 -4
View File
@@ -1,5 +1,15 @@
import {Writable, Readable, writable, derived, get} from "svelte/store"
import {Deferred, fromPairs, TaskQueue, dissoc, identity, uniq, defer, sleep, assoc} from "@welshman/lib"
import {
Deferred,
fromPairs,
TaskQueue,
dissoc,
identity,
uniq,
defer,
sleep,
assoc,
} from "@welshman/lib"
import {stamp, own, hash} from "@welshman/signer"
import {
TrustedEvent,
@@ -225,9 +235,11 @@ export const thunkQueue = new TaskQueue<Thunk>({
// Update status to pending
thunk.status.set(
fromPairs(
thunk.request.relays
.map(url => [url, {status: PublishStatus.Pending, message: "Sending your message..."}])
)
thunk.request.relays.map(url => [
url,
{status: PublishStatus.Pending, message: "Sending your message..."},
]),
),
)
// Send it off
-1
View File
@@ -1,6 +1,5 @@
import {writable, derived} from "svelte/store"
import {Zapper} from "@welshman/util"
import {MultiRequestOptions} from "@welshman/net"
import {
identity,
fetchJson,