Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AutoAdvance feature that was triggering too often #2056

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MainViewModel @Inject constructor(
val canInstallUpdate = MutableLiveData(false)
val messageOfUserToBlock = SingleLiveEvent<Message>()

val autoAdvanceThreadsUids = MutableLiveData<List<String>>()
val autoAdvanceThreadsUids = SingleLiveEvent<List<String>>()

val mailboxesLive = mailboxController.getMailboxesAsync(AccountUtils.currentUserId).asLiveData(ioCoroutineContext)

Expand Down Expand Up @@ -1150,12 +1150,11 @@ class MainViewModel @Inject constructor(

private fun shouldAutoAdvance(message: Message?, threadsUids: List<String>): 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)) {
Expand Down
Loading