Skip to content

Commit

Permalink
refactor: remove user scoped shared pref and store all feature flags …
Browse files Browse the repository at this point in the history
…in the metadata user DB table
  • Loading branch information
MohamadJaara committed Nov 16, 2023
1 parent a6c1110 commit 8bbc90a
Show file tree
Hide file tree
Showing 51 changed files with 1,091 additions and 1,258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ package com.wire.kalium.logic.di
import com.wire.kalium.logic.data.id.toDao
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.persistence.db.PlatformDatabaseData
import com.wire.kalium.persistence.db.UserDatabaseBuilder
import com.wire.kalium.persistence.db.userDatabaseBuilder
import com.wire.kalium.persistence.kmmSettings.UserPrefBuilder
import com.wire.kalium.util.KaliumDispatcherImpl

internal actual class PlatformUserStorageProvider : UserStorageProvider() {
override fun create(userId: UserId, shouldEncryptData: Boolean, platformProperties: PlatformUserStorageProperties): UserStorage {
override fun create(
userId: UserId,
shouldEncryptData: Boolean,
platformProperties: PlatformUserStorageProperties
): UserDatabaseBuilder {
val userIdEntity = userId.toDao()
val pref = UserPrefBuilder(userIdEntity, platformProperties.applicationContext, shouldEncryptData)

val databasePassphrase = if (shouldEncryptData) {
platformProperties.securityHelper.userDBSecret(userId)
Expand All @@ -42,6 +45,6 @@ internal actual class PlatformUserStorageProvider : UserStorageProvider() {
dispatcher = KaliumDispatcherImpl.io,
enableWAL = true
)
return UserStorage(database, pref)
return database
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ import com.wire.kalium.logic.data.id.toDao
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.persistence.db.userDatabaseBuilder
import com.wire.kalium.persistence.db.PlatformDatabaseData
import com.wire.kalium.persistence.kmmSettings.UserPrefBuilder
import com.wire.kalium.persistence.db.UserDatabaseBuilder
import com.wire.kalium.util.KaliumDispatcherImpl

internal actual class PlatformUserStorageProvider actual constructor() : UserStorageProvider() {
override fun create(userId: UserId, shouldEncryptData: Boolean, platformProperties: PlatformUserStorageProperties): UserStorage {
override fun create(
userId: UserId,
shouldEncryptData: Boolean,
platformProperties: PlatformUserStorageProperties
): UserDatabaseBuilder {
val userIdEntity = userId.toDao()
val pref = UserPrefBuilder(userIdEntity, platformProperties.rootPath, shouldEncryptData)

val database = userDatabaseBuilder(
PlatformDatabaseData(platformProperties.rootStoragePath),
userIdEntity,
null,
KaliumDispatcherImpl.io,
true
)
return UserStorage(database, pref)
return database
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.wire.kalium.logic.configuration

import com.wire.kalium.persistence.config.E2EISettingsEntity
import com.wire.kalium.persistence.dao.config.model.E2EISettingsEntity
import kotlinx.datetime.Instant

data class E2EISettings(
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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
import com.wire.kalium.persistence.dao.config.model.MLSMigrationEntity

interface FeatureConfigMapper {
fun fromDTO(featureConfigResponse: FeatureConfigResponse): FeatureConfigModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.wire.kalium.logic.data.message

import com.wire.kalium.persistence.config.SelfDeletionTimerEntity
import com.wire.kalium.persistence.dao.config.model.SelfDeletionTimerEntity

internal object SelfDeletionMapper { // TODO rename and refactor
fun TeamSelfDeleteTimer.toSelfDeletionTimerEntity(): SelfDeletionTimerEntity = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ import co.touchlab.stately.collections.ConcurrentMutableMap
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.util.safeComputeIfAbsent
import com.wire.kalium.persistence.db.UserDatabaseBuilder
import com.wire.kalium.persistence.kmmSettings.UserPrefBuilder

data class UserStorage(val database: UserDatabaseBuilder, val preferences: UserPrefBuilder)
abstract class UserStorageProvider {
private val inMemoryUserStorage: ConcurrentMutableMap<UserId, UserStorage> = ConcurrentMutableMap()
private val inMemoryUserStorage: ConcurrentMutableMap<UserId, UserDatabaseBuilder> = ConcurrentMutableMap()
fun getOrCreate(
userId: UserId,
platformUserStorageProperties: PlatformUserStorageProperties,
shouldEncryptData: Boolean = true
): UserStorage = inMemoryUserStorage.safeComputeIfAbsent(userId) {
): UserDatabaseBuilder = inMemoryUserStorage.safeComputeIfAbsent(userId) {
create(userId, shouldEncryptData, platformUserStorageProperties)
}

protected abstract fun create(
userId: UserId,
shouldEncryptData: Boolean,
platformProperties: PlatformUserStorageProperties
): UserStorage
): UserDatabaseBuilder

fun clearInMemoryUserStorage(userId: UserId) = inMemoryUserStorage.remove(userId)
}
Expand Down
Loading

0 comments on commit 8bbc90a

Please sign in to comment.