|
1 | 1 | /* |
2 | 2 | * Infomaniak Mail - Android |
3 | | - * Copyright (C) 2023-2024 Infomaniak Network SA |
| 3 | + * Copyright (C) 2023-2025 Infomaniak Network SA |
4 | 4 | * |
5 | 5 | * This program is free software: you can redistribute it and/or modify |
6 | 6 | * it under the terms of the GNU General Public License as published by |
@@ -188,27 +188,32 @@ class RefreshController @Inject constructor( |
188 | 188 | } |
189 | 189 | } |
190 | 190 |
|
| 191 | + private val FOLDER_ROLES_TO_REFRESH_TOGETHER = setOf( |
| 192 | + FolderRole.INBOX, |
| 193 | + FolderRole.SENT, |
| 194 | + FolderRole.DRAFT, |
| 195 | + FolderRole.SCHEDULED_DRAFTS, |
| 196 | + ) |
| 197 | + |
191 | 198 | private suspend fun Realm.refreshWithRoleConsideration(scope: CoroutineScope): Set<Thread> { |
192 | 199 |
|
193 | 200 | val impactedThreads = refresh(scope, initialFolder) |
194 | 201 | onStop?.invoke() |
195 | 202 | clearCallbacks() |
196 | 203 |
|
197 | | - when (initialFolder.role) { |
198 | | - FolderRole.INBOX -> listOf(FolderRole.SENT, FolderRole.DRAFT, FolderRole.SCHEDULED_DRAFTS) |
199 | | - FolderRole.SENT -> listOf(FolderRole.INBOX, FolderRole.DRAFT, FolderRole.SCHEDULED_DRAFTS) |
200 | | - FolderRole.DRAFT -> listOf(FolderRole.INBOX, FolderRole.SENT, FolderRole.SCHEDULED_DRAFTS) |
201 | | - FolderRole.SCHEDULED_DRAFTS -> listOf(FolderRole.INBOX, FolderRole.SENT, FolderRole.DRAFT) |
202 | | - else -> emptyList() |
203 | | - }.forEach { role -> |
204 | | - scope.ensureActive() |
| 204 | + if (initialFolder.role in FOLDER_ROLES_TO_REFRESH_TOGETHER) { |
| 205 | + for (role in FOLDER_ROLES_TO_REFRESH_TOGETHER) { |
| 206 | + scope.ensureActive() |
| 207 | + |
| 208 | + if (initialFolder.role == role) continue |
205 | 209 |
|
206 | | - runCatching { |
207 | | - FolderController.getFolder(role, realm = this)?.let { |
208 | | - refresh(scope, folder = it) |
| 210 | + runCatching { |
| 211 | + FolderController.getFolder(role, realm = this)?.let { |
| 212 | + refresh(scope, folder = it) |
| 213 | + } |
| 214 | + }.onFailure { |
| 215 | + throw ReturnThreadsException(impactedThreads, exception = it) |
209 | 216 | } |
210 | | - }.onFailure { |
211 | | - throw ReturnThreadsException(impactedThreads, exception = it) |
212 | 217 | } |
213 | 218 | } |
214 | 219 |
|
|
0 commit comments