refactor: Actions should work with messages not only threads. #2795
refactor: Actions should work with messages not only threads. #2795
Conversation
b10b893 to
5fb3f9e
Compare
b6a55aa to
3548060
Compare
FabianDevel
left a comment
There was a problem hiding this comment.
I'm not sure we should keep the thread in the actionViewModel's function at all.
I believe we have all we need to directly pass the messages list to the functions
For now this feels a bit confusing between the function that accepts threads + messages, and the one that only accept messages but still used for threads too.
app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/MessageController.kt
Show resolved
Hide resolved
app/src/main/java/com/infomaniak/mail/ui/main/folder/PerformSwipeActionManager.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/infomaniak/mail/ui/main/thread/actions/ActionsViewModel.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/infomaniak/mail/ui/main/thread/actions/MultiSelectBottomSheetDialog.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/infomaniak/mail/ui/main/folder/PerformSwipeActionManager.kt
Outdated
Show resolved
Hide resolved
| val updatedSendersRestrictions = data!!.apply { | ||
| blockedSenders.removeIf { it.email == email } | ||
| } |
There was a problem hiding this comment.
Manage the !! with an error snackbar
| //endregion | ||
|
|
||
| //region Move | ||
| fun moveThreadsOrMessagesTo( |
There was a problem hiding this comment.
We should look how to remove this from the mainViewModel also, to avoid having duplicated logic.
| private fun refreshFoldersAsync( | ||
| mailbox: Mailbox, | ||
| messagesFoldersIds: ImpactedFolders, | ||
| currentFolderId: String? = null, | ||
| destinationFolderId: String? = null, | ||
| callbacks: RefreshCallbacks? = null, | ||
| ) = viewModelScope.launch(ioCoroutineContext) { | ||
| sharedUtils.refreshFolders(mailbox, messagesFoldersIds, destinationFolderId, currentFolderId, callbacks) | ||
| } |
There was a problem hiding this comment.
Put this outside the action regions, at the bottom of the class
| fun trySendEmojiReply( | ||
| emoji: String, | ||
| messageUid: String, | ||
| reactions: Map<String, Reaction>, | ||
| hasNetwork: Boolean, | ||
| mailbox: Mailbox, | ||
| onAllowed: () -> Unit = {}, | ||
| ) { | ||
| viewModelScope.launch { | ||
| when (val status = reactions.getEmojiSendStatus(emoji, hasNetwork)) { | ||
| EmojiSendStatus.Allowed -> { | ||
| onAllowed() | ||
| sendEmojiReply(emoji, messageUid, mailbox) | ||
| } | ||
| is EmojiSendStatus.NotAllowed -> snackbarManager.postValue(appContext.getString(status.errorMessageRes)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun Map<String, Reaction>.getEmojiSendStatus(emoji: String, hasNetwork: Boolean): EmojiSendStatus = when { | ||
| this[emoji]?.hasReacted == true -> EmojiSendStatus.NotAllowed.AlreadyUsed | ||
| hasAvailableReactionSlot().not() -> EmojiSendStatus.NotAllowed.MaxReactionReached | ||
| hasNetwork.not() -> EmojiSendStatus.NotAllowed.NoInternet | ||
| else -> EmojiSendStatus.Allowed | ||
| } |
There was a problem hiding this comment.
I think all the emoji stuff should be left out of this viewModel, it's not directly linked to the actions
| if (hasFailedFetching) return | ||
| val draftMode = Draft.DraftMode.REPLY_ALL |
There was a problem hiding this comment.
Add a blank line to separate the early return from the rest of the code
…ck functions to actionsViewModel
3548060 to
96172ac
Compare
|


No description provided.