Wait for the user's own settings before reading the send delay (#655)
This commit is contained in:
parent
801b981bdf
commit
6a3da63b00
5 changed files with 25 additions and 9 deletions
|
|
@ -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,
|
||||
}),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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 getSetting = <K extends keyof SettingsValues>(key: K) => userSettingsValues.get()[key]
|
||||
|
|
|
|||
Loading…
Reference in a new issue