diff --git a/enterprise b/enterprise index c5465c9579..51fe0a48eb 160000 --- a/enterprise +++ b/enterprise @@ -1 +1 @@ -Subproject commit c5465c95792004409e0eaa7342171e1cd652914a +Subproject commit 51fe0a48eb11c7d67da6d598820b06d7d30bf8e9 diff --git a/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt index 5e5e45ffb9..8eb4184fec 100644 --- a/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt +++ b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt @@ -23,7 +23,7 @@ interface EnterpriseService { * Override the brand color. * @param brandColor the color in hex format (#RRGGBBAA or #RRGGBB), or null to reset to default. */ - fun overrideBrandColor(brandColor: String?) + suspend fun overrideBrandColor(brandColor: String?) @Composable fun semanticColorsLight(): State diff --git a/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt b/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt index 6251a0b4e6..924a9aec26 100644 --- a/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt +++ b/features/enterprise/impl-foss/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt @@ -32,7 +32,7 @@ class DefaultEnterpriseService : EnterpriseService { override fun defaultHomeserverList(): List = emptyList() override suspend fun isAllowedToConnectToHomeserver(homeserverUrl: String) = true - override fun overrideBrandColor(brandColor: String?) = Unit + override suspend fun overrideBrandColor(brandColor: String?) = Unit @Composable override fun semanticColorsLight(): State { diff --git a/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt b/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt index f2e597c6fa..04aa9dd640 100644 --- a/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt +++ b/features/enterprise/test/src/main/kotlin/io/element/android/features/enterprise/test/FakeEnterpriseService.kt @@ -42,7 +42,7 @@ class FakeEnterpriseService( isAllowedToConnectToHomeserverResult(homeserverUrl) } - override fun overrideBrandColor(brandColor: String?) { + override suspend fun overrideBrandColor(brandColor: String?) = simulateLongTask { overrideBrandColorResult(brandColor) } diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenter.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenter.kt index 85aadbb06b..9ed2abe609 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenter.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenter.kt @@ -135,7 +135,7 @@ class DeveloperSettingsPresenter( } appPreferencesStore.setTracingLogPacks(currentPacks) } - is DeveloperSettingsEvents.ChangeBrandColor -> { + is DeveloperSettingsEvents.ChangeBrandColor -> coroutineScope.launch { showColorPicker = false val color = event.color?.value?.toHexString(HexFormat.UpperCase)?.substring(2, 8) enterpriseService.overrideBrandColor(color) diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt index f13d5b3cd8..593b54f077 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/developer/DeveloperSettingsPresenterTest.kt @@ -203,6 +203,7 @@ class DeveloperSettingsPresenterTest { assertThat(awaitItem().showColorPicker).isTrue() initialState.eventSink(DeveloperSettingsEvents.ChangeBrandColor(Color.Green)) assertThat(awaitItem().showColorPicker).isFalse() + skipItems(1) overrideBrandColorResult.assertions().isCalledOnce() .with(value("00FF00")) } diff --git a/libraries/session-storage/api/src/main/kotlin/io/element/android/libraries/sessionstorage/api/SessionStore.kt b/libraries/session-storage/api/src/main/kotlin/io/element/android/libraries/sessionstorage/api/SessionStore.kt index 9d9f143e15..96d6c4a68e 100644 --- a/libraries/session-storage/api/src/main/kotlin/io/element/android/libraries/sessionstorage/api/SessionStore.kt +++ b/libraries/session-storage/api/src/main/kotlin/io/element/android/libraries/sessionstorage/api/SessionStore.kt @@ -73,3 +73,15 @@ fun List.toUserList(): List { fun Flow>.toUserListFlow(): Flow> { return map { it.toUserList() } } + +/** + * @return a flow emitting the userId of the latest session if logged in, null otherwise. + */ +fun SessionStore.userIdFlow(): Flow { + return loggedInStateFlow().map { + when (it) { + is LoggedInState.LoggedIn -> it.sessionId + is LoggedInState.NotLoggedIn -> null + } + } +} diff --git a/libraries/wellknown/api/src/main/kotlin/io/element/android/libraries/wellknown/api/ElementWellKnown.kt b/libraries/wellknown/api/src/main/kotlin/io/element/android/libraries/wellknown/api/ElementWellKnown.kt index 064416eec1..6f1384422c 100644 --- a/libraries/wellknown/api/src/main/kotlin/io/element/android/libraries/wellknown/api/ElementWellKnown.kt +++ b/libraries/wellknown/api/src/main/kotlin/io/element/android/libraries/wellknown/api/ElementWellKnown.kt @@ -11,4 +11,5 @@ data class ElementWellKnown( val registrationHelperUrl: String?, val enforceElementPro: Boolean?, val rageshakeUrl: String?, + val brandColor: String?, ) diff --git a/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/InternalElementWellKnown.kt b/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/InternalElementWellKnown.kt index e81d78d498..2a0ba1ee72 100644 --- a/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/InternalElementWellKnown.kt +++ b/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/InternalElementWellKnown.kt @@ -27,4 +27,6 @@ data class InternalElementWellKnown( val enforceElementPro: Boolean? = null, @SerialName("rageshake_url") val rageshakeUrl: String? = null, + @SerialName("brand_color") + val brandColor: String? = null, ) diff --git a/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/Mapper.kt b/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/Mapper.kt index 9c1618f699..169757caa9 100644 --- a/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/Mapper.kt +++ b/libraries/wellknown/impl/src/main/kotlin/io/element/android/libraries/wellknown/impl/Mapper.kt @@ -15,6 +15,7 @@ internal fun InternalElementWellKnown.map() = ElementWellKnown( registrationHelperUrl = registrationHelperUrl, enforceElementPro = enforceElementPro, rageshakeUrl = rageshakeUrl, + brandColor = brandColor, ) internal fun InternalWellKnown.map() = WellKnown( diff --git a/libraries/wellknown/impl/src/test/kotlin/io/element/android/libraries/wellknown/impl/DefaultSessionWellknownRetrieverTest.kt b/libraries/wellknown/impl/src/test/kotlin/io/element/android/libraries/wellknown/impl/DefaultSessionWellknownRetrieverTest.kt index d19530befb..9356648a3a 100644 --- a/libraries/wellknown/impl/src/test/kotlin/io/element/android/libraries/wellknown/impl/DefaultSessionWellknownRetrieverTest.kt +++ b/libraries/wellknown/impl/src/test/kotlin/io/element/android/libraries/wellknown/impl/DefaultSessionWellknownRetrieverTest.kt @@ -161,6 +161,7 @@ class DefaultSessionWellknownRetrieverTest { registrationHelperUrl = null, enforceElementPro = null, rageshakeUrl = null, + brandColor = null, ) ) getUrlLambda.assertions().isCalledOnce() @@ -175,7 +176,8 @@ class DefaultSessionWellknownRetrieverTest { """{ "registration_helper_url": "a_registration_url", "enforce_element_pro": true, - "rageshake_url": "a_rageshake_url" + "rageshake_url": "a_rageshake_url", + "brand_color": "#FF0000" }""".trimIndent().toByteArray() ) } @@ -185,6 +187,7 @@ class DefaultSessionWellknownRetrieverTest { registrationHelperUrl = "a_registration_url", enforceElementPro = true, rageshakeUrl = "a_rageshake_url", + brandColor = "#FF0000", ) ) } @@ -208,6 +211,7 @@ class DefaultSessionWellknownRetrieverTest { registrationHelperUrl = "a_registration_url", enforceElementPro = true, rageshakeUrl = "a_rageshake_url", + brandColor = null, ) ) } diff --git a/libraries/wellknown/test/src/main/kotlin/io/element/android/features/wellknown/test/Fixtures.kt b/libraries/wellknown/test/src/main/kotlin/io/element/android/features/wellknown/test/Fixtures.kt index 686026b78d..26eedc7cde 100644 --- a/libraries/wellknown/test/src/main/kotlin/io/element/android/features/wellknown/test/Fixtures.kt +++ b/libraries/wellknown/test/src/main/kotlin/io/element/android/features/wellknown/test/Fixtures.kt @@ -13,8 +13,10 @@ fun anElementWellKnown( registrationHelperUrl: String? = null, enforceElementPro: Boolean? = null, rageshakeUrl: String? = null, + brandColor: String? = null, ) = ElementWellKnown( registrationHelperUrl = registrationHelperUrl, enforceElementPro = enforceElementPro, rageshakeUrl = rageshakeUrl, + brandColor = brandColor, )