2026-03-23 21:21:04 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {preventDefault} from "@lib/html"
|
|
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
|
|
|
|
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
|
|
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
|
|
|
|
import Spinner from "@lib/components/Spinner.svelte"
|
|
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
|
|
|
|
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
|
|
|
|
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
|
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {deriveUserItem, messagingRelayLists, relayLists} from "@app/core"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {DEFAULT_RELAYS, DEFAULT_MESSAGING_RELAYS} from "@app/env"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushToast} from "@app/toast"
|
2026-03-23 21:21:04 +00:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
next: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {next}: Props = $props()
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const userRelayList = deriveUserItem($app => $relayLists)
|
2026-03-23 21:21:04 +00:00
|
|
|
|
|
|
|
|
const back = () => history.back()
|
|
|
|
|
|
|
|
|
|
const enable = async () => {
|
|
|
|
|
loading = true
|
|
|
|
|
|
|
|
|
|
try {
|
2026-07-28 16:16:26 +00:00
|
|
|
const relayUrls = $userRelayList?.urls() ?? []
|
|
|
|
|
|
|
|
|
|
if (relayUrls.length === 0) {
|
|
|
|
|
const command = await $relayLists.update(writer =>
|
|
|
|
|
writer.setReadUrls(DEFAULT_RELAYS).setWriteUrls(DEFAULT_RELAYS),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const error = await command.publish().waitForError()
|
2026-03-23 21:21:04 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 16:16:26 +00:00
|
|
|
const command = await $messagingRelayLists.setUrls(DEFAULT_MESSAGING_RELAYS)
|
|
|
|
|
const error = await command.publish().waitForError()
|
2026-03-23 21:21:04 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await next()
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-28 16:16:26 +00:00
|
|
|
|
|
|
|
|
let loading = $state(false)
|
2026-03-23 21:21:04 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal tag="form" onsubmit={preventDefault(enable)}>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<ModalHeader>
|
|
|
|
|
<ModalTitle>Enable direct messaging?</ModalTitle>
|
|
|
|
|
</ModalHeader>
|
|
|
|
|
<p>Direct messaging isn't currently enabled. Would you like to turn it on?</p>
|
|
|
|
|
</ModalBody>
|
|
|
|
|
<ModalFooter>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button class="button button-link" onclick={back}>
|
2026-03-23 21:21:04 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
|
|
|
|
Go back
|
|
|
|
|
</Button>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button type="submit" class="button button-primary" disabled={loading}>
|
2026-03-23 21:21:04 +00:00
|
|
|
<Spinner {loading}>Enable direct messaging</Spinner>
|
|
|
|
|
<Icon icon={AltArrowRight} />
|
|
|
|
|
</Button>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</Modal>
|