Skip to content

Commit

Permalink
feat: harden ClientCapabilityDTO for api v7
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Dec 6, 2024
1 parent 212ddce commit e0e3430
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientEntity>): List<OtherUserClient> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<ClientCapabilityDTO> {
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)
}
}
}
Expand Down

0 comments on commit e0e3430

Please sign in to comment.