From 17f1c2ae8953456a286738c3120f584fd7e92e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= <30429749+saleniuk@users.noreply.github.com> Date: Mon, 25 Mar 2024 09:58:33 +0100 Subject: [PATCH] feat: legal hold indicator on message headers [WPB-4571] (#2806) --- .../com/wire/android/mapper/MessageMapper.kt | 4 ++-- .../other/OtherUserProfileScreenViewModel.kt | 13 +---------- .../OtherUserProfileScreenViewModelTest.kt | 23 +++++++++++++++---- .../OtherUserProfileViewModelArrangement.kt | 11 --------- kalium | 2 +- 5 files changed, 22 insertions(+), 31 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/mapper/MessageMapper.kt b/app/src/main/kotlin/com/wire/android/mapper/MessageMapper.kt index c9a2928d2a4..4f32ba4a10f 100644 --- a/app/src/main/kotlin/com/wire/android/mapper/MessageMapper.kt +++ b/app/src/main/kotlin/com/wire/android/mapper/MessageMapper.kt @@ -33,13 +33,13 @@ import com.wire.android.ui.home.conversations.model.UIMessage import com.wire.android.ui.home.conversations.model.UIMessageContent import com.wire.android.ui.home.conversations.previewAsset import com.wire.android.ui.home.conversationslist.model.Membership +import com.wire.android.ui.theme.Accent import com.wire.android.util.time.ISOFormatter import com.wire.android.util.ui.UIText import com.wire.android.util.ui.WireSessionImageLoader import com.wire.kalium.logic.data.message.DeliveryStatus import com.wire.kalium.logic.data.message.Message import com.wire.kalium.logic.data.message.MessageContent -import com.wire.android.ui.theme.Accent import com.wire.kalium.logic.data.user.OtherUser import com.wire.kalium.logic.data.user.SelfUser import com.wire.kalium.logic.data.user.User @@ -145,7 +145,7 @@ class MessageMapper @Inject constructor( is SelfUser, null -> Membership.None }, connectionState = getConnectionState(sender), - isLegalHold = false, + isLegalHold = sender?.isUnderLegalHold == true, messageTime = MessageTime(message.date), messageStatus = getMessageStatus(message), messageId = message.id, diff --git a/app/src/main/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModel.kt index 4c137c93c67..4020413f089 100644 --- a/app/src/main/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModel.kt @@ -73,15 +73,12 @@ import com.wire.kalium.logic.feature.e2ei.CertificateStatus import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusResult import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusUseCase import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCase -import com.wire.kalium.logic.feature.legalhold.LegalHoldState -import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForUserUseCase import com.wire.kalium.logic.feature.user.GetUserInfoResult import com.wire.kalium.logic.feature.user.ObserveUserInfoUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow -import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOn @@ -100,7 +97,6 @@ class OtherUserProfileScreenViewModel @Inject constructor( private val unblockUser: UnblockUserUseCase, private val observeOneToOneConversation: GetOneToOneConversationUseCase, private val observeUserInfo: ObserveUserInfoUseCase, - private val observeLegalHoldStateForUser: ObserveLegalHoldStateForUserUseCase, private val userTypeMapper: UserTypeMapper, private val wireSessionImageLoader: WireSessionImageLoader, private val observeConversationRoleForUser: ObserveConversationRoleForUserUseCase, @@ -139,14 +135,6 @@ class OtherUserProfileScreenViewModel @Inject constructor( observeUserInfoAndUpdateViewState() persistClients() getMLSVerificationStatus() - observeLegalHoldStatus() - } - - private fun observeLegalHoldStatus() { - viewModelScope.launch { - observeLegalHoldStateForUser(userId) - .collectLatest { state = state.copy(isUnderLegalHold = it is LegalHoldState.Enabled) } - } } private fun getMLSVerificationStatus() { @@ -401,6 +389,7 @@ class OtherUserProfileScreenViewModel @Inject constructor( botService = otherUser.botService, blockingState = otherUser.BlockState, isProteusVerified = otherUser.isProteusVerified, + isUnderLegalHold = otherUser.isUnderLegalHold, conversationSheetContent = conversation?.let { ConversationSheetContent( title = otherUser.name.orEmpty(), diff --git a/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModelTest.kt index 9250c3228ec..c9ae6d8e030 100644 --- a/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileScreenViewModelTest.kt @@ -40,7 +40,6 @@ import com.wire.kalium.logic.data.user.type.UserType import com.wire.kalium.logic.feature.connection.BlockUserResult import com.wire.kalium.logic.feature.conversation.GetOneToOneConversationUseCase import com.wire.kalium.logic.feature.conversation.UpdateConversationMemberRoleResult -import com.wire.kalium.logic.feature.legalhold.LegalHoldState import com.wire.kalium.logic.feature.user.GetUserInfoResult import io.mockk.Called import io.mockk.coVerify @@ -208,8 +207,15 @@ class OtherUserProfileScreenViewModelTest { fun `given legal hold enabled, then isUnderLegalHold is true`() = runTest { // given val (_, viewModel) = OtherUserProfileViewModelArrangement() - .withUserInfo(GetUserInfoResult.Success(OTHER_USER.copy(connectionStatus = ConnectionState.NOT_CONNECTED), TEAM)) - .withLegalHoldState(LegalHoldState.Enabled) + .withUserInfo( + GetUserInfoResult.Success( + otherUser = OTHER_USER.copy( + connectionStatus = ConnectionState.NOT_CONNECTED, + isUnderLegalHold = true + ), + team = TEAM + ) + ) .arrange() // then assertEquals(true, viewModel.state.isUnderLegalHold) @@ -219,8 +225,15 @@ class OtherUserProfileScreenViewModelTest { fun `given legal hold disabled, then isUnderLegalHold is false`() = runTest { // given val (_, viewModel) = OtherUserProfileViewModelArrangement() - .withUserInfo(GetUserInfoResult.Success(OTHER_USER.copy(connectionStatus = ConnectionState.NOT_CONNECTED), TEAM)) - .withLegalHoldState(LegalHoldState.Disabled) + .withUserInfo( + GetUserInfoResult.Success( + otherUser = OTHER_USER.copy( + connectionStatus = ConnectionState.NOT_CONNECTED, + isUnderLegalHold = false + ), + team = TEAM + ) + ) .arrange() // then assertEquals(false, viewModel.state.isUnderLegalHold) diff --git a/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileViewModelArrangement.kt b/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileViewModelArrangement.kt index cf090fb8556..1729d4aa114 100644 --- a/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileViewModelArrangement.kt +++ b/app/src/test/kotlin/com/wire/android/ui/userprofile/other/OtherUserProfileViewModelArrangement.kt @@ -47,8 +47,6 @@ import com.wire.kalium.logic.feature.e2ei.CertificateStatus import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusResult import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificateStatusUseCase import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCase -import com.wire.kalium.logic.feature.legalhold.LegalHoldState -import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForUserUseCase import com.wire.kalium.logic.feature.user.GetSelfUserUseCase import com.wire.kalium.logic.feature.user.GetUserInfoResult import com.wire.kalium.logic.feature.user.ObserveUserInfoUseCase @@ -69,9 +67,6 @@ internal class OtherUserProfileViewModelArrangement { @MockK lateinit var observeUserInfo: ObserveUserInfoUseCase - @MockK - lateinit var observeLegalHoldStateForUser: ObserveLegalHoldStateForUserUseCase - @MockK lateinit var wireSessionImageLoader: WireSessionImageLoader @@ -125,7 +120,6 @@ internal class OtherUserProfileViewModelArrangement { unblockUser, getOneToOneConversation, observeUserInfo, - observeLegalHoldStateForUser, userTypeMapper, wireSessionImageLoader, observeConversationRoleForUserUseCase, @@ -167,7 +161,6 @@ internal class OtherUserProfileViewModelArrangement { ) coEvery { getUserE2eiCertificateStatus.invoke(any()) } returns GetUserE2eiCertificateStatusResult.Success(CertificateStatus.VALID) coEvery { getUserE2eiCertificates.invoke(any()) } returns mapOf() - coEvery { observeLegalHoldStateForUser.invoke(any()) } returns flowOf(LegalHoldState.Disabled) } suspend fun withBlockUserResult(result: BlockUserResult) = apply { @@ -193,9 +186,5 @@ internal class OtherUserProfileViewModelArrangement { coEvery { observeUserInfo(any()) } returns flowOf(result) } - fun withLegalHoldState(result: LegalHoldState) = apply { - coEvery { observeLegalHoldStateForUser.invoke(any()) } returns flowOf(result) - } - fun arrange() = this to viewModel } diff --git a/kalium b/kalium index f9480981c8e..085e0a4b9c9 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit f9480981c8ec5b1c3004c450449b2e2449335ebe +Subproject commit 085e0a4b9c9ab3a2e9af222f1d997c5221ac8944