Skip to content

Commit 2662948

Browse files
fix: Revert "refactor: Decouple impacted folder ids computation in thread algo deleted uids handling (#2203)" (#2216)
2 parents 2d46dde + 6913618 commit 2662948

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class FolderController @Inject constructor(
105105
}
106106

107107
private fun MutableRealm.deleteOutdatedFolders(mailbox: Mailbox, remoteFolders: List<Folder>) {
108+
/**
109+
* This list is reversed because we'll delete items while looping over it.
110+
* Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item.
111+
* Looping in reverse enables us to not skip any item.
112+
*/
108113
getFolders(exceptionsFoldersIds = remoteFolders.map { it.id }, realm = this).asReversed().forEach { folder ->
109114
deleteLocalFolder(mailbox, folder)
110115
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ class MessageController @Inject constructor(private val mailboxContentRealm: Rea
229229
}
230230

231231
fun deleteMessages(context: Context, mailbox: Mailbox, messages: List<Message>, realm: MutableRealm) {
232+
/**
233+
* This list is reversed because we'll delete items while looping over it.
234+
* Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item.
235+
* Looping in reverse enables us to not skip any item.
236+
*/
232237
messages.asReversed().forEach { message ->
233238
deleteMessage(context, mailbox, message, realm)
234239
}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,12 @@ class RefreshController @Inject constructor(
452452

453453
val message = MessageController.getMessage(uid = shortUid.toLongUid(folderId), realm = this) ?: return@forEach
454454

455-
message.threads.forEach { thread ->
455+
/**
456+
* This list is reversed because we'll delete items while looping over it.
457+
* Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item.
458+
* Looping in reverse enables us to not skip any item.
459+
*/
460+
message.threads.asReversed().forEach { thread ->
456461
scope.ensureActive()
457462

458463
val isSuccess = thread.messages.remove(message)

app/src/main/java/com/infomaniak/mail/workers/DraftsActionsWorker.kt

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class DraftsActionsWorker @AssistedInject constructor(
139139

140140
var haveAllDraftsSucceeded = true
141141

142+
/**
143+
* This list is reversed because we'll delete items while looping over it.
144+
* Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item.
145+
* Looping in reverse enables us to not skip any item.
146+
*/
142147
drafts.asReversed().forEach { draft ->
143148

144149
val isTargetDraft = draft.localUuid == draftLocalUuid

0 commit comments

Comments
 (0)