1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-2271 Object type | Space member (#941)

This commit is contained in:
Konstantin Ivanov 2024-02-29 16:50:10 +01:00 committed by konstantiniiv
parent dde6cd905f
commit 495b2499e9
7 changed files with 68 additions and 17 deletions

View file

@ -12,6 +12,7 @@ import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.primitives.TypeId
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.ResultInteractor
import com.anytypeio.anytype.domain.block.repo.BlockRepository
@ -159,6 +160,11 @@ class GetDefaultObjectType @Inject constructor(
relation = Relations.SPACE_ID,
condition = DVFilterCondition.EQUAL,
value = space.id
),
DVFilter(
relation = Relations.RESTRICTIONS,
condition = DVFilterCondition.NOT_IN,
value = listOf(ObjectRestriction.CREATE_OBJECT_OF_THIS_TYPE.code.toDouble())
)
)

View file

@ -79,7 +79,8 @@ class ObjectTypesSubscriptionManager (
Relations.RECOMMENDED_LAYOUT,
Relations.DEFAULT_TEMPLATE_ID,
Relations.SPACE_ID,
Relations.UNIQUE_KEY
Relations.UNIQUE_KEY,
Relations.RESTRICTIONS
),
ignoreWorkspace = true
)

View file

@ -63,7 +63,8 @@ class MyTypesDelegate @Inject constructor(
Relations.RESTRICTIONS
),
filters = ObjectSearchConstants.filterTypes(
spaces = listOf(space)
spaces = listOf(space),
excludeParticipant = false
)
)
}

View file

@ -54,7 +54,8 @@ class ObjectTypeChangeViewModel(
private val pipeline = combine(searchQuery, setup) { query, setup ->
val myTypes = proceedWithGettingMyTypes(
query = query
query = query,
setup = setup
)
val marketplaceTypes = proceedWithGettingMarketplaceTypes(
myTypes = myTypes,
@ -100,6 +101,7 @@ class ObjectTypeChangeViewModel(
selectedTypes: List<Id>,
isSetSource: Boolean
) {
Timber.d("Starting with params: isWithCollection=$isWithCollection, isWithBookmark=$isWithBookmark, excludeTypes=$excludeTypes, selectedTypes=$selectedTypes, isSetSource=$isSetSource")
viewModelScope.launch {
setup.emit(
Setup(
@ -270,12 +272,14 @@ class ObjectTypeChangeViewModel(
}
private suspend fun proceedWithGettingMyTypes(
query: String
query: String,
setup: Setup
) = getObjectTypes.run(
GetObjectTypes.Params(
filters = ObjectSearchConstants.filterTypes(
spaces = listOf(spaceManager.get()),
recommendedLayouts = SupportedLayouts.editorLayouts + SupportedLayouts.fileLayouts
recommendedLayouts = SupportedLayouts.editorLayouts + SupportedLayouts.fileLayouts,
excludeParticipant = !setup.isSetSource
),
sorts = ObjectSearchConstants.defaultObjectTypeSearchSorts(),
query = query,

View file

@ -3,6 +3,7 @@ package com.anytypeio.anytype.presentation.objects
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.InternalFlags
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.ObjectTypeIds.BOOKMARK
import com.anytypeio.anytype.core_models.ObjectTypeIds.COLLECTION
@ -88,7 +89,7 @@ fun ObjectState.DataView.isCreateObjectAllowed(objectType: ObjectWrapper.Type? =
return true
}
val skipLayouts = fileLayouts + systemLayouts
val skipLayouts = fileLayouts + systemLayouts + listOf(ObjectType.Layout.PARTICIPANT)
return !skipLayouts.contains(objectType?.recommendedLayout)
}

View file

@ -8,6 +8,7 @@ import com.anytypeio.anytype.core_models.DVFilterCondition
import com.anytypeio.anytype.core_models.EMPTY_QUERY
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction
import com.anytypeio.anytype.domain.search.SearchObjects
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.workspace.SpaceManager
@ -80,6 +81,11 @@ class LimitObjectTypeViewModel(
relation = Relations.IS_HIDDEN,
condition = DVFilterCondition.NOT_EQUAL,
value = true
),
DVFilter(
relation = Relations.RESTRICTIONS,
condition = DVFilterCondition.NOT_IN,
value = listOf(ObjectRestriction.CREATE_OBJECT_OF_THIS_TYPE.code.toDouble())
)
),
keys = listOf(

View file

@ -11,7 +11,9 @@ import com.anytypeio.anytype.core_models.Marketplace.MARKETPLACE_SPACE_ID
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeUniqueKeys
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.primitives.RelationKey
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction
import com.anytypeio.anytype.presentation.objects.SupportedLayouts
/**
@ -631,7 +633,8 @@ object ObjectSearchConstants {
Relations.COVER_ID,
Relations.PAGE_COVER,
Relations.FILE_EXT,
Relations.FILE_MIME_TYPE
Relations.FILE_MIME_TYPE,
Relations.RESTRICTIONS
)
val defaultRelationKeys = listOf(
@ -673,7 +676,8 @@ object ObjectSearchConstants {
fun filterTypes(
spaces: List<Id>,
recommendedLayouts: List<ObjectType.Layout> = emptyList(),
excludedTypeKeys: List<TypeKey> = emptyList()
excludedTypeKeys: List<TypeKey> = emptyList(),
excludeParticipant: Boolean = true
): List<DVFilter> {
return buildList {
addAll(
@ -706,6 +710,11 @@ object ObjectSearchConstants {
DVFilter(
relation = Relations.UNIQUE_KEY,
condition = DVFilterCondition.NOT_EMPTY
),
DVFilter(
relation = Relations.RESTRICTIONS,
condition = DVFilterCondition.NOT_IN,
value = listOf(ObjectRestriction.CREATE_OBJECT_OF_THIS_TYPE.code.toDouble())
)
)
)
@ -718,15 +727,37 @@ object ObjectSearchConstants {
)
)
}
if (recommendedLayouts.isNotEmpty()) {
add(
DVFilter(
relation = Relations.RECOMMENDED_LAYOUT,
condition = DVFilterCondition.IN,
value = recommendedLayouts.map { it.code.toDouble() }
)
addRecommendedLayoutsFilter(recommendedLayouts, excludeParticipant)
}
}
private fun MutableList<DVFilter>.addRecommendedLayoutsFilter(
recommendedLayouts: List<ObjectType.Layout>,
excludeParticipant: Boolean
) {
when {
recommendedLayouts.isNotEmpty() -> add(
DVFilter(
relation = Relations.RECOMMENDED_LAYOUT,
condition = DVFilterCondition.IN,
value = getLayoutCodes(recommendedLayouts, excludeParticipant)
)
}
)
excludeParticipant -> add(
DVFilter(
relation = Relations.RECOMMENDED_LAYOUT,
condition = DVFilterCondition.NOT_IN,
value = listOf(ObjectType.Layout.PARTICIPANT.code.toDouble())
)
)
}
}
private fun getLayoutCodes(layouts: List<ObjectType.Layout>, excludeParticipant: Boolean): List<Double> {
return if (excludeParticipant) {
layouts.filterNot { it == ObjectType.Layout.PARTICIPANT }.map { it.code.toDouble() }
} else {
layouts.map { it.code.toDouble() }
}
}
@ -823,7 +854,8 @@ object ObjectSearchConstants {
Relations.SOURCE_OBJECT,
Relations.RECOMMENDED_LAYOUT,
Relations.DEFAULT_TEMPLATE_ID,
Relations.SPACE_ID
Relations.SPACE_ID,
Relations.RESTRICTIONS
)
//endregion