diff --git a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt index 14e1bb132b0..ec562bd9319 100644 --- a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientModel.kt @@ -69,8 +69,9 @@ enum class DeviceType { Unknown; } -enum class ClientCapability { - LegalHoldImplicitConsent; +sealed class ClientCapability { + data object LegalHoldImplicitConsent : ClientCapability() + data class Unknown(val name: String) : ClientCapability() } data class OtherUserClient( diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientMapper.kt index 57b6d6c4148..f53feb17f5b 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/client/ClientMapper.kt @@ -198,10 +198,12 @@ class ClientMapper( private fun toClientCapabilityDTO(clientCapability: ClientCapability): ClientCapabilityDTO = when (clientCapability) { ClientCapability.LegalHoldImplicitConsent -> ClientCapabilityDTO.LegalHoldImplicitConsent + is ClientCapability.Unknown -> ClientCapabilityDTO.Unknown(clientCapability.name) } private fun fromClientCapabilityDTO(clientCapabilityDTO: ClientCapabilityDTO): ClientCapability = when (clientCapabilityDTO) { ClientCapabilityDTO.LegalHoldImplicitConsent -> ClientCapability.LegalHoldImplicitConsent + is ClientCapabilityDTO.Unknown -> ClientCapability.Unknown(clientCapabilityDTO.name) } fun fromOtherUsersClientsDTO(otherUsersClients: List): List = diff --git a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientRequest.kt b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientRequest.kt index 19021e85746..037cb6b8d16 100644 --- a/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientRequest.kt +++ b/network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientRequest.kt @@ -22,8 +22,14 @@ import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO.Unknown import com.wire.kalium.network.api.authenticated.prekey.PreKeyDTO import com.wire.kalium.network.api.model.MLSPublicKey import com.wire.kalium.network.api.model.UserId +import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder @Serializable data class RegisterClientRequest( @@ -86,12 +92,31 @@ enum class DeviceTypeDTO { } } -@Serializable -enum class ClientCapabilityDTO { +@Serializable(with = ClientCapabilityDTOSerializer::class) +sealed class ClientCapabilityDTO { @SerialName("legalhold-implicit-consent") - LegalHoldImplicitConsent { - override fun toString(): String { - return "legalhold-implicit-consent" + data object LegalHoldImplicitConsent : ClientCapabilityDTO() + data class Unknown(val name: String) : ClientCapabilityDTO() +} + +object ClientCapabilityDTOSerializer : KSerializer { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( + "ClientCapabilityDTO", PrimitiveKind.STRING + ) + + override fun serialize(encoder: Encoder, value: ClientCapabilityDTO) { + when (value) { + is ClientCapabilityDTO.LegalHoldImplicitConsent -> + encoder.encodeString("legalhold-implicit-consent") + is ClientCapabilityDTO.Unknown -> + encoder.encodeString(value.name) + } + } + + override fun deserialize(decoder: Decoder): ClientCapabilityDTO { + return when (val value = decoder.decodeString()) { + "legalhold-implicit-consent" -> ClientCapabilityDTO.LegalHoldImplicitConsent + else -> ClientCapabilityDTO.Unknown(value) } } }