Improve socket auth, outbox loading, some other things
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {derived} from "svelte/store"
|
||||
import {batcher, always} from "@welshman/lib"
|
||||
import {batcher} from "@welshman/lib"
|
||||
import {INBOX_RELAYS, RELAYS, asDecryptedEvent, readList, getRelaysFromList} from "@welshman/util"
|
||||
import {TrustedEvent, PublishedList, RelayMode} from "@welshman/util"
|
||||
import {request} from "@welshman/net"
|
||||
@@ -15,21 +15,32 @@ export type OutboxLoaderRequest = {
|
||||
|
||||
export const loadUsingOutbox = batcher(200, (requests: OutboxLoaderRequest[]) => {
|
||||
const router = Router.get()
|
||||
const authors: string[] = []
|
||||
const scenarios = [router.Index()]
|
||||
const kinds = new Set<number>()
|
||||
const authors = new Set<string>()
|
||||
const scenarios = [router.Index()]
|
||||
|
||||
for (const {pubkey, relays, kind} of requests) {
|
||||
for (const {pubkey, kind} of requests) {
|
||||
kinds.add(kind)
|
||||
authors.push(pubkey)
|
||||
scenarios.push(router.FromPubkey(pubkey), router.FromRelays(relays))
|
||||
authors.add(pubkey)
|
||||
scenarios.push(router.FromPubkey(pubkey))
|
||||
}
|
||||
|
||||
const relays = router.merge(scenarios).getUrls()
|
||||
const filters = [{authors, kinds: Array.from(kinds)}]
|
||||
const filters = [{authors: Array.from(authors), kinds: Array.from(kinds)}]
|
||||
const promise = request({filters, relays, autoClose: true})
|
||||
|
||||
return requests.map(always(promise))
|
||||
return requests.map(async ({kind, pubkey, relays}) => {
|
||||
const promises = [promise]
|
||||
|
||||
// If the caller explicitly provided relays, make sure we check them
|
||||
if (relays.length > 0) {
|
||||
const filters = [{authors: [pubkey], kinds: [kind]}]
|
||||
|
||||
promises.push(request({filters, relays, autoClose: true}))
|
||||
}
|
||||
|
||||
await Promise.all(promises)
|
||||
})
|
||||
})
|
||||
|
||||
export const makeOutboxLoader = (kind: number) => (pubkey: string, relays: string[]) =>
|
||||
|
||||
@@ -533,7 +533,7 @@ export const fromPairs = <T>(pairs: [k?: string, v?: T, ...args: unknown[]][]) =
|
||||
* @param xs - Array of arrays to flatten
|
||||
* @returns Flattened array
|
||||
*/
|
||||
export const flatten = <T>(xs: T[][]) => xs.flatMap(identity)
|
||||
export const flatten = <T>(xs: (T | T[])[], ...args: unknown[]) => xs.flatMap(identity)
|
||||
|
||||
/**
|
||||
* Splits array into two arrays based on predicate
|
||||
|
||||
+13
-11
@@ -114,19 +114,21 @@ export class AuthState extends EventEmitter {
|
||||
async attemptAuth(sign: (event: StampedEvent) => Promise<SignedEvent>) {
|
||||
this.socket.attemptToOpen()
|
||||
|
||||
await poll({
|
||||
signal: AbortSignal.timeout(800),
|
||||
condition: () => this.status === AuthStatus.Requested,
|
||||
})
|
||||
if (![AuthStatus.Forbidden, AuthStatus.Ok].includes(this.status)) {
|
||||
await poll({
|
||||
signal: AbortSignal.timeout(800),
|
||||
condition: () => this.status === AuthStatus.Requested,
|
||||
})
|
||||
|
||||
if (this.status === AuthStatus.Requested) {
|
||||
await this.doAuth(sign)
|
||||
if (this.status === AuthStatus.Requested) {
|
||||
await this.doAuth(sign)
|
||||
}
|
||||
|
||||
await poll({
|
||||
signal: AbortSignal.timeout(800),
|
||||
condition: () => this.status !== AuthStatus.PendingResponse,
|
||||
})
|
||||
}
|
||||
|
||||
await poll({
|
||||
signal: AbortSignal.timeout(800),
|
||||
condition: () => this.status !== AuthStatus.PendingResponse,
|
||||
})
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
|
||||
@@ -178,6 +178,9 @@ export const EVENT_TIME = 31923
|
||||
export const EVENT_RSVP = 31925
|
||||
export const HANDLER_RECOMMENDATION = 31989
|
||||
export const HANDLER_INFORMATION = 31990
|
||||
export const ALERT_REQUEST_EMAIL = 32830
|
||||
export const ALERT_STATUS = 32831
|
||||
export const ALERT_REQUEST_PUSH = 32832
|
||||
export const COMMUNITY = 34550
|
||||
export const ROOM = 35834
|
||||
export const ROOM_META = 39000
|
||||
|
||||
@@ -13,6 +13,7 @@ export type RelayProfile = {
|
||||
icon?: string
|
||||
banner?: string
|
||||
name?: string
|
||||
self?: string
|
||||
pubkey?: string
|
||||
contact?: string
|
||||
software?: string
|
||||
|
||||
Generated
+9
@@ -242,6 +242,15 @@ importers:
|
||||
specifier: ~5.8.0
|
||||
version: 5.8.2
|
||||
|
||||
packages/mls:
|
||||
devDependencies:
|
||||
rimraf:
|
||||
specifier: ~6.0.0
|
||||
version: 6.0.1
|
||||
typescript:
|
||||
specifier: ~5.8.0
|
||||
version: 5.8.2
|
||||
|
||||
packages/net:
|
||||
dependencies:
|
||||
'@welshman/lib':
|
||||
|
||||
Reference in New Issue
Block a user