diff --git a/packages/app/src/relaySelections.ts b/packages/app/src/relaySelections.ts index d7fc1c9..375b5a9 100644 --- a/packages/app/src/relaySelections.ts +++ b/packages/app/src/relaySelections.ts @@ -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() + const authors = new Set() + 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[]) => diff --git a/packages/lib/src/Tools.ts b/packages/lib/src/Tools.ts index 0abeb65..2ec2f6f 100644 --- a/packages/lib/src/Tools.ts +++ b/packages/lib/src/Tools.ts @@ -533,7 +533,7 @@ export const fromPairs = (pairs: [k?: string, v?: T, ...args: unknown[]][]) = * @param xs - Array of arrays to flatten * @returns Flattened array */ -export const flatten = (xs: T[][]) => xs.flatMap(identity) +export const flatten = (xs: (T | T[])[], ...args: unknown[]) => xs.flatMap(identity) /** * Splits array into two arrays based on predicate diff --git a/packages/net/src/auth.ts b/packages/net/src/auth.ts index 6a74d05..7133f3f 100644 --- a/packages/net/src/auth.ts +++ b/packages/net/src/auth.ts @@ -114,19 +114,21 @@ export class AuthState extends EventEmitter { async attemptAuth(sign: (event: StampedEvent) => Promise) { 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() { diff --git a/packages/util/src/Kinds.ts b/packages/util/src/Kinds.ts index 7d2e3ba..19c1862 100644 --- a/packages/util/src/Kinds.ts +++ b/packages/util/src/Kinds.ts @@ -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 diff --git a/packages/util/src/Relay.ts b/packages/util/src/Relay.ts index e05edd3..d676acd 100644 --- a/packages/util/src/Relay.ts +++ b/packages/util/src/Relay.ts @@ -13,6 +13,7 @@ export type RelayProfile = { icon?: string banner?: string name?: string + self?: string pubkey?: string contact?: string software?: string diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 97c17b3..25bc9fb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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':