Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ sealed class Command {

data class SetInternalFlags(val ctx: Id, val flags: List<InternalFlags>)

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?)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Id>, space: Id) : List<Id>
suspend fun addObjectToSpace(command: Command.AddObjectToSpace) : Pair<Id, Struct?>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,9 +14,16 @@ class CreateSpace @Inject constructor(
) : ResultInteractor<CreateSpace.Params, Id>(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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -135,4 +137,8 @@ class CreateSpaceViewModel(
val showMultiplayerTooltip: Boolean
): Command()
}

companion object {
const val MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE = 2
}
}
Loading