Skip to content

Commit fd45aec

Browse files
authored
refactor: Avoid duplicating values when defining what folders need to refresh together (#2156)
2 parents 890bf16 + 1507fb3 commit fd45aec

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshController.kt

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Infomaniak Mail - Android
3-
* Copyright (C) 2023-2024 Infomaniak Network SA
3+
* Copyright (C) 2023-2025 Infomaniak Network SA
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -188,27 +188,32 @@ class RefreshController @Inject constructor(
188188
}
189189
}
190190

191+
private val FOLDER_ROLES_TO_REFRESH_TOGETHER = setOf(
192+
FolderRole.INBOX,
193+
FolderRole.SENT,
194+
FolderRole.DRAFT,
195+
FolderRole.SCHEDULED_DRAFTS,
196+
)
197+
191198
private suspend fun Realm.refreshWithRoleConsideration(scope: CoroutineScope): Set<Thread> {
192199

193200
val impactedThreads = refresh(scope, initialFolder)
194201
onStop?.invoke()
195202
clearCallbacks()
196203

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
205209

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)
209216
}
210-
}.onFailure {
211-
throw ReturnThreadsException(impactedThreads, exception = it)
212217
}
213218
}
214219

0 commit comments

Comments
 (0)