Add simplified sliding sync toggle to developer options
This commit is contained in:
parent
21553d757a
commit
b9f4403408
13 changed files with 98 additions and 3 deletions
|
|
@ -37,12 +37,13 @@ dependencies {
|
|||
debugImplementation(libs.matrix.sdk)
|
||||
}
|
||||
implementation(projects.appconfig)
|
||||
implementation(projects.libraries.di)
|
||||
implementation(projects.libraries.androidutils)
|
||||
implementation(projects.libraries.di)
|
||||
implementation(projects.libraries.featureflag.api)
|
||||
implementation(projects.libraries.network)
|
||||
implementation(projects.libraries.preferences.api)
|
||||
implementation(projects.services.analytics.api)
|
||||
implementation(projects.services.toolbox.api)
|
||||
implementation(projects.libraries.featureflag.api)
|
||||
api(projects.libraries.matrix.api)
|
||||
implementation(libs.dagger)
|
||||
implementation(projects.libraries.core)
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ import io.element.android.libraries.matrix.impl.util.anonymizedTokens
|
|||
import io.element.android.libraries.matrix.impl.util.cancelAndDestroy
|
||||
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
|
||||
import io.element.android.libraries.matrix.impl.verification.RustSessionVerificationService
|
||||
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
|
@ -126,6 +127,7 @@ class RustMatrixClient(
|
|||
private val baseDirectory: File,
|
||||
baseCacheDirectory: File,
|
||||
private val clock: SystemClock,
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
) : MatrixClient {
|
||||
override val sessionId: UserId = UserId(client.userId())
|
||||
override val deviceId: String = client.deviceId()
|
||||
|
|
@ -554,6 +556,7 @@ class RustMatrixClient(
|
|||
}
|
||||
close()
|
||||
deleteSessionDirectory(deleteCryptoDb = true)
|
||||
appPreferencesStore.setSimplifiedSlidingSyncEnabled(false)
|
||||
if (removeSession) {
|
||||
sessionStore.removeSession(sessionId.value)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ import io.element.android.libraries.matrix.impl.certificates.UserCertificatesPro
|
|||
import io.element.android.libraries.matrix.impl.proxy.ProxyProvider
|
||||
import io.element.android.libraries.matrix.impl.util.anonymizedTokens
|
||||
import io.element.android.libraries.network.useragent.UserAgentProvider
|
||||
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
|
||||
import io.element.android.libraries.sessionstorage.api.SessionData
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.rustcomponents.sdk.ClientBuilder
|
||||
import org.matrix.rustcomponents.sdk.Session
|
||||
|
|
@ -46,9 +48,14 @@ class RustMatrixClientFactory @Inject constructor(
|
|||
private val proxyProvider: ProxyProvider,
|
||||
private val clock: SystemClock,
|
||||
private val utdTracker: UtdTracker,
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
) {
|
||||
suspend fun create(sessionData: SessionData): RustMatrixClient = withContext(coroutineDispatchers.io) {
|
||||
val client = getBaseClientBuilder(sessionData.sessionPath, sessionData.passphrase)
|
||||
val client = getBaseClientBuilder(
|
||||
sessionPath = sessionData.sessionPath,
|
||||
passphrase = sessionData.passphrase,
|
||||
useSimplifiedSlidingSync = appPreferencesStore.isSimplifiedSlidingSyncEnabledFlow().first(),
|
||||
)
|
||||
.homeserverUrl(sessionData.homeserverUrl)
|
||||
.username(sessionData.userId)
|
||||
.use { it.build() }
|
||||
|
|
@ -70,6 +77,7 @@ class RustMatrixClientFactory @Inject constructor(
|
|||
baseDirectory = baseDirectory,
|
||||
baseCacheDirectory = cacheDirectory,
|
||||
clock = clock,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
).also {
|
||||
Timber.tag(it.toString()).d("Creating Client with access token '$anonymizedAccessToken' and refresh token '$anonymizedRefreshToken'")
|
||||
}
|
||||
|
|
@ -79,6 +87,7 @@ class RustMatrixClientFactory @Inject constructor(
|
|||
sessionPath: String,
|
||||
passphrase: String?,
|
||||
slidingSyncProxy: String? = null,
|
||||
useSimplifiedSlidingSync: Boolean = false,
|
||||
): ClientBuilder {
|
||||
return ClientBuilder()
|
||||
.sessionPath(sessionPath)
|
||||
|
|
@ -88,6 +97,7 @@ class RustMatrixClientFactory @Inject constructor(
|
|||
.addRootCertificates(userCertificatesProvider.provides())
|
||||
.autoEnableBackups(true)
|
||||
.autoEnableCrossSigning(true)
|
||||
.simplifiedSlidingSync(useSimplifiedSlidingSync)
|
||||
.run {
|
||||
// Workaround for non-nullable proxy parameter in the SDK, since each call to the ClientBuilder returns a new reference we need to keep
|
||||
proxyProvider.provides()?.let { proxy(it) } ?: this
|
||||
|
|
|
|||
|
|
@ -28,5 +28,8 @@ interface AppPreferencesStore {
|
|||
suspend fun setTheme(theme: String)
|
||||
fun getThemeFlow(): Flow<String?>
|
||||
|
||||
suspend fun setSimplifiedSlidingSyncEnabled(enabled: Boolean)
|
||||
fun isSimplifiedSlidingSyncEnabledFlow(): Flow<Boolean>
|
||||
|
||||
suspend fun reset()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(na
|
|||
private val developerModeKey = booleanPreferencesKey("developerMode")
|
||||
private val customElementCallBaseUrlKey = stringPreferencesKey("elementCallBaseUrl")
|
||||
private val themeKey = stringPreferencesKey("theme")
|
||||
private val simplifiedSlidingSyncKey = booleanPreferencesKey("useSimplifiedSlidingSync")
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class DefaultAppPreferencesStore @Inject constructor(
|
||||
|
|
@ -87,6 +88,18 @@ class DefaultAppPreferencesStore @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun setSimplifiedSlidingSyncEnabled(enabled: Boolean) {
|
||||
store.edit { prefs ->
|
||||
prefs[simplifiedSlidingSyncKey] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
override fun isSimplifiedSlidingSyncEnabledFlow(): Flow<Boolean> {
|
||||
return store.data.map { prefs ->
|
||||
prefs[simplifiedSlidingSyncKey] ?: false
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
store.edit { it.clear() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,12 @@ class InMemoryAppPreferencesStore(
|
|||
isDeveloperModeEnabled: Boolean = false,
|
||||
customElementCallBaseUrl: String? = null,
|
||||
theme: String? = null,
|
||||
simplifiedSlidingSyncEnabled: Boolean = false
|
||||
) : AppPreferencesStore {
|
||||
private val isDeveloperModeEnabled = MutableStateFlow(isDeveloperModeEnabled)
|
||||
private val customElementCallBaseUrl = MutableStateFlow(customElementCallBaseUrl)
|
||||
private val theme = MutableStateFlow(theme)
|
||||
private val simplifiedSlidingSyncEnabled = MutableStateFlow(simplifiedSlidingSyncEnabled)
|
||||
|
||||
override suspend fun setDeveloperModeEnabled(enabled: Boolean) {
|
||||
isDeveloperModeEnabled.value = enabled
|
||||
|
|
@ -53,6 +55,14 @@ class InMemoryAppPreferencesStore(
|
|||
return theme
|
||||
}
|
||||
|
||||
override suspend fun setSimplifiedSlidingSyncEnabled(enabled: Boolean) {
|
||||
simplifiedSlidingSyncEnabled.value = enabled
|
||||
}
|
||||
|
||||
override fun isSimplifiedSlidingSyncEnabledFlow(): Flow<Boolean> {
|
||||
return simplifiedSlidingSyncEnabled
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
// No op
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue