Skip to content

Commit

Permalink
refactor: Clean delete Thread function
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Jan 30, 2025
1 parent 021df2f commit eeb2a33
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -503,21 +503,17 @@ class MainViewModel @Inject constructor(
val shouldPermanentlyDelete = isPermanentDeleteFolder(getActionFolderRole(threads, message))

val messages = getMessagesToDelete(threads, message)

val messagesUids = messages.filter { it.isScheduledDraft.not() }.getUids()
val scheduledMessagesUuid = messages.filter { it.isScheduledDraft }.getUids()
val uids = messages.getUids()

threadController.updateIsLocallyMovedOutStatus(threadsUids, hasBeenMovedOut = true)

val apiResponses = if (shouldPermanentlyDelete) {
ApiRepository.deleteMessages(mailbox.uuid, messagesUids)
// TODO: Delete scheduled messages separately, but avoid making too much call (waiting for API changes).
ApiRepository.deleteMessages(mailbox.uuid, uids)
} else {
trashId = folderController.getFolder(FolderRole.TRASH)!!.id
ApiRepository.moveMessages(mailbox.uuid, messagesUids, trashId).also {
ApiRepository.moveMessages(mailbox.uuid, uids, trashId).also {
undoResources = it.mapNotNull { apiResponse -> apiResponse.data?.undoResource }
}
// TODO: Move? scheduled messages separately.
}

deleteThreadOrMessageTrigger.postValue(Unit)
Expand Down

0 comments on commit eeb2a33

Please sign in to comment.