diff --git a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/MessageController.kt b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/MessageController.kt index 6743edd946..0135cb26c2 100644 --- a/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/MessageController.kt +++ b/app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/MessageController.kt @@ -143,11 +143,8 @@ class MessageController @Inject constructor(private val mailboxContentRealm: Rea return getMessagesQuery(messageUid, mailboxContentRealm()).first().asFlow() } - fun getMessageCountInThreadForFolder(threadUid: String, folderId: String, realm: Realm): Long? { - return ThreadController.getThread(threadUid, realm) - ?.messages?.query("${Message::folderId.name} == $0", folderId) - ?.count() - ?.find() + fun getMessagesCountInThread(threadUid: String, realm: Realm): Int? { + return ThreadController.getThread(threadUid, realm)?.messages?.count() } //endregion diff --git a/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt b/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt index 83ee47bafa..75c77bfa8b 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt @@ -121,7 +121,7 @@ class MainViewModel @Inject constructor( val canInstallUpdate = MutableLiveData(false) val messageOfUserToBlock = SingleLiveEvent() - val autoAdvanceThreadsUids = MutableLiveData>() + val autoAdvanceThreadsUids = SingleLiveEvent>() val mailboxesLive = mailboxController.getMailboxesAsync(AccountUtils.currentUserId).asLiveData(ioCoroutineContext) @@ -1150,12 +1150,11 @@ class MainViewModel @Inject constructor( private fun shouldAutoAdvance(message: Message?, threadsUids: List): Boolean { val isWorkingWithThread = message == null - return isWorkingWithThread || threadHasOnlyOneMessageLeftInCurrentFolder(threadsUids.first()) + return isWorkingWithThread || threadHasOnlyOneMessageLeft(threadsUids.first()) } - private fun threadHasOnlyOneMessageLeftInCurrentFolder(threadUid: String): Boolean { - val folderId = currentFolderId ?: return false - return messageController.getMessageCountInThreadForFolder(threadUid, folderId, mailboxContentRealm()) == 1L + private fun threadHasOnlyOneMessageLeft(threadUid: String): Boolean { + return messageController.getMessagesCountInThread(threadUid, mailboxContentRealm()) == 1 } fun shareThreadUrl(messageUid: String, startShareActivity: ((String) -> Unit)) {