Skip to content

Commit

Permalink
Merge pull request #2056 from Infomaniak/fix-autoAdvance
Browse files Browse the repository at this point in the history
Fix AutoAdvance feature that was triggering too often
  • Loading branch information
KevinBoulongne authored Sep 27, 2024
2 parents be36a18 + 0466c5f commit e4ca206
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
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

0 comments on commit e4ca206

Please sign in to comment.