Skip to content

Commit

Permalink
refactor: mls feature config handling (#2114)
Browse files Browse the repository at this point in the history
* refactor: mls feature config handling

* chore: remove debug println

* chore: use named arguments for better readability

* refactor: extract handlers into variables and re-use them
  • Loading branch information
typfel authored Oct 6, 2023
1 parent 0e23c25 commit fc867fa
Show file tree
Hide file tree
Showing 34 changed files with 970 additions and 766 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package com.wire.kalium.logic.configuration

import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.data.featureConfig.AppLockConfigModel
import com.wire.kalium.logic.data.featureConfig.MLSMigrationModel
import com.wire.kalium.logic.data.featureConfig.toEntity
import com.wire.kalium.logic.data.featureConfig.toModel
import com.wire.kalium.logic.data.user.SupportedProtocol
import com.wire.kalium.logic.data.user.toDao
import com.wire.kalium.logic.data.user.toModel
Expand Down Expand Up @@ -62,6 +65,8 @@ interface UserConfigRepository {
fun snoozeE2EINotification(duration: Duration): Either<StorageFailure, Unit>
fun setDefaultProtocol(protocol: SupportedProtocol): Either<StorageFailure, Unit>
fun getDefaultProtocol(): Either<StorageFailure, SupportedProtocol>
suspend fun setSupportedProtocols(protocols: Set<SupportedProtocol>): Either<StorageFailure, Unit>
suspend fun getSupportedProtocols(): Either<StorageFailure, Set<SupportedProtocol>>
fun setConferenceCallingEnabled(enabled: Boolean): Either<StorageFailure, Unit>
fun isConferenceCallingEnabled(): Either<StorageFailure, Boolean>
fun setSecondFactorPasswordChallengeStatus(isRequired: Boolean): Either<StorageFailure, Unit>
Expand All @@ -85,6 +90,8 @@ interface UserConfigRepository {
suspend fun observeTeamSettingsSelfDeletingStatus(): Flow<Either<StorageFailure, TeamSettingsSelfDeletionStatus>>
fun observeE2EINotificationTime(): Flow<Either<StorageFailure, Instant?>>
fun setE2EINotificationTime(instant: Instant): Either<StorageFailure, Unit>
suspend fun getMigrationConfiguration(): Either<StorageFailure, MLSMigrationModel>
suspend fun setMigrationConfiguration(configuration: MLSMigrationModel): Either<StorageFailure, Unit>
}

@Suppress("TooManyFunctions")
Expand Down Expand Up @@ -197,6 +204,11 @@ class UserConfigDataSource(
override fun getDefaultProtocol(): Either<StorageFailure, SupportedProtocol> =
wrapStorageRequest { userConfigStorage.defaultProtocol().toModel() }

override suspend fun setSupportedProtocols(protocols: Set<SupportedProtocol>): Either<StorageFailure, Unit> =
wrapStorageRequest { userConfigDAO.setSupportedProtocols(protocols.toDao()) }

override suspend fun getSupportedProtocols(): Either<StorageFailure, Set<SupportedProtocol>> =
wrapStorageRequest { userConfigDAO.getSupportedProtocols()?.toModel() }
override fun setConferenceCallingEnabled(enabled: Boolean): Either<StorageFailure, Unit> =
wrapStorageRequest {
userConfigStorage.persistConferenceCalling(enabled)
Expand Down Expand Up @@ -310,4 +322,14 @@ class UserConfigDataSource(
}
}
}

override suspend fun getMigrationConfiguration(): Either<StorageFailure, MLSMigrationModel> =
wrapStorageRequest {
userConfigDAO.getMigrationConfiguration()?.toModel()
}

override suspend fun setMigrationConfiguration(configuration: MLSMigrationModel): Either<StorageFailure, Unit> =
wrapStorageRequest {
userConfigDAO.setMigrationConfiguration(configuration.toEntity())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.wire.kalium.logic.data.featureConfig.ClassifiedDomainsModel
import com.wire.kalium.logic.data.featureConfig.ConferenceCallingModel
import com.wire.kalium.logic.data.featureConfig.ConfigsStatusModel
import com.wire.kalium.logic.data.featureConfig.E2EIModel
import com.wire.kalium.logic.data.featureConfig.MLSMigrationModel
import com.wire.kalium.logic.data.featureConfig.MLSModel
import com.wire.kalium.logic.data.featureConfig.SelfDeletingMessagesModel
import com.wire.kalium.logic.data.id.ConversationId
Expand Down Expand Up @@ -526,6 +527,21 @@ sealed class Event(open val id: String, open val transient: Boolean, open val li
)
}

data class MLSMigrationUpdated(
override val id: String,
override val transient: Boolean,
override val live: Boolean,
val model: MLSMigrationModel
) : FeatureConfig(id, transient, live) {
override fun toLogMap(): Map<String, Any?> = mapOf(
typeKey to "FeatureConfig.MLSUpdated",
idKey to id.obfuscateId(),
featureStatusKey to model.status.name,
"startTime" to model.startTime,
"endTime" to model.endTime
)
}

data class ClassifiedDomainsUpdated(
override val id: String,
override val transient: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ class EventMapper(
featureConfigMapper.fromDTO(featureConfigUpdatedDTO.data as FeatureConfigData.MLS)
)

is FeatureConfigData.MLSMigration -> Event.FeatureConfig.MLSMigrationUpdated(
id,
transient,
live,
featureConfigMapper.fromDTO(featureConfigUpdatedDTO.data as FeatureConfigData.MLSMigration)
)

is FeatureConfigData.ClassifiedDomains -> Event.FeatureConfig.ClassifiedDomainsUpdated(
id,
transient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.wire.kalium.network.api.base.authenticated.featureConfigs.FeatureConf
import com.wire.kalium.network.api.base.authenticated.featureConfigs.FeatureConfigResponse
import com.wire.kalium.network.api.base.authenticated.featureConfigs.FeatureFlagStatusDTO
import com.wire.kalium.network.api.base.authenticated.featureConfigs.MLSMigrationConfigDTO
import com.wire.kalium.persistence.config.MLSMigrationEntity

interface FeatureConfigMapper {
fun fromDTO(featureConfigResponse: FeatureConfigResponse): FeatureConfigModel
Expand Down Expand Up @@ -152,3 +153,17 @@ class FeatureConfigMapperImpl : FeatureConfigMapper {
fromModel(model.status)
)
}

fun MLSMigrationModel.toEntity(): MLSMigrationEntity =
MLSMigrationEntity(
status = status.equals(Status.ENABLED),
startTime = startTime,
endTime = endTime
)

fun MLSMigrationEntity.toModel(): MLSMigrationModel =
MLSMigrationModel(
status = if (status) Status.ENABLED else Status.DISABLED,
startTime = startTime,
endTime = endTime
)

This file was deleted.

Loading

0 comments on commit fc867fa

Please sign in to comment.