mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
fix: poll message status when sent or already processing.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
import SendModal from './sendModal.svelte';
|
||||
import ScheduleModal from './scheduleModal.svelte';
|
||||
import CancelModal from './cancelModal.svelte';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
|
||||
export let message: Models.Message & { data: Record<string, string> };
|
||||
export let topics: Models.Topic[];
|
||||
@@ -18,6 +20,36 @@
|
||||
let showCancel = false;
|
||||
let showFailed = false;
|
||||
let errors: string[] = [];
|
||||
|
||||
let intervalID: ReturnType<typeof setInterval>;
|
||||
|
||||
function checkMessageStatus() {
|
||||
sdk.forProject.messaging
|
||||
.getMessage(message.$id)
|
||||
.then((msg) => {
|
||||
if (msg.status !== 'processing') {
|
||||
clearInterval(intervalID);
|
||||
message.status = msg.status;
|
||||
}
|
||||
})
|
||||
.catch(() => clearInterval(intervalID));
|
||||
}
|
||||
|
||||
async function pollMessageStatus(update: boolean = true) {
|
||||
if (update) message.status = 'processing';
|
||||
|
||||
checkMessageStatus();
|
||||
clearInterval(intervalID);
|
||||
intervalID = setInterval(checkMessageStatus, 2000);
|
||||
}
|
||||
|
||||
onDestroy(() => clearInterval(intervalID));
|
||||
|
||||
onMount(() => {
|
||||
if (message.status === 'processing') {
|
||||
pollMessageStatus(false);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<CardGrid hideFooter={['processing', 'sent'].includes(message.status)}>
|
||||
@@ -70,7 +102,7 @@
|
||||
|
||||
<ScheduleModal bind:show={showSchedule} {message} {topics} />
|
||||
|
||||
<SendModal bind:show={showSend} {message} {topics} />
|
||||
<SendModal bind:show={showSend} {message} {topics} on:update={() => pollMessageStatus()} />
|
||||
|
||||
<CancelModal bind:show={showCancel} {message} />
|
||||
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { MessagingProviderType, type Models } from '@appwrite.io/console';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
export let show = false;
|
||||
export let message: Models.Message & { data: Record<string, unknown> };
|
||||
export let topics: Models.Topic[];
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
let totalTargets = message.targets?.length ?? 0;
|
||||
|
||||
for (const topic of topics) {
|
||||
@@ -80,6 +82,8 @@
|
||||
type: 'error'
|
||||
});
|
||||
trackError(error, Submit.MessagingMessageUpdate);
|
||||
} finally {
|
||||
dispatch('update');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user