-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mls): navigate to migrated conversation [WPB-4705] (#2317)
- Loading branch information
1 parent
080ef10
commit 36b5ef6
Showing
6 changed files
with
200 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...kotlin/com/wire/android/ui/home/conversations/migration/ConversationMigrationViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.home.conversations.migration | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.viewModelScope | ||
import com.wire.android.navigation.SavedStateViewModel | ||
import com.wire.android.ui.home.conversations.ConversationNavArgs | ||
import com.wire.android.ui.navArgs | ||
import com.wire.kalium.logic.data.conversation.ConversationDetails | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.data.id.QualifiedID | ||
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.flow.filterIsInstance | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ConversationMigrationViewModel @Inject constructor( | ||
override val savedStateHandle: SavedStateHandle, | ||
private val observeConversationDetails: ObserveConversationDetailsUseCase | ||
) : SavedStateViewModel(savedStateHandle) { | ||
|
||
/** | ||
* Represents the target conversation, after a conversation migration. | ||
* The target conversation is the active one-on-one conversation ID if the current conversation | ||
* is migrated to a different conversation. | ||
* If this conversation was not migrated to another one, the target conversation is null. | ||
*/ | ||
var migratedConversationId by mutableStateOf<ConversationId?>(null) | ||
private set | ||
|
||
private val conversationNavArgs = savedStateHandle.navArgs<ConversationNavArgs>() | ||
private val conversationId: QualifiedID = conversationNavArgs.conversationId | ||
|
||
init { | ||
viewModelScope.launch { | ||
observeConversationDetails(conversationId) | ||
.filterIsInstance<ObserveConversationDetailsUseCase.Result.Success>() | ||
.map { it.conversationDetails } | ||
.filterIsInstance<ConversationDetails.OneOne>() | ||
.collectLatest { | ||
val activeOneOnOneConversationId = it.otherUser.activeOneOnOneConversationId | ||
val wasThisConversationMigrated = activeOneOnOneConversationId != conversationId | ||
if (wasThisConversationMigrated) { | ||
migratedConversationId = activeOneOnOneConversationId | ||
} | ||
} | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...in/com/wire/android/ui/home/conversations/migration/ConversationMigrationViewModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.home.conversations.migration | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.wire.android.config.CoroutineTestExtension | ||
import com.wire.android.config.NavigationTestExtension | ||
import com.wire.android.framework.TestConversation | ||
import com.wire.android.framework.TestUser | ||
import com.wire.android.ui.home.conversations.ConversationNavArgs | ||
import com.wire.android.ui.navArgs | ||
import com.wire.kalium.logic.data.conversation.ConversationDetails | ||
import com.wire.kalium.logic.data.conversation.LegalHoldStatus | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.data.user.type.UserType | ||
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.amshove.kluent.shouldBe | ||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(CoroutineTestExtension::class) | ||
@ExtendWith(NavigationTestExtension::class) | ||
class ConversationMigrationViewModelTest { | ||
|
||
@Test | ||
fun givenActiveOneOnOneMatchesCurrentConversation_thenMigratedConversationShouldBeNull() = runTest { | ||
val (_, conversationMigrationViewModel) = arrange { | ||
withConversationDetailsReturning( | ||
ConversationDetails.OneOne( | ||
conversation = TestConversation.ONE_ON_ONE, | ||
otherUser = TestUser.OTHER_USER.copy(activeOneOnOneConversationId = conversationId), | ||
legalHoldStatus = LegalHoldStatus.ENABLED, | ||
userType = UserType.NONE, | ||
unreadEventCount = mapOf(), | ||
lastMessage = null | ||
) | ||
) | ||
} | ||
|
||
conversationMigrationViewModel.migratedConversationId shouldBe null | ||
} | ||
|
||
@Test | ||
fun givenActiveOneOnOneDiffersFromCurrentConversation_thenMigratedConversationShouldBeTheOneInDetails() = runTest { | ||
val expectedActiveOneOnOneId = ConversationId("expectedActiveOneOnOneId", "testDomain") | ||
val (_, conversationMigrationViewModel) = arrange { | ||
withConversationDetailsReturning( | ||
ConversationDetails.OneOne( | ||
conversation = TestConversation.ONE_ON_ONE, | ||
otherUser = TestUser.OTHER_USER.copy(activeOneOnOneConversationId = expectedActiveOneOnOneId), | ||
legalHoldStatus = LegalHoldStatus.ENABLED, | ||
userType = UserType.NONE, | ||
unreadEventCount = mapOf(), | ||
lastMessage = null | ||
) | ||
) | ||
} | ||
|
||
conversationMigrationViewModel.migratedConversationId shouldBeEqualTo expectedActiveOneOnOneId | ||
} | ||
|
||
private class Arrangement(private val configure: Arrangement.() -> Unit) { | ||
|
||
@MockK | ||
lateinit var observeConversationDetailsUseCase: ObserveConversationDetailsUseCase | ||
|
||
@MockK | ||
lateinit var savedStateHandle: SavedStateHandle | ||
|
||
init { | ||
MockKAnnotations.init(this) | ||
every { savedStateHandle.navArgs<ConversationNavArgs>() } returns ConversationNavArgs(conversationId) | ||
} | ||
|
||
fun withConversationDetailsReturning(conversationDetails: ConversationDetails) = apply { | ||
coEvery { observeConversationDetailsUseCase(conversationId) } returns | ||
flowOf(ObserveConversationDetailsUseCase.Result.Success(conversationDetails)) | ||
} | ||
|
||
fun arrange(): Pair<Arrangement, ConversationMigrationViewModel> = run { | ||
configure() | ||
this@Arrangement to ConversationMigrationViewModel(savedStateHandle, observeConversationDetailsUseCase) | ||
} | ||
} | ||
|
||
private companion object { | ||
val conversationId = TestConversation.ID | ||
|
||
fun arrange(configure: Arrangement.() -> Unit) = Arrangement(configure).arrange() | ||
} | ||
} |
Submodule kalium
updated
61 files