Wait for the settings decrypt before reading the send delay (#681)
This commit is contained in:
parent
589af8060e
commit
ff52f711da
1 changed files with 12 additions and 5 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import type {Writable} from "svelte/store"
|
import type {Writable} from "svelte/store"
|
||||||
import {derived, writable} from "svelte/store"
|
import {derived, writable} from "svelte/store"
|
||||||
import {append, equals, remove, spec, toggle} from "@welshman/lib"
|
import {append, equals, poll, remove, spec, toggle} from "@welshman/lib"
|
||||||
import {APP_DATA} from "@welshman/util"
|
import {APP_DATA} from "@welshman/util"
|
||||||
import {withGetter} from "@welshman/store"
|
import {withGetter} from "@welshman/store"
|
||||||
import {AppData} from "@welshman/domain"
|
import {AppData} from "@welshman/domain"
|
||||||
|
|
@ -11,6 +11,8 @@ import {app, fromApp, usePlugin} from "@app/core"
|
||||||
|
|
||||||
export const SETTINGS = "flotilla/settings"
|
export const SETTINGS = "flotilla/settings"
|
||||||
|
|
||||||
|
const settingsFilter = {kinds: [APP_DATA], "#d": [SETTINGS]}
|
||||||
|
|
||||||
export enum RelayAuthMode {
|
export enum RelayAuthMode {
|
||||||
Aggressive = "aggressive",
|
Aggressive = "aggressive",
|
||||||
Conservative = "conservative",
|
Conservative = "conservative",
|
||||||
|
|
@ -59,7 +61,7 @@ export class Settings extends DerivedPlugin<AppDataReader> {
|
||||||
|
|
||||||
constructor(app: IApp) {
|
constructor(app: IApp) {
|
||||||
super(app, {
|
super(app, {
|
||||||
filters: [{kinds: [APP_DATA], "#d": [SETTINGS]}],
|
filters: [settingsFilter],
|
||||||
eventToItem: app.use(Domain).reader(AppData),
|
eventToItem: app.use(Domain).reader(AppData),
|
||||||
getKey: settings => settings.author(),
|
getKey: settings => settings.author(),
|
||||||
})
|
})
|
||||||
|
|
@ -71,7 +73,7 @@ export class Settings extends DerivedPlugin<AppDataReader> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(pubkey: string) {
|
fetch(pubkey: string) {
|
||||||
return this.app.use(Network).loadUsingOutbox(pubkey, {kinds: [APP_DATA], "#d": [SETTINGS]})
|
return this.app.use(Network).loadUsingOutbox(pubkey, settingsFilter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,13 +112,18 @@ export const createSettingsForm = (): Writable<SettingsValues> => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A send reads the delay when it is clicked, and a room can paint before the user's own settings arrive.
|
// A send reads the delay when it is clicked, and the settings event is readable only once it decrypts.
|
||||||
export const loadSendDelay = async () => {
|
export const loadSendDelay = async () => {
|
||||||
const $app = app.get()
|
const $app = app.get()
|
||||||
const {pubkey} = User.require($app)
|
const {pubkey} = User.require($app)
|
||||||
|
const decrypted = () => Boolean($app.use(Settings).get(pubkey))
|
||||||
|
|
||||||
if (!$app.use(Settings).get(pubkey)) {
|
if (!decrypted()) {
|
||||||
await $app.use(Settings).load(pubkey)
|
await $app.use(Settings).load(pubkey)
|
||||||
|
|
||||||
|
if ($app.repository.query([{...settingsFilter, authors: [pubkey]}]).length > 0) {
|
||||||
|
await poll({interval: 30, condition: decrypted, signal: AbortSignal.timeout(3000)})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return userSettingsValues.get().send_delay
|
return userSettingsValues.get().send_delay
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue