Skip to content

Commit

Permalink
feat: migration system messages
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel committed Jul 18, 2023
1 parent 01e9fe9 commit f7cdd0d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<User>): UIMessageContent.SystemMessage {
Expand Down Expand Up @@ -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<User>
Expand Down Expand Up @@ -235,6 +243,7 @@ class SystemMessageContentMapper @Inject constructor(

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -367,13 +368,36 @@ 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,
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@
<string name="label_system_message_deactivated">deactivated</string>
<string name="label_system_message_conversation_history_lost">You haven\'t used this device for a while. some messages may not appear here.</string>
<string name="label_system_message_conversation_mls_wrong_epoch_error_handled">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.</string>
<string name="label_system_message_conversation_history_lost_protocol_changed">You didn\'t update your app in time. some messages may not appear here.</string>
<string name="label_system_message_conversation_protocol_changed_proteus">Migration of encryption protocol was canceled.</string>
<string name="label_system_message_conversation_protocol_changed_mixed">Migration of encryption protocol has started. Make sure you all your Wire clients are updated.</string>
<string name="label_system_message_conversation_protocol_changed_mls">Migration of encryption protocol is completed. Wire clients which haven\'t been updated will stop receiving messages.</string>
<string name="label_system_message_receipt_mode_on">on</string>
<string name="label_system_message_receipt_mode_off">off</string>
<string name="label_system_message_conversation_started_by_self">**You** started the conversation</string>
Expand Down
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 163 files

0 comments on commit f7cdd0d

Please sign in to comment.