Skip to content

Commit

Permalink
fix: Revert "refactor: Decouple impacted folder ids computation in th…
Browse files Browse the repository at this point in the history
…read algo deleted uids handling (#2203)" (#2216)
  • Loading branch information
KevinBoulongne authored Mar 5, 2025
2 parents 2d46dde + 6913618 commit 2662948
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class FolderController @Inject constructor(
}

private fun MutableRealm.deleteOutdatedFolders(mailbox: Mailbox, remoteFolders: List<Folder>) {
/**
* This list is reversed because we'll delete items while looping over it.
* Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item.
* Looping in reverse enables us to not skip any item.
*/
getFolders(exceptionsFoldersIds = remoteFolders.map { it.id }, realm = this).asReversed().forEach { folder ->
deleteLocalFolder(mailbox, folder)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ class MessageController @Inject constructor(private val mailboxContentRealm: Rea
}

fun deleteMessages(context: Context, mailbox: Mailbox, messages: List<Message>, realm: MutableRealm) {
/**
* This list is reversed because we'll delete items while looping over it.
* Doing so for managed Realm objects will lively update the list we're iterating through, making us skip the next item.
* Looping in reverse enables us to not skip any item.
*/
messages.asReversed().forEach { message ->
deleteMessage(context, mailbox, message, realm)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,12 @@ class RefreshController @Inject constructor(

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

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

val isSuccess = thread.messages.remove(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class DraftsActionsWorker @AssistedInject constructor(

var haveAllDraftsSucceeded = true

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

val isTargetDraft = draft.localUuid == draftLocalUuid
Expand Down

0 comments on commit 2662948

Please sign in to comment.