From f39ed574073e1777fe58c9630150b97f97af0d26 Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Mon, 18 Nov 2024 18:23:55 +0100 Subject: [PATCH] DROID-3075 Spaces | Fix | Active space is no longer available (#1808) --- .../domain/auth/interactor/LaunchAccount.kt | 6 +----- .../anytype/domain/workspace/WorkspaceManager.kt | 15 +++++++++++++++ .../presentation/splash/SplashViewModel.kt | 8 ++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt index 00ad1f261a..9037106303 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/auth/interactor/LaunchAccount.kt @@ -48,11 +48,7 @@ class LaunchAccount @Inject constructor( configStorage.set(config = setup.config) val lastSessionSpace = settings.getCurrentSpace() if (lastSessionSpace != null) { - val result = spaceManager.set(lastSessionSpace.id) - if (result.isFailure) { - // Falling back to the default space - spaceManager.set(setup.config.space) - } + spaceManager.set(lastSessionSpace.id) } awaitAccountStartManager.setState(AwaitAccountStartManager.State.Started) setup.config.analytics diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/workspace/WorkspaceManager.kt b/domain/src/main/java/com/anytypeio/anytype/domain/workspace/WorkspaceManager.kt index 7c61d0ddf6..cb8f69fe2c 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/workspace/WorkspaceManager.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/workspace/WorkspaceManager.kt @@ -26,6 +26,7 @@ interface SpaceManager { fun observe() : Flow fun observe(space: SpaceId): Flow fun state(): Flow + fun getState(): State fun clear() @@ -102,6 +103,20 @@ interface SpaceManager { } } + override fun getState(): State { + val space = currentSpace.value + return if (space == NO_SPACE) { + State.NoSpace + } else { + val config = info[space] + if (config != null) { + State.Space.Active(config) + } else { + State.Space.Idle(SpaceId(space)) + } + } + } + override fun clear() { info.clear() currentSpace.value = NO_SPACE diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/splash/SplashViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/splash/SplashViewModel.kt index b4c7dbcbd3..ec7242ad48 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/splash/SplashViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/splash/SplashViewModel.kt @@ -271,9 +271,13 @@ class SplashViewModel( } } + /** + * Before navigating to widgets, make sure space was opened successfully during launchAccount + * @see [LaunchAccount] use-case + */ private suspend fun proceedWithVaultNavigation(deeplink: String? = null) { val space = getLastOpenedSpace.async(Unit).getOrNull() - if (space != null) { + if (space != null && spaceManager.getState() != SpaceManager.State.NoSpace) { commands.emit(Command.NavigateToWidgets( space = space.id, deeplink = deeplink @@ -288,7 +292,7 @@ class SplashViewModel( analytics = analytics, userProperty = UserProperty.AccountId(id) ) - localeProvider.language()?.let { lang -> + localeProvider.language().let { lang -> viewModelScope.updateUserProperties( analytics = analytics, userProperty = UserProperty.InterfaceLanguage(lang)