Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: legal hold indicator on message headers [WPB-4571] #2806

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/wire/android/mapper/MessageMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,9 +67,6 @@ internal class OtherUserProfileViewModelArrangement {
@MockK
lateinit var observeUserInfo: ObserveUserInfoUseCase

@MockK
lateinit var observeLegalHoldStateForUser: ObserveLegalHoldStateForUserUseCase

@MockK
lateinit var wireSessionImageLoader: WireSessionImageLoader

Expand Down Expand Up @@ -125,7 +120,6 @@ internal class OtherUserProfileViewModelArrangement {
unblockUser,
getOneToOneConversation,
observeUserInfo,
observeLegalHoldStateForUser,
userTypeMapper,
wireSessionImageLoader,
observeConversationRoleForUserUseCase,
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 21 files
+2 −2 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapper.kt
+4 −4 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt
+4 −2 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserMapper.kt
+5 −2 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserModel.kt
+2 −2 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/message/MessageMapperTest.kt
+63 −2 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/user/UserMapperTest.kt
+2 −1 logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestUser.kt
+20 −18 persistence/src/commonMain/db_user/com/wire/kalium/persistence/MessageDetailsView.sq
+5 −1 persistence/src/commonMain/db_user/com/wire/kalium/persistence/Users.sq
+204 −0 persistence/src/commonMain/db_user/migrations/80.sqm
+1 −1 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/ConnectionDAO.kt
+1 −2 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/ConnectionDAOImpl.kt
+2 −1 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/UserDAO.kt
+5 −2 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/UserDAOImpl.kt
+4 −4 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt
+8 −4 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt
+7 −7 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/backup/DatabaseExporterTest.kt
+16 −13 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/message/MessageDAOTest.kt
+4 −0 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/message/MessageMapperTest.kt
+2 −2 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/utils/stubs/MessageStubs.kt
+2 −1 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/utils/stubs/UserStubs.kt
Loading