Integration: make the default urls modifiable from MatrixConfiguration

This commit is contained in:
ganfra 2020-06-02 20:05:00 +02:00
parent c815c4080d
commit 173c1d3a6e
5 changed files with 11 additions and 22 deletions

View File

@ -22,6 +22,8 @@ import java.net.Proxy
data class MatrixConfiguration(
val applicationFlavor: String = "Default-application-flavor",
val cryptoConfig: MXCryptoConfig = MXCryptoConfig(),
val integrationUIUrl: String = "https://scalar.vector.im/",
val integrationRestUrl: String = "https://scalar.vector.im/api",
/**
* Optional proxy to connect to the matrix servers
* You can create one using for instance Proxy(proxyType, InetSocketAddress(hostname, port)

View File

@ -20,7 +20,7 @@ package im.vector.matrix.android.api.session.integrationmanager
*/
data class IntegrationManagerConfig(
val uiUrl: String,
val apiUrl: String,
val restUrl: String,
val kind: Kind
) {

View File

@ -20,9 +20,8 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.R
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.auth.wellknown.WellknownResult
import im.vector.matrix.android.api.MatrixConfiguration
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.integrationmanager.IntegrationManagerConfig
import im.vector.matrix.android.api.session.integrationmanager.IntegrationManagerService
@ -31,7 +30,6 @@ import im.vector.matrix.android.api.session.widgets.model.WidgetType
import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.api.util.NoOpCancellable
import im.vector.matrix.android.internal.database.model.WellknownIntegrationManagerConfigEntity
import im.vector.matrix.android.internal.di.UserId
import im.vector.matrix.android.internal.extensions.observeNotNull
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData
@ -43,9 +41,6 @@ import im.vector.matrix.android.internal.session.widgets.helper.extractWidgetSeq
import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.util.StringProvider
import im.vector.matrix.android.internal.util.awaitTransaction
import im.vector.matrix.android.internal.wellknown.GetWellknownTask
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@ -62,14 +57,11 @@ import javax.inject.Inject
*
*/
@SessionScope
internal class IntegrationManager @Inject constructor(@UserId private val userId: String,
internal class IntegrationManager @Inject constructor(matrixConfiguration: MatrixConfiguration,
private val taskExecutor: TaskExecutor,
private val monarchy: Monarchy,
private val stringProvider: StringProvider,
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
private val accountDataDataSource: AccountDataDataSource,
private val getWellknownTask: GetWellknownTask,
private val configExtractor: IntegrationManagerConfigExtractor,
private val widgetFactory: WidgetFactory) {
private val currentConfigs = ArrayList<IntegrationManagerConfig>()
@ -82,8 +74,8 @@ internal class IntegrationManager @Inject constructor(@UserId private val userId
init {
val defaultConfig = IntegrationManagerConfig(
uiUrl = stringProvider.getString(R.string.integrations_ui_url),
apiUrl = stringProvider.getString(R.string.integrations_rest_url),
uiUrl = matrixConfiguration.integrationUIUrl,
restUrl = matrixConfiguration.integrationRestUrl,
kind = IntegrationManagerConfig.Kind.DEFAULT
)
currentConfigs.add(defaultConfig)
@ -259,7 +251,7 @@ internal class IntegrationManager @Inject constructor(@UserId private val userId
val integrationManagerData = data.toModel<IntegrationManagerWidgetData>()
return IntegrationManagerConfig(
uiUrl = url,
apiUrl = integrationManagerData?.apiUrl ?: url,
restUrl = integrationManagerData?.apiUrl ?: url,
kind = IntegrationManagerConfig.Kind.ACCOUNT
)
}

View File

@ -56,8 +56,8 @@ internal class DefaultWidgetURLFormatter @Inject constructor(private val integra
val defaultWhiteList = stringProvider.getStringArray(R.array.integrations_widgets_urls).asList()
whiteListedUrls = when (preferredConfig.kind) {
IntegrationManagerConfig.Kind.DEFAULT -> defaultWhiteList
IntegrationManagerConfig.Kind.ACCOUNT -> defaultWhiteList + preferredConfig.apiUrl
IntegrationManagerConfig.Kind.HOMESERVER -> listOf(preferredConfig.apiUrl)
IntegrationManagerConfig.Kind.ACCOUNT -> defaultWhiteList + preferredConfig.restUrl
IntegrationManagerConfig.Kind.HOMESERVER -> listOf(preferredConfig.restUrl)
}
}
}
@ -67,7 +67,7 @@ internal class DefaultWidgetURLFormatter @Inject constructor(private val integra
*/
override suspend fun format(baseUrl: String, params: Map<String, String>, forceFetchScalarToken: Boolean, bypassWhitelist: Boolean): String {
return if (bypassWhitelist || isWhiteListed(baseUrl)) {
val taskParams = GetScalarTokenTask.Params(currentConfig.apiUrl, forceFetchScalarToken)
val taskParams = GetScalarTokenTask.Params(currentConfig.restUrl, forceFetchScalarToken)
val scalarToken = getScalarTokenTask.execute(taskParams)
buildString {
append(baseUrl)

View File

@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Widget urls -->
<string name="integrations_ui_url" translatable="false">"https://scalar.vector.im/"</string>
<string name="integrations_rest_url" translatable="false">"https://scalar.vector.im/api"</string>
<string name="integrations_jitsi_widget_url" translatable="false">"https://scalar.vector.im/api/widgets/jitsi.html"</string>
<string-array name="integrations_widgets_urls" translatable="false">
<item>https://scalar.vector.im/_matrix/integrations/v1</item>
<item>https://scalar.vector.im/api</item>