Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove user scoped shared pref and store all feature flags in the metadata user DB table #2235

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading