This commit is contained in:
Timothy Jaeryang Baek 2025-12-26 15:57:19 +04:00
parent 44faf00fac
commit 6c14ba1fb4
2 changed files with 26 additions and 9 deletions

View file

@ -16,7 +16,7 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
export let show = false; export let show = false;
export let params = {}; export let eventData = null;
let loading = false; let loading = false;
let completed = false; let completed = false;
@ -26,14 +26,20 @@
const syncStats = async () => { const syncStats = async () => {
if (window.opener) { if (window.opener) {
window.opener.focus(); window.opener.focus();
window.opener.postMessage({ type: 'sync:start' }, '*'); window.opener.postMessage(
{ type: 'sync:start', requestId: eventData?.requestId ?? null },
'*'
);
} }
const res = await getVersion(localStorage.token).catch(() => { const res = await getVersion(localStorage.token).catch(() => {
return null; return null;
}); });
if (res) { if (res) {
window.opener.postMessage({ type: 'sync:version', data: res }, '*'); window.opener.postMessage(
{ type: 'sync:version', data: res, requestId: eventData?.requestId ?? null },
'*'
);
} }
loading = true; loading = true;
@ -43,7 +49,11 @@
let allItemsLoaded = false; let allItemsLoaded = false;
while (!allItemsLoaded) { while (!allItemsLoaded) {
const res = await exportChatStats(localStorage.token, page, params).catch(() => { const res = await exportChatStats(
localStorage.token,
page,
eventData?.searchParams ?? {}
).catch(() => {
return null; return null;
}); });
@ -53,7 +63,10 @@
if (window.opener) { if (window.opener) {
if (res.items.length > 0) { if (res.items.length > 0) {
window.opener.postMessage({ type: 'sync:stats:chats', data: res }, '*'); window.opener.postMessage(
{ type: 'sync:stats:chats', data: res, requestId: eventData?.requestId ?? null },
'*'
);
} }
} else { } else {
console.log('No opener found to send stats back to.'); console.log('No opener found to send stats back to.');
@ -71,7 +84,10 @@
// send sync complete message // send sync complete message
if (window.opener) { if (window.opener) {
window.opener.postMessage({ type: 'sync:complete' }, '*'); window.opener.postMessage(
{ type: 'sync:complete', requestId: eventData?.requestId ?? null },
'*'
);
} }
loading = false; loading = false;
completed = true; completed = true;

View file

@ -90,8 +90,9 @@
let tokenTimer = null; let tokenTimer = null;
let showRefresh = false; let showRefresh = false;
let showSyncStatsModal = false; let showSyncStatsModal = false;
let syncStatsParams = {}; let syncStatsEventData = null;
let heartbeatInterval = null; let heartbeatInterval = null;
@ -613,7 +614,7 @@
} }
if (event.data === 'export:stats' || event.data?.type === 'export:stats') { if (event.data === 'export:stats' || event.data?.type === 'export:stats') {
syncStatsParams = event.data?.searchParams ?? {}; syncStatsEventData = event.data;
showSyncStatsModal = true; showSyncStatsModal = true;
} }
}; };
@ -886,7 +887,7 @@
{/if} {/if}
{#if $config?.features.enable_community_sharing} {#if $config?.features.enable_community_sharing}
<SyncStatsModal bind:show={showSyncStatsModal} params={syncStatsParams} /> <SyncStatsModal bind:show={showSyncStatsModal} eventData={syncStatsEventData} />
{/if} {/if}
<Toaster <Toaster