Skip to content

Commit dcafc65

Browse files
refactor: Directly delete Messages in Realm, it will automatically remove them from their Threads (#2217)
2 parents c7e12ae + dc42f54 commit dcafc65

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -449,21 +449,8 @@ class RefreshController @Inject constructor(
449449

450450
shortUids.forEach { shortUid ->
451451
scope.ensureActive()
452-
453452
val message = MessageController.getMessage(uid = shortUid.toLongUid(folderId), realm = this) ?: return@forEach
454-
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 ->
461-
scope.ensureActive()
462-
463-
val isSuccess = thread.messages.remove(message)
464-
if (isSuccess) threads += thread
465-
}
466-
453+
threads += message.threads
467454
MessageController.deleteMessage(appContext, mailbox, message, realm = this)
468455
}
469456

0 commit comments

Comments
 (0)