From 91c2b37c5b86662f875e91aebf60f799baf7dfac Mon Sep 17 00:00:00 2001 From: boris Date: Fri, 29 Sep 2023 11:51:08 +0300 Subject: [PATCH] feat: SystemMessage about MLS verified conversation (#2104) --- .../wire/kalium/logic/data/message/Message.kt | 8 ++++++++ .../kalium/logic/data/message/MessageContent.kt | 8 ++++++-- .../kalium/logic/data/message/MessageMapper.kt | 8 ++++++++ .../logic/data/message/PersistMessageUseCase.kt | 2 ++ ...SConversationsVerificationStatusesHandler.kt | 9 +++++---- ...versationsVerificationStatusesHandlerTest.kt | 2 +- .../persistence/dao/message/MessageEntity.kt | 11 +++++++---- .../dao/message/MessageInsertExtension.kt | 17 ++++++++++++++--- .../persistence/dao/message/MessageMapper.kt | 4 ++++ 9 files changed, 55 insertions(+), 14 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt index 4b38f1b116f..d3a8cd5b66e 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt @@ -321,10 +321,18 @@ sealed interface Message { typeKey to "conversationDegradedMLS" ) + is MessageContent.ConversationVerifiedMLS -> mutableMapOf( + typeKey to "conversationVerifiedMLS" + ) + is MessageContent.ConversationDegradedProteus -> mutableMapOf( typeKey to "conversationDegradedProteus" ) + is MessageContent.ConversationVerifiedProteus -> mutableMapOf( + typeKey to "conversationVerifiedProteus" + ) + is MessageContent.FederationStopped.ConnectionRemoved -> mutableMapOf( typeKey to "federationConnectionRemoved" ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt index 262f3cac210..f73707d7f18 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt @@ -291,8 +291,10 @@ sealed class MessageContent { object HistoryLost : System() object ConversationCreated : System() - object ConversationDegradedMLS : System() - object ConversationDegradedProteus : System() + data object ConversationDegradedMLS : System() + data object ConversationVerifiedMLS : System() + data object ConversationDegradedProteus : System() + data object ConversationVerifiedProteus : System() sealed class FederationStopped : System() { data class Removed(val domain: String) : FederationStopped() data class ConnectionRemoved(val domainList: List) : FederationStopped() @@ -344,6 +346,8 @@ fun MessageContent?.getType() = when (this) { is MessageContent.FederationStopped.ConnectionRemoved -> "Federation.ConnectionRemoved" is MessageContent.FederationStopped.Removed -> "Federation.Removed" is MessageContent.Unknown -> "Unknown" + MessageContent.ConversationVerifiedMLS -> "ConversationVerification.Verified.MLS" + MessageContent.ConversationVerifiedProteus -> "ConversationVerification.Verified.Proteus" null -> "null" } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt index 51a78eaf794..dd01e37ca91 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt @@ -200,6 +200,7 @@ class MessageMapperImpl( message.id, message.date ) + else -> LocalNotificationMessage.SelfDeleteMessage( message.id, message.date @@ -257,6 +258,8 @@ class MessageMapperImpl( MessageEntity.ContentType.CONVERSATION_DEGRADED_PREOTEUS -> null MessageEntity.ContentType.COMPOSITE -> null MessageEntity.ContentType.FEDERATION -> null + MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS -> null + MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS -> null } } @@ -362,7 +365,9 @@ class MessageMapperImpl( is MessageEntityContent.ConversationCreated -> MessageContent.ConversationCreated is MessageEntityContent.MLSWrongEpochWarning -> MessageContent.MLSWrongEpochWarning is MessageEntityContent.ConversationDegradedMLS -> MessageContent.ConversationDegradedMLS + is MessageEntityContent.ConversationVerifiedMLS -> MessageContent.ConversationVerifiedMLS is MessageEntityContent.ConversationDegradedProteus -> MessageContent.ConversationDegradedProteus + is MessageEntityContent.ConversationVerifiedProteus -> MessageContent.ConversationVerifiedProteus is MessageEntityContent.Federation -> when (type) { MessageEntity.FederationType.DELETE -> MessageContent.FederationStopped.Removed(domainList.first()) MessageEntity.FederationType.CONNECTION_REMOVED -> MessageContent.FederationStopped.ConnectionRemoved(domainList) @@ -576,4 +581,7 @@ fun MessageContent.System.toMessageEntityContent(): MessageEntityContent.System listOf(domain), MessageEntity.FederationType.DELETE ) + + MessageContent.ConversationVerifiedMLS -> MessageEntityContent.ConversationVerifiedMLS + MessageContent.ConversationVerifiedProteus -> MessageEntityContent.ConversationVerifiedProteus } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/PersistMessageUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/PersistMessageUseCase.kt index 9399d6d8b81..c414067bf3e 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/PersistMessageUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/PersistMessageUseCase.kt @@ -98,7 +98,9 @@ internal class PersistMessageUseCaseImpl( is MessageContent.ConversationCreated -> false is MessageContent.MLSWrongEpochWarning -> false MessageContent.ConversationDegradedMLS -> false + MessageContent.ConversationVerifiedMLS -> false MessageContent.ConversationDegradedProteus -> false + MessageContent.ConversationVerifiedProteus -> false is MessageContent.Composite -> true is MessageContent.ButtonAction -> false is MessageContent.ButtonActionConfirmation -> false diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandler.kt index 87b30e6defd..b1e2b0b314e 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandler.kt @@ -64,8 +64,8 @@ internal class MLSConversationsVerificationStatusesHandlerImpl( conversationRepository.updateVerificationStatus(newStatus, conversation.conversation.id) - if (newStatus == VerificationStatus.DEGRADED) { - notifyUserAboutStateChanges(conversation.conversation.id, VerificationStatus.DEGRADED) + if (newStatus == VerificationStatus.DEGRADED || newStatus == VerificationStatus.VERIFIED) { + notifyUserAboutStateChanges(conversation.conversation.id, newStatus) } } @@ -91,8 +91,9 @@ internal class MLSConversationsVerificationStatusesHandlerImpl( conversationId: ConversationId, updatedStatus: VerificationStatus ) { - // TODO notify about verified too - val content = MessageContent.ConversationDegradedMLS + val content = if (updatedStatus == VerificationStatus.VERIFIED) MessageContent.ConversationVerifiedMLS + else MessageContent.ConversationDegradedMLS + val conversationDegradedMessage = Message.System( id = uuid4().toString(), content = content, diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandlerTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandlerTest.kt index 1339f37fdec..5df85b87b0a 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandlerTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/MLSConversationsVerificationStatusesHandlerTest.kt @@ -168,7 +168,7 @@ class MLSConversationsVerificationStatusesHandlerTest { verify(arrangement.persistMessageUseCase) .suspendFunction(arrangement.persistMessageUseCase::invoke) .with(anyInstanceOf(Message.System::class)) - .wasNotInvoked() + .wasInvoked(once) } private fun arrange(block: Arrangement.() -> Unit) = Arrangement(block).arrange() diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt index 0ff002cd6d3..69519e305d9 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt @@ -47,6 +47,7 @@ sealed interface MessageEntity { val isSelfMessage: Boolean val expireAfterMs: Long? val selfDeletionStartDate: Instant? + data class Regular( override val id: String, override val conversationId: QualifiedIDEntity, @@ -190,8 +191,8 @@ sealed interface MessageEntity { TEXT, ASSET, KNOCK, MEMBER_CHANGE, MISSED_CALL, RESTRICTED_ASSET, CONVERSATION_RENAMED, UNKNOWN, FAILED_DECRYPTION, REMOVED_FROM_TEAM, CRYPTO_SESSION_RESET, NEW_CONVERSATION_RECEIPT_MODE, CONVERSATION_RECEIPT_MODE_CHANGED, HISTORY_LOST, CONVERSATION_MESSAGE_TIMER_CHANGED, - CONVERSATION_CREATED, MLS_WRONG_EPOCH_WARNING, CONVERSATION_DEGRADED_MLS, CONVERSATION_DEGRADED_PREOTEUS, - COMPOSITE, FEDERATION + CONVERSATION_CREATED, MLS_WRONG_EPOCH_WARNING, CONVERSATION_DEGRADED_MLS, CONVERSATION_DEGRADED_PREOTEUS, CONVERSATION_VERIFIED_MLS, + CONVERSATION_VERIFIED_PREOTEUS, COMPOSITE, FEDERATION } enum class MemberChangeType { @@ -326,8 +327,10 @@ sealed class MessageEntityContent { data class ConversationMessageTimerChanged(val messageTimer: Long?) : System() object HistoryLost : System() object ConversationCreated : System() - object ConversationDegradedMLS : System() - object ConversationDegradedProteus : System() + data object ConversationDegradedMLS : System() + data object ConversationVerifiedMLS : System() + data object ConversationDegradedProteus : System() + data object ConversationVerifiedProteus : System() data class Federation(val domainList: List, val type: MessageEntity.FederationType) : System() } diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageInsertExtension.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageInsertExtension.kt index 16e4751f17c..c8890069539 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageInsertExtension.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageInsertExtension.kt @@ -231,10 +231,18 @@ internal class MessageInsertExtensionImpl( /* no-op */ } + is MessageEntityContent.ConversationVerifiedMLS -> { + /* no-op */ + } + is MessageEntityContent.ConversationDegradedProteus -> { /* no-op */ } + is MessageEntityContent.ConversationVerifiedProteus -> { + /* no-op */ + } + is MessageEntityContent.Federation -> { messagesQueries.insertFederationTerminatedMessage( message_id = message.id, @@ -292,12 +300,13 @@ internal class MessageInsertExtensionImpl( is MessageEntityContent.MemberChange, is MessageEntityContent.NewConversationReceiptMode, is MessageEntityContent.Federation, + MessageEntityContent.ConversationDegradedMLS, + MessageEntityContent.ConversationVerifiedMLS, + MessageEntityContent.ConversationDegradedProteus, + MessageEntityContent.ConversationVerifiedProteus, is MessageEntityContent.TeamMemberRemoved -> { /* no-op */ } - - MessageEntityContent.ConversationDegradedMLS -> TODO() - MessageEntityContent.ConversationDegradedProteus -> TODO() } } } @@ -383,5 +392,7 @@ internal class MessageInsertExtensionImpl( is MessageEntityContent.ConversationDegradedProteus -> MessageEntity.ContentType.CONVERSATION_DEGRADED_PREOTEUS is MessageEntityContent.Composite -> MessageEntity.ContentType.COMPOSITE is MessageEntityContent.Federation -> MessageEntity.ContentType.FEDERATION + MessageEntityContent.ConversationVerifiedMLS -> MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS + MessageEntityContent.ConversationVerifiedProteus -> MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS } } diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt index 5f20dff6abb..09d876a112b 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt @@ -202,6 +202,8 @@ object MessageMapper { MessageEntity.ContentType.UNKNOWN -> MessagePreviewEntityContent.Unknown MessageEntity.ContentType.FAILED_DECRYPTION -> MessagePreviewEntityContent.Unknown MessageEntity.ContentType.CRYPTO_SESSION_RESET -> MessagePreviewEntityContent.CryptoSessionReset + MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS -> MessagePreviewEntityContent.Unknown + MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS -> MessagePreviewEntityContent.Unknown } } @@ -561,6 +563,8 @@ object MessageMapper { MessageEntity.ContentType.MLS_WRONG_EPOCH_WARNING -> MessageEntityContent.MLSWrongEpochWarning MessageEntity.ContentType.CONVERSATION_DEGRADED_MLS -> MessageEntityContent.ConversationDegradedMLS MessageEntity.ContentType.CONVERSATION_DEGRADED_PREOTEUS -> MessageEntityContent.ConversationDegradedProteus + MessageEntity.ContentType.CONVERSATION_VERIFIED_MLS -> MessageEntityContent.ConversationVerifiedMLS + MessageEntity.ContentType.CONVERSATION_VERIFIED_PREOTEUS -> MessageEntityContent.ConversationVerifiedProteus MessageEntity.ContentType.FEDERATION -> MessageEntityContent.Federation( domainList = federationDomainList.requireField("federationDomainList"), type = federationType.requireField("federationType")