diff --git a/src/app/components/Chat.svelte b/src/app/components/Chat.svelte index c63ef531..5eb8b285 100644 --- a/src/app/components/Chat.svelte +++ b/src/app/components/Chat.svelte @@ -41,7 +41,7 @@ import ComposeParent from "@app/components/ComposeParent.svelte" import ThunkToast from "@app/components/ThunkToast.svelte" 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 {makeFeedContext} from "@app/feeds" import {navigate, pushModal} from "@app/modal" @@ -141,13 +141,15 @@ 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. const thunks = await Promise.all( Array.from(enumerate(templates)).map(([i, event]) => $wraps.publish({ event, recipients: pubkeys, - delay: $userSettingsValues.send_delay + ms(i), + delay: delay + ms(i), pow: 16, }), ), diff --git a/src/app/components/CommentCompose.svelte b/src/app/components/CommentCompose.svelte index e36ae762..3d9fc774 100644 --- a/src/app/components/CommentCompose.svelte +++ b/src/app/components/CommentCompose.svelte @@ -12,7 +12,7 @@ import {relays, thunks, writer} from "@app/core" import {DraftKey} from "@app/drafts" import {makeEditor} from "@app/editor" - import {getSetting} from "@app/settings" + import {loadSendDelay} from "@app/settings" import {pushToast} from "@app/toast" type Values = { @@ -79,7 +79,7 @@ try { 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() if (error) { diff --git a/src/app/components/EventReply.svelte b/src/app/components/EventReply.svelte index 9f61823c..00043186 100644 --- a/src/app/components/EventReply.svelte +++ b/src/app/components/EventReply.svelte @@ -17,7 +17,7 @@ import {DraftKey} from "@app/drafts" import {pushToast} from "@app/toast" import {relays, thunks, writer} from "@app/core" - import {getSetting} from "@app/settings" + import {loadSendDelay} from "@app/settings" type Values = { content?: string | object @@ -76,7 +76,7 @@ const thunk = $thunks.publish({ relays: [url], event: await eventWriter.renderTemplate(), - delay: getSetting("send_delay"), + delay: await loadSendDelay(), }) draftKey.clear() diff --git a/src/app/components/RoomChat.svelte b/src/app/components/RoomChat.svelte index 55aa4704..a9c593a0 100644 --- a/src/app/components/RoomChat.svelte +++ b/src/app/components/RoomChat.svelte @@ -43,7 +43,7 @@ groupRoomMessages, prependParent, } from "@app/rooms" - import {userSettingsValues} from "@app/settings" + import {loadSendDelay} from "@app/settings" import {isFeedLoading, makeFeed, makeFeedContext, makeScrollLoader} from "@app/feeds" import {pageLoading} from "@app/loading" import {checked, deferredRoomPath, setChecked} from "@app/notifications" @@ -211,13 +211,15 @@ eventWriter.setParent(parent) } + const delay = await loadSendDelay() + const thunk = $thunks.publish({ relays: [url], event: stamp(await eventWriter.renderTemplate(), eventToEdit?.created_at), - delay: $userSettingsValues.send_delay, + delay, }) - if ($userSettingsValues.send_delay) { + if (delay) { pushToast({ timeout: 30_000, children: { diff --git a/src/app/settings.ts b/src/app/settings.ts index f8cc9f75..5aaa06b0 100644 --- a/src/app/settings.ts +++ b/src/app/settings.ts @@ -110,6 +110,18 @@ export const createSettingsForm = (): Writable => { } } +// 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 getSetting = (key: K) => userSettingsValues.get()[key]