mirror of
https://github.com/ProtonMail/android-mail.git
synced 2026-05-15 09:50:40 +00:00
Split usecase into two entry points
MAILANDR-2566: delete action for spam/trash
This commit is contained in:
+9
-11
@@ -30,18 +30,16 @@ class GetDetailBottomSheetActions @Inject constructor(
|
||||
@CustomizeToolbarFeatureEnabled val isCustomizeToolbarEnabled: Boolean
|
||||
) {
|
||||
|
||||
operator fun invoke(
|
||||
conversation: Conversation?,
|
||||
message: Message,
|
||||
affectingConversation: Boolean
|
||||
): List<Action> {
|
||||
operator fun invoke(conversation: Conversation?, affectingConversation: Boolean): List<Action> {
|
||||
val showDelete = affectingConversation && conversation?.allMessagesAreSpamOrTrash() == true
|
||||
return getActions(showDelete = showDelete, affectingConversation = affectingConversation)
|
||||
}
|
||||
|
||||
operator fun invoke(message: Message): List<Action> =
|
||||
getActions(showDelete = message.isSpamOrTrash(), affectingConversation = false)
|
||||
|
||||
private fun getActions(showDelete: Boolean, affectingConversation: Boolean): List<Action> {
|
||||
val showCustomizeToolbar = isCustomizeToolbarEnabled
|
||||
val showDelete = when {
|
||||
conversation != null -> {
|
||||
affectingConversation && conversation.allMessagesAreSpamOrTrash()
|
||||
}
|
||||
else -> message.isSpamOrTrash()
|
||||
}
|
||||
|
||||
return mutableListOf<Action>().apply {
|
||||
if (!affectingConversation) {
|
||||
|
||||
+10
-10
@@ -62,7 +62,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(false)
|
||||
|
||||
// When
|
||||
val result = sut(null, normalMessage, affectingConversation = false)
|
||||
val result = sut(normalMessage)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -91,7 +91,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(true)
|
||||
|
||||
// When
|
||||
val result = sut(null, normalMessage, affectingConversation = false)
|
||||
val result = sut(normalMessage)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -121,7 +121,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(true)
|
||||
|
||||
// When
|
||||
val result = sut(null, spamMessage, affectingConversation = false)
|
||||
val result = sut(spamMessage)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -151,7 +151,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(false)
|
||||
|
||||
// When
|
||||
val result = sut(null, trashMessage, affectingConversation = false)
|
||||
val result = sut(trashMessage)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -180,7 +180,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(true)
|
||||
|
||||
// When
|
||||
val result = sut(normalConversation, trashMessage, affectingConversation = true)
|
||||
val result = sut(normalConversation, affectingConversation = true)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -205,7 +205,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(true)
|
||||
|
||||
// When
|
||||
val result = sut(trashedConversation, trashMessage, affectingConversation = true)
|
||||
val result = sut(trashedConversation, affectingConversation = true)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -225,12 +225,12 @@ class GetDetailBottomSheetActionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns correct actions for a spam conversation message with toolbar FF enabled`() = runTest {
|
||||
fun `returns correct actions for a spam conversation with toolbar FF enabled`() = runTest {
|
||||
// Given
|
||||
customizeToolbarFeatureEnabled(true)
|
||||
|
||||
// When
|
||||
val result = sut(spamConversation, normalMessage, affectingConversation = true)
|
||||
val result = sut(spamConversation, affectingConversation = true)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -255,7 +255,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(true)
|
||||
|
||||
// When
|
||||
val result = sut(normalConversation, trashMessage, affectingConversation = true)
|
||||
val result = sut(normalConversation, affectingConversation = true)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
@@ -280,7 +280,7 @@ class GetDetailBottomSheetActionsTest {
|
||||
customizeToolbarFeatureEnabled(true)
|
||||
|
||||
// When
|
||||
val result = sut(normalConversation, trashMessage, affectingConversation = false)
|
||||
val result = sut(normalConversation, affectingConversation = false)
|
||||
|
||||
// Then
|
||||
assertEquals(
|
||||
|
||||
+1
-1
@@ -857,7 +857,7 @@ class ConversationDetailViewModel @Inject constructor(
|
||||
|
||||
val actions = getBottomSheetActions(
|
||||
conversation = conversation,
|
||||
affectingConversation = affectingConversation, message = message
|
||||
affectingConversation = affectingConversation
|
||||
)
|
||||
|
||||
val event = ConversationDetailEvent.ConversationBottomSheetEvent(
|
||||
|
||||
+1
-1
@@ -505,7 +505,7 @@ class MessageDetailViewModel @Inject constructor(
|
||||
return@let resolveParticipantName(message.sender, it)
|
||||
}?.name ?: message.sender.name
|
||||
|
||||
val actions = getBottomSheetActions(conversation = null, affectingConversation = false, message = message)
|
||||
val actions = getBottomSheetActions(message = message)
|
||||
|
||||
val event = MessageDetailEvent.MessageBottomSheetEvent(
|
||||
DetailMoreActionsBottomSheetState.MessageDetailMoreActionsBottomSheetEvent.DataLoaded(
|
||||
|
||||
+1
-1
@@ -366,7 +366,7 @@ class ConversationDetailViewModelTest {
|
||||
private val updateCustomizeToolbarSpotlight = mockk<UpdateCustomizeToolbarSpotlight>()
|
||||
|
||||
private val getBottomSheetActions = mockk<GetDetailBottomSheetActions> {
|
||||
every { this@mockk.invoke(any(), any(), any()) } returns listOf(Action.Archive)
|
||||
every { this@mockk.invoke(any(), any()) } returns listOf(Action.Archive)
|
||||
}
|
||||
|
||||
private val testDispatcher: TestDispatcher by lazy {
|
||||
|
||||
+1
-1
@@ -395,7 +395,7 @@ class MessageDetailViewModelTest {
|
||||
private val updateCustomizeToolbarSpotlight = mockk<UpdateCustomizeToolbarSpotlight>()
|
||||
|
||||
private val getBottomSheetActions = mockk<GetDetailBottomSheetActions> {
|
||||
every { this@mockk.invoke(any(), any(), any()) } returns listOf(Action.Archive)
|
||||
every { this@mockk.invoke(any()) } returns listOf(Action.Archive)
|
||||
}
|
||||
|
||||
private val messageDetailReducer = MessageDetailReducer(
|
||||
|
||||
Reference in New Issue
Block a user