Skip to content

Commit

Permalink
Ensure Boolean io.element.disable_network_constraint is explicitly …
Browse files Browse the repository at this point in the history
…set in the .well-known file.
  • Loading branch information
bmarty committed Oct 13, 2023
1 parent 7884b9d commit 64a7de5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ data class HomeServerCapabilities(
/**
* If set to true, the SDK will not use the network constraint when configuring Worker for the WorkManager, provided in Wellknown.
*/
val disableNetworkConstraint: Boolean = false,
val disableNetworkConstraint: Boolean? = null,
) {

enum class RoomCapabilitySupport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class MigrateSessionTo054(realm: DynamicRealm) : RealmMigrator(realm, 5
override fun doMigrate(realm: DynamicRealm) {
realm.schema.get("HomeServerCapabilitiesEntity")
?.addField(HomeServerCapabilitiesEntityFields.DISABLE_NETWORK_CONSTRAINT, Boolean::class.java)
?.setNullable(HomeServerCapabilitiesEntityFields.DISABLE_NETWORK_CONSTRAINT, true)
?.forceRefreshOfHomeServerCapabilities()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal open class HomeServerCapabilitiesEntity(
var canRedactEventWithRelations: Boolean = false,
var externalAccountManagementUrl: String? = null,
var authenticationIssuer: String? = null,
var disableNetworkConstraint: Boolean = false,
var disableNetworkConstraint: Boolean? = null,
) : RealmObject() {

companion object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@
package org.matrix.android.sdk.internal.session.workmanager

import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.internal.session.homeserver.HomeServerCapabilitiesDataSource
import javax.inject.Inject

@Suppress("RedundantIf")
internal class DefaultWorkManagerConfig @Inject constructor(
private val credentials: Credentials,
private val homeServerCapabilitiesDataSource: HomeServerCapabilitiesDataSource,
) : WorkManagerConfig {
override fun withNetworkConstraint(): Boolean {
return if (credentials.discoveryInformation?.disableNetworkConstraint == true) {
// Boolean `io.element.disable_network_constraint` explicitly set to `true` in the login response
false
} else if (homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint == true) {
// Boolean `io.element.disable_network_constraint` explicitly set to `true` in the .well-known file
false
} else {
homeServerCapabilitiesDataSource.getHomeServerCapabilities()?.disableNetworkConstraint.orFalse().not()
// Default, use the Network constraint
true
}
}
}

0 comments on commit 64a7de5

Please sign in to comment.