Skip to content

Commit a49fe11

Browse files
committed
Avoid using when and revert moveOutlocally everytime
1 parent 1c09c10 commit a49fe11

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

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

+16-20
Original file line numberDiff line numberDiff line change
@@ -503,26 +503,22 @@ class MainViewModel @Inject constructor(
503503

504504
deleteThreadOrMessageTrigger.postValue(Unit)
505505

506-
when {
507-
apiResponses.atLeastOneSucceeded() -> {
508-
if (shouldAutoAdvance(message, threadsUids)) autoAdvanceThreadsUids.postValue(threadsUids)
509-
510-
refreshFoldersAsync(
511-
mailbox = mailbox,
512-
messagesFoldersIds = messages.getFoldersIds(exception = trashId),
513-
destinationFolderId = trashId,
514-
callbacks = RefreshCallbacks(::onDownloadStart, ::onDownloadStop),
515-
)
516-
}
517-
!apiResponses.atLeastOneSucceeded() -> {
518-
threadController.updateIsMovedOutLocally(threadsUids, hasBeenMovedOut = false)
519-
}
520-
isSwipe -> {
521-
// We need to make the swiped Thread come back, so we reassign the LiveData with Realm values
522-
reassignCurrentThreadsLive()
523-
}
506+
if (apiResponses.atLeastOneSucceeded()) {
507+
if (shouldAutoAdvance(message, threadsUids)) autoAdvanceThreadsUids.postValue(threadsUids)
508+
509+
refreshFoldersAsync(
510+
mailbox = mailbox,
511+
messagesFoldersIds = messages.getFoldersIds(exception = trashId),
512+
destinationFolderId = trashId,
513+
callbacks = RefreshCallbacks(onStart = { onDownloadStart() }, onStop = { onDownloadStop(threadsUids) }),
514+
)
515+
} else if (isSwipe) {
516+
// We need to make the swiped Thread come back, so we reassign the LiveData with Realm values
517+
reassignCurrentThreadsLive()
524518
}
525519

520+
threadController.updateIsMovedOutLocally(threadsUids, hasBeenMovedOut = false)
521+
526522
val undoDestinationId = message?.folderId ?: threads.first().folderId
527523
val undoFoldersIds = (messages.getFoldersIds(exception = undoDestinationId) + trashId).filterNotNull()
528524
showDeleteSnackbar(
@@ -618,10 +614,10 @@ class MainViewModel @Inject constructor(
618614
destinationFolderId = destinationFolder.id,
619615
callbacks = RefreshCallbacks(onStart = { onDownloadStart() }, onStop = { onDownloadStop(threadsUids) }),
620616
)
621-
} else {
622-
threadController.updateIsMovedOutLocally(threadsUids, hasBeenMovedOut = false)
623617
}
624618

619+
threadController.updateIsMovedOutLocally(threadsUids, hasBeenMovedOut = false)
620+
625621
showMoveSnackbar(threads, message, messages, apiResponses, destinationFolder)
626622
}
627623

0 commit comments

Comments
 (0)