From 6070ca27b6c3c5bd8e6d6621c6a67ad152698536 Mon Sep 17 00:00:00 2001 From: Jacob Persson <7156+typfel@users.noreply.github.com> Date: Thu, 22 Jun 2023 13:45:49 +0200 Subject: [PATCH] feat: migration system messages --- .../mapper/SystemMessageContentMapper.kt | 16 +++++++++++-- .../wire/android/migration/MigrationMapper.kt | 7 ++++-- .../home/conversations/SystemMessageItem.kt | 6 +++++ .../ui/home/conversations/model/UIMessage.kt | 24 ++++++++++++++++++- app/src/main/res/values/strings.xml | 4 ++++ kalium | 2 +- 6 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt b/app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt index d86127f0034..e3a8069782f 100644 --- a/app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt +++ b/app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt @@ -58,9 +58,11 @@ class SystemMessageContentMapper @Inject constructor( is MessageContent.NewConversationReceiptMode -> mapNewConversationReceiptMode(content) is MessageContent.ConversationReceiptModeChanged -> mapConversationReceiptModeChanged(message.senderUserId, content, members) is MessageContent.HistoryLost -> mapConversationHistoryLost() + is MessageContent.HistoryLostProtocolChanged -> mapConverationHistoryListProtocolChanged() is MessageContent.ConversationMessageTimerChanged -> mapConversationTimerChanged(message.senderUserId, content, members) is MessageContent.ConversationCreated -> mapConversationCreated(message.senderUserId, message.date, members) is MessageContent.MLSWrongEpochWarning -> mapMLSWrongEpochWarning() + is MessageContent.ConversationProtocolChanged -> mapConversationProtocolChanged(content) } private fun mapConversationCreated(senderUserId: UserId, date: String, userList: List): UIMessageContent.SystemMessage { @@ -101,6 +103,12 @@ class SystemMessageContentMapper @Inject constructor( } } + private fun mapConversationProtocolChanged( + content: MessageContent.ConversationProtocolChanged + ): UIMessageContent.SystemMessage { + return UIMessageContent.SystemMessage.ConversationProtocolChanged(content.protocol) + } + private fun mapResetSession( senderUserId: UserId, userList: List @@ -233,8 +241,12 @@ class SystemMessageContentMapper @Inject constructor( return memberNameList } - private fun mapConversationHistoryLost(): UIMessageContent.SystemMessage = UIMessageContent.SystemMessage.HistoryLost() - private fun mapMLSWrongEpochWarning(): UIMessageContent.SystemMessage = UIMessageContent.SystemMessage.MLSWrongEpochWarning() + private fun mapConversationHistoryLost(): UIMessageContent.SystemMessage = + UIMessageContent.SystemMessage.HistoryLost() + private fun mapMLSWrongEpochWarning(): UIMessageContent.SystemMessage = + UIMessageContent.SystemMessage.MLSWrongEpochWarning() + private fun mapConverationHistoryListProtocolChanged(): UIMessageContent.SystemMessage = + UIMessageContent.SystemMessage.HistoryLostProtocolChanged() fun mapMemberName(user: User?, type: SelfNameType = SelfNameType.NameOrDeleted): UIText = when (user) { is OtherUser -> user.name?.let { UIText.DynamicString(it) } ?: UIText.StringResource(messageResourceProvider.memberNameDeleted) is SelfUser -> when (type) { diff --git a/app/src/main/kotlin/com/wire/android/migration/MigrationMapper.kt b/app/src/main/kotlin/com/wire/android/migration/MigrationMapper.kt index d3a6e5f90b8..e4f3bc1b37c 100644 --- a/app/src/main/kotlin/com/wire/android/migration/MigrationMapper.kt +++ b/app/src/main/kotlin/com/wire/android/migration/MigrationMapper.kt @@ -39,6 +39,7 @@ import com.wire.kalium.logic.data.user.ConnectionState import com.wire.kalium.logic.data.user.OtherUser import com.wire.kalium.logic.data.user.SelfUser import com.wire.kalium.logic.data.user.SsoId +import com.wire.kalium.logic.data.user.SupportedProtocol import com.wire.kalium.logic.data.user.UserAvailabilityStatus import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.data.user.type.UserType @@ -200,7 +201,8 @@ class MigrationMapper @Inject constructor() { connectionStatus = ConnectionState.ACCEPTED, previewPicture = scalaUserData.pictureAssetId?.let { toQualifiedId(it, scalaUserData.domain, selfuser) }, completePicture = scalaUserData.pictureAssetId?.let { toQualifiedId(it, scalaUserData.domain, selfuser) }, - availabilityStatus = mapUserAvailabilityStatus(scalaUserData.availability) + availabilityStatus = mapUserAvailabilityStatus(scalaUserData.availability), + supportedProtocols = setOf(SupportedProtocol.PROTEUS) ) } else { val botService = @@ -227,7 +229,8 @@ class MigrationMapper @Inject constructor() { userType = userType, availabilityStatus = mapUserAvailabilityStatus(scalaUserData.availability), botService = botService, - deleted = scalaUserData.deleted + deleted = scalaUserData.deleted, + supportedProtocols = setOf(SupportedProtocol.PROTEUS) ) } } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/SystemMessageItem.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/SystemMessageItem.kt index ce5aa4edf11..1e01860085f 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/SystemMessageItem.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/SystemMessageItem.kt @@ -226,7 +226,9 @@ private fun getColorFilter(message: SystemMessage): ColorFilter? { is SystemMessage.TeamMemberRemoved, is SystemMessage.ConversationReceiptModeChanged, is SystemMessage.HistoryLost, + is SystemMessage.HistoryLostProtocolChanged, is SystemMessage.NewConversationReceiptMode, + is SystemMessage.ConversationProtocolChanged, is SystemMessage.ConversationMessageTimerActivated, is SystemMessage.ConversationMessageCreated, is SystemMessage.ConversationStartedWithMembers, @@ -381,6 +383,8 @@ private val SystemMessage.expandable is SystemMessage.ConversationReceiptModeChanged -> false is SystemMessage.Knock -> false is SystemMessage.HistoryLost -> false + is SystemMessage.HistoryLostProtocolChanged -> false + is SystemMessage.ConversationProtocolChanged -> false is SystemMessage.ConversationMessageTimerActivated -> false is SystemMessage.ConversationMessageTimerDeactivated -> false is SystemMessage.ConversationMessageCreated -> false @@ -444,6 +448,8 @@ fun SystemMessage.annotatedString( is SystemMessage.Knock -> arrayOf(author.asString(res)) is SystemMessage.HistoryLost -> arrayOf() is SystemMessage.MLSWrongEpochWarning -> arrayOf() + is SystemMessage.HistoryLostProtocolChanged -> arrayOf() + is SystemMessage.ConversationProtocolChanged -> arrayOf() is SystemMessage.ConversationMessageTimerActivated -> arrayOf( author.asString(res), selfDeletionDuration.longLabel.asString(res) diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt index 7f1fb105b35..5c569d83c0a 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt @@ -31,6 +31,7 @@ import com.wire.android.ui.home.messagecomposer.SelfDeletionDuration import com.wire.android.util.ui.UIText import com.wire.android.util.uiMessageDateTime import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.data.conversation.Conversation import com.wire.kalium.logic.data.message.Message import com.wire.kalium.logic.data.message.MessageContent import com.wire.kalium.logic.data.user.AssetId @@ -367,13 +368,34 @@ sealed class UIMessageContent { } ) - class HistoryLost : SystemMessage(R.drawable.ic_info, R.string.label_system_message_conversation_history_lost, true) class MLSWrongEpochWarning : SystemMessage( iconResId = R.drawable.ic_info, stringResId = R.string.label_system_message_conversation_mls_wrong_epoch_error_handled, isSmallIcon = true ) + data class ConversationProtocolChanged( + val protocol: Conversation.Protocol + ) : SystemMessage( + R.drawable.ic_info, + when (protocol) { + Conversation.Protocol.PROTEUS -> R.string.label_system_message_conversation_protocol_changed_proteus + Conversation.Protocol.MIXED -> R.string.label_system_message_conversation_protocol_changed_mixed + Conversation.Protocol.MLS -> R.string.label_system_message_conversation_protocol_changed_mls + } + ) + + class HistoryLost: SystemMessage( + R.drawable.ic_info, + R.string.label_system_message_conversation_history_lost, + true) + + class HistoryLostProtocolChanged: SystemMessage( + R.drawable.ic_info, + R.string.label_system_message_conversation_history_lost_protocol_changed, + true + ) + data class ConversationMessageCreated( val author: UIText, val isAuthorSelfUser: Boolean = false, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fd28ed4432d..af025a6ba9b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -567,6 +567,10 @@ deactivated You haven\'t used this device for a while. some messages may not appear here. The MLS group key was updated without our knowledge. This could happen due to lost messages between backends, or a bug. We have automatically rejoined the conversation, but you may have lost messages. + You didn\'t update your app in time. some messages may not appear here. + Migration of encryption protocol was canceled. + Migration of encryption protocol has started. Make sure you all your Wire clients are updated. + Migration of encryption protocol is completed. Wire clients which haven\'t been updated will stop receiving messages. on off **You** started the conversation diff --git a/kalium b/kalium index 44aba7e4d1c..5aa0c3e225d 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit 44aba7e4d1cc9792d81d9ce0b81d0378c54a86ff +Subproject commit 5aa0c3e225dd7d4fb87772e94854627509415c5e