From 22e3b370e389bacabfb0e474fab349044984e558 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 14 May 2020 17:54:27 +0200 Subject: [PATCH] IntegrationConfig: make preferred non null as we should at least get the default one --- .../session/integrationmanager/IntegrationManager.kt | 9 +++++---- .../android/internal/session/widgets/WidgetURLBuilder.kt | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt index 2adb3378f3..f3a06af929 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt @@ -109,8 +109,8 @@ internal class IntegrationManager @Inject constructor(private val taskExecutor: accountDataDataSource .getLiveAccountDataEvent(UserAccountData.TYPE_WIDGETS) .observeNotNull(lifecycleOwner) { - val integrationManager = it.getOrNull()?.asIntegrationManagerWidgetContent() - val config = integrationManager?.extractIntegrationManagerConfig() + val integrationManagerContent = it.getOrNull()?.asIntegrationManagerWidgetContent() + val config = integrationManagerContent?.extractIntegrationManagerConfig() val accountConfig = currentConfigs.firstOrNull { currentConfig -> currentConfig.kind == IntegrationManagerConfig.Kind.ACCOUNT } @@ -133,8 +133,9 @@ internal class IntegrationManager @Inject constructor(private val taskExecutor: } } - fun getPreferredConfig(): IntegrationManagerConfig? { - return getOrderedConfigs().firstOrNull() + fun getPreferredConfig(): IntegrationManagerConfig { + // This can't be null as we should have at least the default one registered + return getOrderedConfigs().first() } /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetURLBuilder.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetURLBuilder.kt index ae6e570c19..ade827564e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetURLBuilder.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/WidgetURLBuilder.kt @@ -32,7 +32,7 @@ internal class DefaultWidgetURLBuilder @Inject constructor(private val integrati private val stringProvider: StringProvider ) : IntegrationManager.Listener, WidgetURLBuilder { - private var currentConfig: IntegrationManagerConfig? = null + private var currentConfig = integrationManager.getPreferredConfig() private var whiteListedUrls: List = emptyList() fun start() { @@ -53,11 +53,10 @@ internal class DefaultWidgetURLBuilder @Inject constructor(private val integrati if (currentConfig != preferredConfig) { currentConfig = preferredConfig val defaultWhiteList = stringProvider.getStringArray(R.array.integrations_widgets_urls).asList() - whiteListedUrls = when (preferredConfig?.kind) { + whiteListedUrls = when (preferredConfig.kind) { IntegrationManagerConfig.Kind.DEFAULT -> defaultWhiteList IntegrationManagerConfig.Kind.ACCOUNT -> defaultWhiteList + preferredConfig.apiUrl IntegrationManagerConfig.Kind.HOMESERVER -> listOf(preferredConfig.apiUrl) - else -> emptyList() } } }