mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-11 03:17:02 +00:00
Add retry for thunks
This commit is contained in:
@@ -115,7 +115,7 @@ export const broadcastUserData = async (relays: string[]) => {
|
||||
|
||||
for (const event of events) {
|
||||
if (isSignedEvent(event)) {
|
||||
await publishThunk({event, relays})
|
||||
await publishThunk({event, relays}).result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
const back = () => history.back()
|
||||
|
||||
const confirm = async (url: string) => {
|
||||
await addSpaceMembership(url)
|
||||
await addSpaceMembership(url).result
|
||||
|
||||
goto(makeSpacePath(url), {replaceState: true})
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
const back = () => history.back()
|
||||
|
||||
const tryJoin = async () => {
|
||||
await addSpaceMembership(url)
|
||||
await addSpaceMembership(url).result
|
||||
|
||||
clearModals()
|
||||
}
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
<script lang="ts">
|
||||
import {displayRelayUrl} from "@welshman/util"
|
||||
import {PublishStatus} from "@welshman/net"
|
||||
import {mergeThunks, publishThunk} from "@welshman/app"
|
||||
import type {Thunk, MergedThunk} from "@welshman/app"
|
||||
import Icon from '@lib/components/Icon.svelte'
|
||||
import Tippy from "@lib/components/Tippy.svelte"
|
||||
import Button from '@lib/components/Button.svelte'
|
||||
import ThunkStatusDetail from '@app/components/ThunkStatusDetail.svelte'
|
||||
|
||||
export let thunk: Thunk | MergedThunk
|
||||
|
||||
const {status} = thunk
|
||||
const {Pending, Success, Failure, Timeout} = PublishStatus
|
||||
|
||||
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)
|
||||
$: canCancel = ps.length === 0
|
||||
$: isPending = ps.some(s => s.status === Pending)
|
||||
@@ -29,11 +38,14 @@
|
||||
{/if}
|
||||
</span>
|
||||
{:else if isFailure && failure}
|
||||
{@const [url, {message}] = failure}
|
||||
<span
|
||||
class="flex tooltip cursor-pointer gap-1 mt-2"
|
||||
data-tip="{message} ({displayRelayUrl(url)})">
|
||||
<Icon icon="danger" class="translate-y-px" size={3} />
|
||||
<span class="opacity-50">Failed to send!</span>
|
||||
</span>
|
||||
{@const [url, {message, status}] = failure}
|
||||
<Tippy
|
||||
component={ThunkStatusDetail}
|
||||
props={{url, message, status, retry}}
|
||||
params={{interactive: true}}>
|
||||
<span class="flex tooltip cursor-pointer gap-1 mt-2 items-center">
|
||||
<Icon icon="danger" size={3} />
|
||||
<span class="opacity-50">Failed to send!</span>
|
||||
</span>
|
||||
</Tippy>
|
||||
{/if}
|
||||
|
||||
21
src/app/components/ThunkStatusDetail.svelte
Normal file
21
src/app/components/ThunkStatusDetail.svelte
Normal file
@@ -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 tags = [...params.tags, ...remove($pubkey!, pubkeys).map(tagPubkey)]
|
||||
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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user