Skip to content

Commit 9a494f9

Browse files
LunarXKevinBoulongne
authored andcommitted
fix: List snooze folder when computing what folder are impacted by an action
1 parent a168ee1 commit 9a494f9

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ import com.infomaniak.mail.R
3030
import com.infomaniak.mail.data.LocalSettings
3131
import com.infomaniak.mail.data.api.ApiRepository
3232
import com.infomaniak.mail.data.cache.RealmDatabase
33-
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
34-
import com.infomaniak.mail.data.cache.mailboxContent.MessageController
35-
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController
33+
import com.infomaniak.mail.data.cache.mailboxContent.*
3634
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshCallbacks
3735
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshMode
38-
import com.infomaniak.mail.data.cache.mailboxContent.ThreadController
3936
import com.infomaniak.mail.data.cache.mailboxInfo.MailboxController
4037
import com.infomaniak.mail.data.cache.mailboxInfo.PermissionsController
4138
import com.infomaniak.mail.data.cache.mailboxInfo.QuotasController
@@ -549,7 +546,8 @@ class MainViewModel @Inject constructor(
549546
threadController.updateIsLocallyMovedOutStatus(threadsUids, hasBeenMovedOut = false)
550547

551548
val undoDestinationId = message?.folderId ?: threads.first().folderId
552-
val undoFoldersIds = (messages.getFoldersIds(exception = undoDestinationId) + trashId).filterNotNull()
549+
val undoFoldersIds = messages.getFoldersIds(exception = undoDestinationId)
550+
if (trashId != null) undoFoldersIds += trashId
553551
showDeleteSnackbar(
554552
apiResponses,
555553
shouldPermanentlyDelete,
@@ -566,7 +564,7 @@ class MainViewModel @Inject constructor(
566564
shouldPermanentlyDelete: Boolean,
567565
message: Message?,
568566
undoResources: List<String>,
569-
undoFoldersIds: List<String>,
567+
undoFoldersIds: ImpactedFolders,
570568
undoDestinationId: String?,
571569
numberOfImpactedThreads: Int,
572570
) {
@@ -605,7 +603,7 @@ class MainViewModel @Inject constructor(
605603

606604
if (apiResponse.isSuccess() && mailbox.uuid == targetMailboxUuid) {
607605
val draftFolderId = folderController.getFolder(FolderRole.DRAFT)!!.id
608-
refreshFoldersAsync(mailbox, listOf(draftFolderId))
606+
refreshFoldersAsync(mailbox, ImpactedFolders(mutableSetOf(draftFolderId)))
609607
}
610608

611609
showDeletedDraftSnackbar(apiResponse)
@@ -623,7 +621,7 @@ class MainViewModel @Inject constructor(
623621
with(ApiRepository.rescheduleDraft(resource, scheduleDate)) {
624622
if (isSuccess()) {
625623
val scheduledDraftsFolderId = folderController.getFolder(FolderRole.SCHEDULED_DRAFTS)!!.id
626-
refreshFoldersAsync(currentMailbox.value!!, listOf(scheduledDraftsFolderId))
624+
refreshFoldersAsync(currentMailbox.value!!, ImpactedFolders(mutableSetOf(scheduledDraftsFolderId)))
627625
} else {
628626
snackbarManager.postValue(title = appContext.getString(translatedError))
629627
}
@@ -642,7 +640,7 @@ class MainViewModel @Inject constructor(
642640

643641
if (apiResponse.isSuccess()) {
644642
val scheduledDraftsFolderId = folderController.getFolder(FolderRole.SCHEDULED_DRAFTS)!!.id
645-
refreshFoldersAsync(mailbox, listOf(scheduledDraftsFolderId))
643+
refreshFoldersAsync(mailbox, ImpactedFolders(mutableSetOf(scheduledDraftsFolderId)))
646644
onSuccess()
647645
} else {
648646
snackbarManager.postValue(title = appContext.getString(apiResponse.translatedError))
@@ -655,7 +653,7 @@ class MainViewModel @Inject constructor(
655653

656654
if (apiResponse.isSuccess()) {
657655
val scheduledDraftsFolderId = folderController.getFolder(FolderRole.SCHEDULED_DRAFTS)!!.id
658-
refreshFoldersAsync(mailbox, listOf(scheduledDraftsFolderId))
656+
refreshFoldersAsync(mailbox, ImpactedFolders(mutableSetOf(scheduledDraftsFolderId)))
659657
}
660658

661659
showUnscheduledDraftSnackbar(apiResponse)
@@ -731,9 +729,11 @@ class MainViewModel @Inject constructor(
731729
null
732730
} else {
733731
val undoDestinationId = message?.folderId ?: threads.first().folderId
732+
val foldersIds = messages.getFoldersIds(exception = undoDestinationId)
733+
foldersIds += destinationFolder.id
734734
UndoData(
735735
resources = apiResponses.mapNotNull { it.data?.undoResource },
736-
foldersIds = messages.getFoldersIds(exception = undoDestinationId) + destinationFolder.id,
736+
foldersIds = foldersIds,
737737
destinationFolderId = undoDestinationId,
738738
)
739739
}
@@ -1111,7 +1111,7 @@ class MainViewModel @Inject constructor(
11111111

11121112
private fun refreshFoldersAsync(
11131113
mailbox: Mailbox,
1114-
messagesFoldersIds: List<String>,
1114+
messagesFoldersIds: ImpactedFolders,
11151115
destinationFolderId: String? = null,
11161116
callbacks: RefreshCallbacks? = null,
11171117
) = viewModelScope.launch(ioCoroutineContext) {

app/src/main/java/com/infomaniak/mail/ui/main/SnackbarManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Infomaniak Mail - Android
3-
* Copyright (C) 2023-2024 Infomaniak Network SA
3+
* Copyright (C) 2023-2025 Infomaniak Network SA
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@ import androidx.fragment.app.FragmentActivity
2323
import com.google.android.material.snackbar.Snackbar
2424
import com.infomaniak.lib.core.utils.SingleLiveEvent
2525
import com.infomaniak.lib.core.utils.SnackbarUtils.showSnackbar
26+
import com.infomaniak.mail.data.cache.mailboxContent.ImpactedFolders
2627
import javax.inject.Inject
2728
import javax.inject.Singleton
2829
import com.infomaniak.lib.core.R as RCore
@@ -91,7 +92,7 @@ class SnackbarManager @Inject constructor() {
9192

9293
data class UndoData(
9394
val resources: List<String>,
94-
val foldersIds: List<String>,
95+
val foldersIds: ImpactedFolders,
9596
val destinationFolderId: String?,
9697
)
9798
}

app/src/main/java/com/infomaniak/mail/utils/SharedUtils.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.infomaniak.mail.R
2424
import com.infomaniak.mail.data.LocalSettings
2525
import com.infomaniak.mail.data.api.ApiRepository
2626
import com.infomaniak.mail.data.cache.RealmDatabase
27+
import com.infomaniak.mail.data.cache.mailboxContent.ImpactedFolders
2728
import com.infomaniak.mail.data.cache.mailboxContent.MessageController
2829
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController
2930
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshCallbacks
@@ -111,22 +112,23 @@ class SharedUtils @Inject constructor(
111112

112113
suspend fun refreshFolders(
113114
mailbox: Mailbox,
114-
messagesFoldersIds: List<String>,
115+
messagesFoldersIds: ImpactedFolders,
115116
destinationFolderId: String? = null,
116117
currentFolderId: String? = null,
117118
callbacks: RefreshCallbacks? = null,
118119
) {
120+
val realm = mailboxContentRealm()
119121

120122
// We always want to refresh the `destinationFolder` last, to avoid any blink on the UI.
121-
val foldersIds = messagesFoldersIds.toMutableSet()
123+
val foldersIds = messagesFoldersIds.getFolderIds(realm).toMutableSet()
122124
destinationFolderId?.let(foldersIds::add)
123125

124126
foldersIds.forEach { folderId ->
125127
refreshController.refreshThreads(
126128
refreshMode = RefreshMode.REFRESH_FOLDER,
127129
mailbox = mailbox,
128130
folderId = folderId,
129-
realm = mailboxContentRealm(),
131+
realm = realm,
130132
callbacks = if (folderId == currentFolderId) callbacks else null,
131133
)
132134
}

app/src/main/java/com/infomaniak/mail/utils/extensions/Extensions.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ import com.infomaniak.mail.MainApplication
7878
import com.infomaniak.mail.R
7979
import com.infomaniak.mail.data.LocalSettings.ThreadDensity
8080
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
81+
import com.infomaniak.mail.data.cache.mailboxContent.ImpactedFolders
8182
import com.infomaniak.mail.data.models.Attachment
8283
import com.infomaniak.mail.data.models.Folder
8384
import com.infomaniak.mail.data.models.Folder.FolderRole
85+
import com.infomaniak.mail.data.models.SnoozeState
8486
import com.infomaniak.mail.data.models.correspondent.Correspondent
8587
import com.infomaniak.mail.data.models.correspondent.MergedContact
8688
import com.infomaniak.mail.data.models.correspondent.Recipient
@@ -416,7 +418,22 @@ fun List<Folder>.addDividerBeforeFirstCustomFolder(dividerType: Any): List<Any>
416418
//endregion
417419

418420
//region Messages
419-
fun List<Message>.getFoldersIds(exception: String? = null) = mapNotNull { if (it.folderId == exception) null else it.folderId }
421+
fun List<Message>.getFoldersIds(exception: String? = null): ImpactedFolders {
422+
val impactedFolders = ImpactedFolders()
423+
424+
forEach { message ->
425+
when {
426+
message.folderId == exception -> Unit
427+
message.snoozeState == SnoozeState.Snoozed -> {
428+
impactedFolders += message.folderId
429+
impactedFolders += FolderRole.SNOOZED
430+
}
431+
else -> impactedFolders += message.folderId
432+
}
433+
}
434+
435+
return impactedFolders
436+
}
420437

421438
fun List<Message>.getUids(): List<String> = map { it.uid }
422439
//endregion

0 commit comments

Comments
 (0)