forked from coracle/flotilla
Add retry for thunks
This commit is contained in:
+1
-1
@@ -115,7 +115,7 @@ export const broadcastUserData = async (relays: string[]) => {
|
|||||||
|
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
if (isSignedEvent(event)) {
|
if (isSignedEvent(event)) {
|
||||||
await publishThunk({event, relays})
|
await publishThunk({event, relays}).result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const confirm = async (url: string) => {
|
const confirm = async (url: string) => {
|
||||||
await addSpaceMembership(url)
|
await addSpaceMembership(url).result
|
||||||
|
|
||||||
goto(makeSpacePath(url), {replaceState: true})
|
goto(makeSpacePath(url), {replaceState: true})
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const tryJoin = async () => {
|
const tryJoin = async () => {
|
||||||
await addSpaceMembership(url)
|
await addSpaceMembership(url).result
|
||||||
|
|
||||||
clearModals()
|
clearModals()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {displayRelayUrl} from "@welshman/util"
|
import {displayRelayUrl} from "@welshman/util"
|
||||||
import {PublishStatus} from "@welshman/net"
|
import {PublishStatus} from "@welshman/net"
|
||||||
|
import {mergeThunks, publishThunk} from "@welshman/app"
|
||||||
import type {Thunk, MergedThunk} from "@welshman/app"
|
import type {Thunk, MergedThunk} from "@welshman/app"
|
||||||
import Icon from '@lib/components/Icon.svelte'
|
import Icon from '@lib/components/Icon.svelte'
|
||||||
|
import Tippy from "@lib/components/Tippy.svelte"
|
||||||
import Button from '@lib/components/Button.svelte'
|
import Button from '@lib/components/Button.svelte'
|
||||||
|
import ThunkStatusDetail from '@app/components/ThunkStatusDetail.svelte'
|
||||||
|
|
||||||
export let thunk: Thunk | MergedThunk
|
export let thunk: Thunk | MergedThunk
|
||||||
|
|
||||||
const {status} = thunk
|
|
||||||
const {Pending, Success, Failure, Timeout} = PublishStatus
|
const {Pending, Success, Failure, Timeout} = PublishStatus
|
||||||
|
|
||||||
const abort = () => thunk.controller.abort()
|
const abort = () => thunk.controller.abort()
|
||||||
|
|
||||||
|
const retry = () => {
|
||||||
|
thunk = (thunk as any).thunks
|
||||||
|
? mergeThunks((thunk as MergedThunk).thunks.map(t => publishThunk(t.request)))
|
||||||
|
: publishThunk((thunk as Thunk).request)
|
||||||
|
}
|
||||||
|
|
||||||
|
$: status = thunk.status
|
||||||
$: ps = Object.values($status)
|
$: ps = Object.values($status)
|
||||||
$: canCancel = ps.length === 0
|
$: canCancel = ps.length === 0
|
||||||
$: isPending = ps.some(s => s.status === Pending)
|
$: isPending = ps.some(s => s.status === Pending)
|
||||||
@@ -29,11 +38,14 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
{:else if isFailure && failure}
|
{:else if isFailure && failure}
|
||||||
{@const [url, {message}] = failure}
|
{@const [url, {message, status}] = failure}
|
||||||
<span
|
<Tippy
|
||||||
class="flex tooltip cursor-pointer gap-1 mt-2"
|
component={ThunkStatusDetail}
|
||||||
data-tip="{message} ({displayRelayUrl(url)})">
|
props={{url, message, status, retry}}
|
||||||
<Icon icon="danger" class="translate-y-px" size={3} />
|
params={{interactive: true}}>
|
||||||
<span class="opacity-50">Failed to send!</span>
|
<span class="flex tooltip cursor-pointer gap-1 mt-2 items-center">
|
||||||
</span>
|
<Icon icon="danger" size={3} />
|
||||||
|
<span class="opacity-50">Failed to send!</span>
|
||||||
|
</span>
|
||||||
|
</Tippy>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {PublishStatus} from '@welshman/net'
|
||||||
|
import {displayRelayUrl} from '@welshman/util'
|
||||||
|
import Button from '@lib/components/Button.svelte'
|
||||||
|
|
||||||
|
export let url
|
||||||
|
export let status
|
||||||
|
export let message
|
||||||
|
export let retry
|
||||||
|
|
||||||
|
if (!message && status === PublishStatus.Timeout) {
|
||||||
|
message = "request timed out"
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="card2 bg-alt col-2">
|
||||||
|
<p>
|
||||||
|
Failed to publish to {displayRelayUrl(url)}: {message}.
|
||||||
|
</p>
|
||||||
|
<Button class="link" on:click={retry}>Retry</Button>
|
||||||
|
</div>
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
const onSubmit = async ({content, ...params}: EventContent) => {
|
const onSubmit = async ({content, ...params}: EventContent) => {
|
||||||
const tags = [...params.tags, ...remove($pubkey!, pubkeys).map(tagPubkey)]
|
const tags = [...params.tags, ...remove($pubkey!, pubkeys).map(tagPubkey)]
|
||||||
const template = createEvent(DIRECT_MESSAGE, {content, tags})
|
const template = createEvent(DIRECT_MESSAGE, {content, tags})
|
||||||
const thunk = await sendWrapped({template, pubkeys, delay: 60000})
|
const thunk = await sendWrapped({template, pubkeys, delay: 2000})
|
||||||
|
|
||||||
thunks.update(assoc(thunk.thunks[0].event.id, thunk))
|
thunks.update(assoc(thunk.thunks[0].event.id, thunk))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user