diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/Command.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/Command.kt index 4421f63757..2b5bd485f5 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/Command.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/Command.kt @@ -475,6 +475,12 @@ sealed class Command { data class SetInternalFlags(val ctx: Id, val flags: List) + data class CreateSpace( + val details: Struct, + val withChat: Boolean, + val shouldApplyEmptyUseCase: Boolean + ) + data class AddObjectToSpace(val space: Id, val objectId: Id) data class ApplyTemplate(val objectId: Id, val template: Id?) diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt index 6f94f3f64b..bec28bc816 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockDataRepository.kt @@ -759,9 +759,8 @@ class BlockDataRepository( remote.deleteSpace(space) } - override suspend fun createWorkspace(details: Struct, withChat: Boolean): Id = remote.createWorkspace( - details = details, - withChat = withChat + override suspend fun createWorkspace(command: Command.CreateSpace): Id = remote.createWorkspace( + command = command ) override suspend fun setSpaceDetails(space: SpaceId, details: Struct) { diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt index 0020ff2efa..db09f050a6 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/block/BlockRemote.kt @@ -339,7 +339,7 @@ interface BlockRemote { suspend fun setSpaceDetails(space: SpaceId, details: Struct) suspend fun deleteSpace(space: SpaceId) - suspend fun createWorkspace(details: Struct, withChat: Boolean): Id + suspend fun createWorkspace(command: Command.CreateSpace): Id suspend fun getSpaceConfig(space: Id): Config diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt b/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt index 9a7514da70..aa376c6348 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/block/repo/BlockRepository.kt @@ -391,7 +391,7 @@ interface BlockRepository { ): Payload suspend fun deleteSpace(space: SpaceId) - suspend fun createWorkspace(details: Struct, withChat: Boolean): Id + suspend fun createWorkspace(command: Command.CreateSpace): Id suspend fun getSpaceConfig(space: Id): Config suspend fun addObjectListToSpace(objects: List, space: Id) : List suspend fun addObjectToSpace(command: Command.AddObjectToSpace) : Pair diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/spaces/CreateSpace.kt b/domain/src/main/java/com/anytypeio/anytype/domain/spaces/CreateSpace.kt index a4bde51315..f90e92d079 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/spaces/CreateSpace.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/spaces/CreateSpace.kt @@ -1,5 +1,6 @@ package com.anytypeio.anytype.domain.spaces +import com.anytypeio.anytype.core_models.Command import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Struct import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers @@ -13,9 +14,16 @@ class CreateSpace @Inject constructor( ) : ResultInteractor(dispatchers.io) { override suspend fun doWork(params: Params): Id = repo.createWorkspace( - details = params.details, - withChat = params.withChat + command = Command.CreateSpace( + details = params.details, + withChat = params.withChat, + shouldApplyEmptyUseCase = params.shouldApplyEmptyUseCase + ), ) - data class Params(val details: Struct, val withChat: Boolean = true) + data class Params( + val details: Struct, + val withChat: Boolean = false, + val shouldApplyEmptyUseCase: Boolean = false + ) } \ No newline at end of file diff --git a/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt b/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt index e1a6e3b0c9..de04866011 100644 --- a/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt +++ b/gallery-experience/src/main/java/com/anytypeio/anytype/gallery_experience/viewmodel/GalleryInstallationViewModel.kt @@ -28,11 +28,13 @@ import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationNaviga import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationSpacesState import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationState import com.anytypeio.anytype.gallery_experience.models.GallerySpaceView +import com.anytypeio.anytype.presentation.spaces.CreateSpaceViewModel.Companion.MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE import com.anytypeio.anytype.presentation.spaces.SelectSpaceViewModel import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider import com.anytypeio.anytype.presentation.spaces.spaceIcon import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import timber.log.Timber @@ -129,7 +131,10 @@ class GalleryInstallationViewModel( details = mapOf( Relations.NAME to manifestInfo.title, Relations.ICON_OPTION to spaceGradientProvider.randomId().toDouble() - ) + ), + shouldApplyEmptyUseCase = spacesViewState.value.spaces.count { item -> + item.obj.isActive + } >= MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE ) createSpace.async(params).fold( onSuccess = { space -> diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt index e17a98c863..15dd5250b6 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/block/BlockMiddleware.kt @@ -730,12 +730,8 @@ class BlockMiddleware( middleware.spaceDelete(space) } - override suspend fun createWorkspace( - details: Struct, - withChat: Boolean - ): Id = middleware.workspaceCreate( - details = details, - withChat = withChat + override suspend fun createWorkspace(command: Command.CreateSpace): Id = middleware.workspaceCreate( + command = command ) override suspend fun getSpaceConfig(space: Id): Config = middleware.workspaceOpen( diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt index f632652db1..fe1e1b1972 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt @@ -1935,11 +1935,14 @@ class Middleware @Inject constructor( } @Throws(Exception::class) - fun workspaceCreate(details: Struct, withChat: Boolean): Id { + fun workspaceCreate(command: Command.CreateSpace): Id { val request = Rpc.Workspace.Create.Request( - details = details, - useCase = Rpc.Object.ImportUseCase.Request.UseCase.GET_STARTED, - withChat = withChat + details = command.details, + useCase = if (command.shouldApplyEmptyUseCase) + Rpc.Object.ImportUseCase.Request.UseCase.EMPTY + else + Rpc.Object.ImportUseCase.Request.UseCase.GET_STARTED, + withChat = command.withChat ) logRequestIfDebug(request) val (response, time) = measureTimedValue { service.workspaceCreate(request) } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/CreateSpaceViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/CreateSpaceViewModel.kt index 6bf968fcfa..d1001e54c8 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/CreateSpaceViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/CreateSpaceViewModel.kt @@ -58,13 +58,15 @@ class CreateSpaceViewModel( return } val isSingleSpace = spaceViewContainer.get().size == 1 + val numberOfActiveSpaces = spaceViewContainer.get().filter { it.isActive }.size viewModelScope.launch { createSpace.stream( CreateSpace.Params( details = mapOf( Relations.NAME to name, Relations.ICON_OPTION to spaceIconView.value.color.index.toDouble() - ) + ), + shouldApplyEmptyUseCase = numberOfActiveSpaces >= MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE ) ).collect { result -> result.fold( @@ -135,4 +137,8 @@ class CreateSpaceViewModel( val showMultiplayerTooltip: Boolean ): Command() } + + companion object { + const val MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE = 2 + } } \ No newline at end of file