Wait for the user's own settings before reading the send delay (#655)

This commit is contained in:
Coracle-Bot 2026-09-25 17:11:44 +00:00 committed by hodlbod
parent 801b981bdf
commit 6a3da63b00
5 changed files with 25 additions and 9 deletions

View file

@ -41,7 +41,7 @@
import ComposeParent from "@app/components/ComposeParent.svelte" import ComposeParent from "@app/components/ComposeParent.svelte"
import ThunkToast from "@app/components/ThunkToast.svelte" import ThunkToast from "@app/components/ThunkToast.svelte"
import {app, deletes, router, user, wraps} from "@app/core" import {app, deletes, router, user, wraps} from "@app/core"
import {userSettingsValues} from "@app/settings" import {loadSendDelay} from "@app/settings"
import {deriveChat, makeChatId} from "@app/chats" import {deriveChat, makeChatId} from "@app/chats"
import {makeFeedContext} from "@app/feeds" import {makeFeedContext} from "@app/feeds"
import {navigate, pushModal} from "@app/modal" import {navigate, pushModal} from "@app/modal"
@ -141,13 +141,15 @@
addTemplate(DIRECT_MESSAGE, buffer.splice(0).join(""), tags) addTemplate(DIRECT_MESSAGE, buffer.splice(0).join(""), tags)
const delay = await loadSendDelay()
// Kind 15 carries one image each per nip 17, and a second's sleep keeps the timestamps distinct. // Kind 15 carries one image each per nip 17, and a second's sleep keeps the timestamps distinct.
const thunks = await Promise.all( const thunks = await Promise.all(
Array.from(enumerate(templates)).map(([i, event]) => Array.from(enumerate(templates)).map(([i, event]) =>
$wraps.publish({ $wraps.publish({
event, event,
recipients: pubkeys, recipients: pubkeys,
delay: $userSettingsValues.send_delay + ms(i), delay: delay + ms(i),
pow: 16, pow: 16,
}), }),
), ),

View file

@ -12,7 +12,7 @@
import {relays, thunks, writer} from "@app/core" import {relays, thunks, writer} from "@app/core"
import {DraftKey} from "@app/drafts" import {DraftKey} from "@app/drafts"
import {makeEditor} from "@app/editor" import {makeEditor} from "@app/editor"
import {getSetting} from "@app/settings" import {loadSendDelay} from "@app/settings"
import {pushToast} from "@app/toast" import {pushToast} from "@app/toast"
type Values = { type Values = {
@ -79,7 +79,7 @@
try { try {
const reply = await renderReply(content, ed.storage.nostr.getEditorTags()) const reply = await renderReply(content, ed.storage.nostr.getEditorTags())
const thunk = $thunks.publish({...reply, delay: getSetting("send_delay")}) const thunk = $thunks.publish({...reply, delay: await loadSendDelay()})
const error = await thunk.waitForError() const error = await thunk.waitForError()
if (error) { if (error) {

View file

@ -17,7 +17,7 @@
import {DraftKey} from "@app/drafts" import {DraftKey} from "@app/drafts"
import {pushToast} from "@app/toast" import {pushToast} from "@app/toast"
import {relays, thunks, writer} from "@app/core" import {relays, thunks, writer} from "@app/core"
import {getSetting} from "@app/settings" import {loadSendDelay} from "@app/settings"
type Values = { type Values = {
content?: string | object content?: string | object
@ -76,7 +76,7 @@
const thunk = $thunks.publish({ const thunk = $thunks.publish({
relays: [url], relays: [url],
event: await eventWriter.renderTemplate(), event: await eventWriter.renderTemplate(),
delay: getSetting("send_delay"), delay: await loadSendDelay(),
}) })
draftKey.clear() draftKey.clear()

View file

@ -43,7 +43,7 @@
groupRoomMessages, groupRoomMessages,
prependParent, prependParent,
} from "@app/rooms" } from "@app/rooms"
import {userSettingsValues} from "@app/settings" import {loadSendDelay} from "@app/settings"
import {isFeedLoading, makeFeed, makeFeedContext, makeScrollLoader} from "@app/feeds" import {isFeedLoading, makeFeed, makeFeedContext, makeScrollLoader} from "@app/feeds"
import {pageLoading} from "@app/loading" import {pageLoading} from "@app/loading"
import {checked, deferredRoomPath, setChecked} from "@app/notifications" import {checked, deferredRoomPath, setChecked} from "@app/notifications"
@ -211,13 +211,15 @@
eventWriter.setParent(parent) eventWriter.setParent(parent)
} }
const delay = await loadSendDelay()
const thunk = $thunks.publish({ const thunk = $thunks.publish({
relays: [url], relays: [url],
event: stamp(await eventWriter.renderTemplate(), eventToEdit?.created_at), event: stamp(await eventWriter.renderTemplate(), eventToEdit?.created_at),
delay: $userSettingsValues.send_delay, delay,
}) })
if ($userSettingsValues.send_delay) { if (delay) {
pushToast({ pushToast({
timeout: 30_000, timeout: 30_000,
children: { children: {

View file

@ -110,6 +110,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.
export const loadSendDelay = async () => {
const $app = app.get()
const {pubkey} = User.require($app)
if (!$app.use(Settings).get(pubkey)) {
await $app.use(Settings).load(pubkey)
}
return userSettingsValues.get().send_delay
}
export const zapAmounts = derived(userSettingsValues, $settings => $settings.zap_amounts) export const zapAmounts = derived(userSettingsValues, $settings => $settings.zap_amounts)
export const getSetting = <K extends keyof SettingsValues>(key: K) => userSettingsValues.get()[key] export const getSetting = <K extends keyof SettingsValues>(key: K) => userSettingsValues.get()[key]