From b7d286543518b3942b93eef94683144d526d98ee Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Thu, 5 Feb 2026 13:07:27 +0500 Subject: [PATCH] mobile: fix switching app from background to foreground starts a new attachment cache download group --- apps/mobile/app/hooks/use-app-events.tsx | 7 ++++++- packages/core/src/database/fs.ts | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsx index 4dba33602..e5d0cc519 100644 --- a/apps/mobile/app/hooks/use-app-events.tsx +++ b/apps/mobile/app/hooks/use-app-events.tsx @@ -561,6 +561,7 @@ export const useAppEvents = () => { initialUrl: string; backupDidWait: boolean; isConnectingSSE: boolean; + attachmentsCachedOfflineMode: boolean; }> >({}); @@ -655,7 +656,11 @@ export const useAppEvents = () => { } } - if (SettingsService.getProperty("offlineMode")) { + if ( + SettingsService.getProperty("offlineMode") && + !refValues.current.attachmentsCachedOfflineMode + ) { + refValues.current.attachmentsCachedOfflineMode = true; db.attachments.cacheAttachments().catch(() => { /* empty */ }); diff --git a/packages/core/src/database/fs.ts b/packages/core/src/database/fs.ts index 1ae799d52..8d0ef91f4 100644 --- a/packages/core/src/database/fs.ts +++ b/packages/core/src/database/fs.ts @@ -63,7 +63,16 @@ export class FileStorage { let current = 0; const token = await this.tokenManager.getAccessToken(); const total = files.length; - const group = this.groups.downloads.get(groupId) || new Set(); + + if (this.groups.downloads.has(groupId)) { + logger.debug("[queueDownloads] group already exists", { + groupId + }); + return this.groups.downloads.get(groupId); + } + + const group = new Set(); + files.forEach((f) => group.add(f.filename)); this.groups.downloads.set(groupId, group); @@ -143,7 +152,16 @@ export class FileStorage { let current = 0; const token = await this.tokenManager.getAccessToken(); const total = files.length; - const group = this.groups.uploads.get(groupId) || new Set(); + + if (this.groups.uploads.has(groupId)) { + logger.debug("[queueUploads] group already exists", { + groupId + }); + return this.groups.uploads.get(groupId); + } + + const group = new Set(); + files.forEach((f) => group.add(f.filename)); this.groups.uploads.set(groupId, group);