Skip to content

Commit

Permalink
feat: Update conversation Proteus verification status (WPB-1789) (#2157)
Browse files Browse the repository at this point in the history
* feat: Update conversation Proteus verification status

* Code style fix

* Fix code stlye again

* Fixed test models

* Fixed test models

* Review fixes

* feat: Update conversation Proteus verification status: modev as much as possible to DB level

* Reverted useles changes

* Fixed test

* Fixed DB migration
  • Loading branch information
borichellow authored Oct 27, 2023
1 parent 2fb391f commit 07301bd
Show file tree
Hide file tree
Showing 36 changed files with 413 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ internal class ConnectionDataSource(
userMessageTimer = null,
archived = false,
archivedInstant = null,
verificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED
mlsVerificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

package com.wire.kalium.logic.data.conversation

import com.wire.kalium.logic.data.conversation.Conversation.Access
import com.wire.kalium.logic.data.conversation.Conversation.AccessRole
import com.wire.kalium.logic.data.conversation.Conversation.ProtocolInfo
import com.wire.kalium.logic.data.conversation.Conversation.ReceiptMode
import com.wire.kalium.logic.data.conversation.Conversation.Type
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.GroupID
import com.wire.kalium.logic.data.id.PlainId
Expand Down Expand Up @@ -71,7 +76,8 @@ data class Conversation(
val userMessageTimer: Duration?,
val archived: Boolean,
val archivedDateTime: Instant?,
val verificationStatus: VerificationStatus
val mlsVerificationStatus: VerificationStatus,
val proteusVerificationStatus: VerificationStatus
) {

companion object {
Expand Down Expand Up @@ -268,7 +274,6 @@ data class Conversation(
"role" to "$role"
)
}

}

sealed class ConversationDetails(open val conversation: Conversation) {
Expand Down Expand Up @@ -327,7 +332,8 @@ sealed class ConversationDetails(open val conversation: Conversation) {
userMessageTimer = null,
archived = false,
archivedDateTime = null,
verificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ internal class ConversationMapperImpl(
hasIncompleteMetadata = false,
archived = apiModel.members.self.otrArchived ?: false,
archivedInstant = apiModel.members.self.otrArchivedRef?.toInstant(),
verificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED
mlsVerificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED
)

override fun fromDaoModel(daoModel: ConversationViewEntity): Conversation = with(daoModel) {
Expand All @@ -147,7 +148,8 @@ internal class ConversationMapperImpl(
userMessageTimer = userMessageTimer?.toDuration(DurationUnit.MILLISECONDS),
archived = archived,
archivedDateTime = archivedDateTime,
verificationStatus = verificationStatusFromEntity(verificationStatus)
mlsVerificationStatus = verificationStatusFromEntity(mlsVerificationStatus),
proteusVerificationStatus = verificationStatusFromEntity(proteusVerificationStatus)
)
}

Expand All @@ -173,7 +175,8 @@ internal class ConversationMapperImpl(
userMessageTimer = userMessageTimer?.toDuration(DurationUnit.MILLISECONDS),
archived = archived,
archivedDateTime = archivedInstant,
verificationStatus = verificationStatusFromEntity(verificationStatus)
mlsVerificationStatus = verificationStatusFromEntity(mlsVerificationStatus),
proteusVerificationStatus = verificationStatusFromEntity(proteusVerificationStatus)
)
}

Expand Down Expand Up @@ -371,7 +374,8 @@ internal class ConversationMapperImpl(
userMessageTimer = userMessageTimer?.inWholeMilliseconds,
archived = archived,
archivedInstant = archivedDateTime,
verificationStatus = verificationStatusToEntity(verificationStatus)
mlsVerificationStatus = verificationStatusToEntity(mlsVerificationStatus),
proteusVerificationStatus = verificationStatusToEntity(proteusVerificationStatus)
)
}

Expand Down Expand Up @@ -400,7 +404,8 @@ internal class ConversationMapperImpl(
hasIncompleteMetadata = true,
archived = false,
archivedInstant = null,
verificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED
mlsVerificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = ConversationEntity.VerificationStatus.NOT_VERIFIED
)

private fun ConversationResponse.getProtocolInfo(mlsGroupState: GroupState?): ProtocolInfo {
Expand Down Expand Up @@ -451,6 +456,7 @@ internal class ConversationMapperImpl(

override fun verificationStatusToEntity(verificationStatus: Conversation.VerificationStatus) =
ConversationEntity.VerificationStatus.valueOf(verificationStatus.name)

}

private fun ConversationEntity.Type.fromDaoModelToType(): Conversation.Type = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import com.wire.kalium.logger.KaliumLogger.Companion.ApplicationFlow.CONVERSATIO
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.data.conversation.Conversation.ProtocolInfo.MLSCapable.GroupState
import com.wire.kalium.logic.data.client.MLSClientProvider
import com.wire.kalium.logic.data.conversation.Conversation.ProtocolInfo.MLSCapable.GroupState
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.GroupID
import com.wire.kalium.logic.data.id.IdMapper
Expand Down Expand Up @@ -248,7 +248,7 @@ interface ConversationRepository {
domain: String
): Either<CoreFailure, OneOnOneMembers>

suspend fun updateVerificationStatus(
suspend fun updateMlsVerificationStatus(
verificationStatus: Conversation.VerificationStatus,
conversationID: ConversationId
): Either<CoreFailure, Unit>
Expand Down Expand Up @@ -281,6 +281,7 @@ interface ConversationRepository {
* @return **true** if the protocol was changed or **false** if the protocol was unchanged.
*/
suspend fun updateProtocolLocally(conversationId: ConversationId, protocol: Conversation.Protocol): Either<CoreFailure, Boolean>

}

@Suppress("LongParameterList", "TooManyFunctions", "LargeClass")
Expand Down Expand Up @@ -963,12 +964,12 @@ internal class ConversationDataSource internal constructor(
.mapValues { it.value.toModel() }
}

override suspend fun updateVerificationStatus(
override suspend fun updateMlsVerificationStatus(
verificationStatus: Conversation.VerificationStatus,
conversationID: ConversationId
): Either<CoreFailure, Unit> =
wrapStorageRequest {
conversationDAO.updateVerificationStatus(
conversationDAO.updateMlsVerificationStatus(
conversationMapper.verificationStatusToEntity(verificationStatus),
conversationID.toDao()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,11 @@ sealed interface MessagePreviewContent {

data object Unknown : MessagePreviewContent

sealed class VerificationChanged : MessagePreviewContent {
data object VerifiedMls : VerificationChanged()
data object VerifiedProteus : VerificationChanged()
data object DegradedMls : VerificationChanged()
data object DegradedProteus : VerificationChanged()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ class MessageMapperImpl(
MessageEntity.ContentType.CONVERSATION_CREATED -> null
MessageEntity.ContentType.MLS_WRONG_EPOCH_WARNING -> null
MessageEntity.ContentType.CONVERSATION_DEGRADED_MLS -> null
MessageEntity.ContentType.CONVERSATION_DEGRADED_PREOTEUS -> null
MessageEntity.ContentType.CONVERSATION_DEGRADED_PROTEUS -> null
MessageEntity.ContentType.COMPOSITE -> null
MessageEntity.ContentType.FEDERATION -> null
MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS -> null
MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS -> null
MessageEntity.ContentType.CONVERSATION_VERIFIED_PROTEUS -> null
MessageEntity.ContentType.CONVERSATION_PROTOCOL_CHANGED -> null
MessageEntity.ContentType.CONVERSATION_STARTED_UNVERIFIED_WARNING -> null
}
Expand Down Expand Up @@ -440,6 +440,10 @@ private fun MessagePreviewEntityContent.toMessageContent(): MessagePreviewConten
is MessagePreviewEntityContent.CryptoSessionReset -> MessagePreviewContent.CryptoSessionReset
MessagePreviewEntityContent.Unknown -> MessagePreviewContent.Unknown
is MessagePreviewEntityContent.Composite -> MessagePreviewContent.WithUser.Composite(username = senderName, messageBody = messageBody)
is MessagePreviewEntityContent.ConversationVerifiedMls -> MessagePreviewContent.VerificationChanged.VerifiedMls
is MessagePreviewEntityContent.ConversationVerifiedProteus -> MessagePreviewContent.VerificationChanged.VerifiedProteus
is MessagePreviewEntityContent.ConversationVerificationDegradedMls -> MessagePreviewContent.VerificationChanged.DegradedMls
is MessagePreviewEntityContent.ConversationVerificationDegradedProteus -> MessagePreviewContent.VerificationChanged.DegradedProteus
}

fun AssetTypeEntity.toModel(): AssetType = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ fun WebConversationContent.toConversation(selfUserId: UserId): Conversation? {
userMessageTimer = null,
archived = archivedState ?: false,
archivedDateTime = conversationArchivedTimestamp,
verificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,9 @@ class UserSessionScope internal constructor(
authenticationScope.secondFactorVerificationRepository,
slowSyncRepository,
cachedClientIdClearer,
updateSupportedProtocolsAndResolveOneOnOnes
updateSupportedProtocolsAndResolveOneOnOnes,
conversationRepository,
persistMessage
)
val conversations: ConversationScope by lazy {
ConversationScope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import com.wire.kalium.logic.data.auth.verification.SecondFactorVerificationRepo
import com.wire.kalium.logic.data.client.ClientRepository
import com.wire.kalium.logic.data.client.MLSClientProvider
import com.wire.kalium.logic.data.client.remote.ClientRemoteRepository
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.keypackage.KeyPackageLimitsProvider
import com.wire.kalium.logic.data.keypackage.KeyPackageRepository
import com.wire.kalium.logic.data.logout.LogoutRepository
import com.wire.kalium.logic.data.message.PersistMessageUseCase
import com.wire.kalium.logic.data.notification.PushTokenRepository
import com.wire.kalium.logic.data.prekey.PreKeyRepository
import com.wire.kalium.logic.data.session.SessionRepository
Expand Down Expand Up @@ -68,7 +70,9 @@ class ClientScope @OptIn(DelicateKaliumApi::class) internal constructor(
private val secondFactorVerificationRepository: SecondFactorVerificationRepository,
private val slowSyncRepository: SlowSyncRepository,
private val cachedClientIdClearer: CachedClientIdClearer,
private val updateSupportedProtocolsAndResolveOneOnOnes: UpdateSupportedProtocolsAndResolveOneOnOnesUseCase
private val updateSupportedProtocolsAndResolveOneOnOnes: UpdateSupportedProtocolsAndResolveOneOnOnesUseCase,
private val conversationRepository: ConversationRepository,
private val persistMessage: PersistMessageUseCase
) {
@OptIn(DelicateKaliumApi::class)
val register: RegisterClientUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ internal class MLSConversationsVerificationStatusesHandlerImpl(
}

private suspend fun updateStatusAndNotifyUserIfNeeded(newStatusFromCC: VerificationStatus, conversation: ConversationDetails) {
val currentStatus = conversation.conversation.verificationStatus
val currentStatus = conversation.conversation.mlsVerificationStatus
val newStatus = getActualNewStatus(newStatusFromCC, currentStatus)

if (newStatus == currentStatus) return

conversationRepository.updateVerificationStatus(newStatus, conversation.conversation.id)
conversationRepository.updateMlsVerificationStatus(newStatus, conversation.conversation.id)

if (newStatus == VerificationStatus.DEGRADED || newStatus == VerificationStatus.VERIFIED) {
notifyUserAboutStateChanges(conversation.conversation.id, newStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.wire.kalium.logic.data.user.type.UserType
import com.wire.kalium.logic.feature.call.Call
import com.wire.kalium.logic.feature.call.CallStatus
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.persistence.dao.conversation.ConversationEntity
import io.mockative.Mock
import io.mockative.classOf
import io.mockative.eq
Expand Down Expand Up @@ -153,7 +152,8 @@ class EndCallOnConversationChangeUseCaseTest {
userMessageTimer = null,
archived = false,
archivedDateTime = null,
verificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
)

val otherUser = OtherUser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
fun givenVerifiedConversation_whenVerifiedStatusComes_thenNotingChanged() = runTest {
val conversationDetails = TestConversationDetails.CONVERSATION_GROUP.copy(
conversation = TestConversation.MLS_CONVERSATION.copy(
verificationStatus = Conversation.VerificationStatus.VERIFIED
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED
)
)
val (arrangement, handler) = arrange {
Expand All @@ -58,7 +58,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
advanceUntilIdle()

verify(arrangement.conversationRepository)
.suspendFunction(arrangement.conversationRepository::updateVerificationStatus)
.suspendFunction(arrangement.conversationRepository::updateMlsVerificationStatus)
.with(any(), any())
.wasNotInvoked()

Expand All @@ -81,7 +81,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
advanceUntilIdle()

verify(arrangement.conversationRepository)
.suspendFunction(arrangement.conversationRepository::updateVerificationStatus)
.suspendFunction(arrangement.conversationRepository::updateMlsVerificationStatus)
.with(any(), any())
.wasNotInvoked()

Expand All @@ -95,7 +95,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
fun givenVerifiedConversation_whenNotVerifiedStatusComes_thenStatusSetToDegradedAndSystemMessageAdded() = runTest {
val conversationDetails = TestConversationDetails.CONVERSATION_GROUP.copy(
conversation = TestConversation.MLS_CONVERSATION.copy(
verificationStatus = Conversation.VerificationStatus.VERIFIED
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED
)
)
val (arrangement, handler) = arrange {
Expand All @@ -108,7 +108,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
advanceUntilIdle()

verify(arrangement.conversationRepository)
.suspendFunction(arrangement.conversationRepository::updateVerificationStatus)
.suspendFunction(arrangement.conversationRepository::updateMlsVerificationStatus)
.with(eq(Conversation.VerificationStatus.DEGRADED), eq(conversationDetails.conversation.id))
.wasInvoked(once)

Expand All @@ -122,7 +122,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
fun givenDegradedConversation_whenNotVerifiedStatusComes_thenNothingChanged() = runTest {
val conversationDetails = TestConversationDetails.CONVERSATION_GROUP.copy(
conversation = TestConversation.MLS_CONVERSATION
.copy(verificationStatus = Conversation.VerificationStatus.DEGRADED)
.copy(mlsVerificationStatus = Conversation.VerificationStatus.DEGRADED)
)
val (arrangement, handler) = arrange {
withObserveEpochChanges(flowOf(TestConversation.GROUP_ID))
Expand All @@ -134,7 +134,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
advanceUntilIdle()

verify(arrangement.conversationRepository)
.suspendFunction(arrangement.conversationRepository::updateVerificationStatus)
.suspendFunction(arrangement.conversationRepository::updateMlsVerificationStatus)
.with(any(), any())
.wasNotInvoked()

Expand All @@ -148,7 +148,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
fun givenDegradedConversation_whenVerifiedStatusComes_thenStatusUpdated() = runTest {
val conversationDetails = TestConversationDetails.CONVERSATION_GROUP.copy(
conversation = TestConversation.MLS_CONVERSATION.copy(
verificationStatus = Conversation.VerificationStatus.DEGRADED
mlsVerificationStatus = Conversation.VerificationStatus.DEGRADED
)
)
val (arrangement, handler) = arrange {
Expand All @@ -161,7 +161,7 @@ class MLSConversationsVerificationStatusesHandlerTest {
advanceUntilIdle()

verify(arrangement.conversationRepository)
.suspendFunction(arrangement.conversationRepository::updateVerificationStatus)
.suspendFunction(arrangement.conversationRepository::updateMlsVerificationStatus)
.with(eq(Conversation.VerificationStatus.VERIFIED), eq(conversationDetails.conversation.id))
.wasInvoked(once)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.wire.kalium.logic.data.id.TeamId
import com.wire.kalium.logic.framework.TestConversation
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.sync.SyncManager
import com.wire.kalium.persistence.dao.conversation.ConversationEntity
import io.mockative.Mock
import io.mockative.any
import io.mockative.classOf
Expand Down Expand Up @@ -410,7 +409,8 @@ class UpdateConversationAccessUseCaseTest {
userMessageTimer = null,
archived = false,
archivedDateTime = null,
verificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED
)
}

Expand Down
Loading

0 comments on commit 07301bd

Please sign in to comment.