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

DROID-1934 Multispaces | FIx | Display profile object in global search (#560)

This commit is contained in:
Evgenii Kozlov 2023-11-16 14:44:07 +01:00 committed by uburoiubu
parent 262a9c141d
commit dbf4193cda
No known key found for this signature in database
GPG key ID: C8FB80E0A595FBB6
11 changed files with 74 additions and 51 deletions

View file

@ -12,6 +12,7 @@ data class Config(
val profile: Id,
val gateway: Url,
val space: Id,
val techSpace: Id,
val spaceView: Id,
val widgets: Id,
val analytics: Id,

View file

@ -18,6 +18,7 @@ object ObjectTypeIds {
const val TASK = "ot-task"
const val DATE = "ot-date"
const val PROFILE = "ot-profile" //contains User Profile page and Anytype Person page
const val HUMAN = "ot-human"
const val NOTE = "ot-note"
const val WORKSPACE = "ot-space"
const val DASHBOARD = "ot-dashboard"
@ -60,6 +61,7 @@ object MarketplaceObjectTypeIds {
const val TASK = "_ottask"
const val DATE = "_otdate"
const val PROFILE = "_otprofile"
const val HUMAN = "_othuman"
const val NOTE = "_otnote"
const val DASHBOARD = "_otdashboard"
const val BOOKMARK = "_otbookmark"

View file

@ -74,6 +74,8 @@ object Relations {
const val SPACE_ACCOUNT_STATUS = "spaceAccountStatus"
const val SPACE_LOCAL_STATUS = "spaceLocalStatus"
const val IDENTITY_PROFILE_LINK = "identityProfileLink"
val systemRelationKeys = listOf(
"id",
"name",

View file

@ -53,7 +53,8 @@ fun Rpc.Account.Select.Response.toAccountSetup(): AccountSetup {
widgets = info.widgetsId,
analytics = info.analyticsId,
device = info.deviceId,
network = info.networkId
network = info.networkId,
techSpace = info.techSpaceId
),
status = status?.core() ?: AccountStatus.Unknown
)

View file

@ -769,6 +769,7 @@ fun Account.Info.config() : Config = Config(
profile = profileObjectId,
gateway = gatewayUrl,
space = accountSpaceId,
techSpace = techSpaceId,
spaceView = spaceViewId,
widgets = widgetsId,
analytics = analyticsId,

View file

@ -2,7 +2,9 @@ package com.anytypeio.anytype.presentation.objects
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Marketplace
import com.anytypeio.anytype.core_models.MarketplaceObjectTypeIds
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectTypeUniqueKeys
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.Relations.SOURCE_OBJECT
@ -18,6 +20,7 @@ import com.anytypeio.anytype.presentation.relations.RelationValueView
import com.anytypeio.anytype.presentation.sets.filter.CreateFilterView
import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider
import com.anytypeio.anytype.presentation.widgets.collection.CollectionView
import timber.log.Timber
@Deprecated("To be deleted")
fun List<ObjectWrapper.Basic>.toView(
@ -53,13 +56,20 @@ fun List<ObjectWrapper.Basic>.toViews(
gradientProvider: SpaceGradientProvider = SpaceGradientProvider.Default
): List<DefaultObjectView> = map { obj ->
val typeUrl = obj.getProperType()
val isProfile = typeUrl == MarketplaceObjectTypeIds.PROFILE
val layout = obj.getProperLayout()
DefaultObjectView(
id = obj.id,
name = obj.getProperName(),
description = obj.description,
type = typeUrl,
typeName = objectTypes.firstOrNull { it.id == typeUrl }?.name,
typeName = objectTypes.firstOrNull { type ->
if (isProfile) {
type.uniqueKey == ObjectTypeUniqueKeys.PROFILE
} else {
type.id == typeUrl
}
}?.name,
layout = layout,
icon = ObjectIcon.from(
obj = obj,

View file

@ -21,7 +21,7 @@ import com.anytypeio.anytype.presentation.objects.SupportedLayouts
object ObjectSearchConstants {
//region SEARCH OBJECTS
fun filterSearchObjects(space: Id) = listOf(
fun filterSearchObjects(spaces: List<Id>) = listOf(
DVFilter(
relation = Relations.IS_ARCHIVED,
condition = DVFilterCondition.NOT_EQUAL,
@ -57,8 +57,8 @@ object ObjectSearchConstants {
),
DVFilter(
relation = Relations.SPACE_ID,
condition = DVFilterCondition.EQUAL,
value = space
condition = DVFilterCondition.IN,
value = spaces
)
)

View file

@ -6,6 +6,7 @@ import com.anytypeio.anytype.analytics.base.Analytics
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_utils.common.EventWrapper
import com.anytypeio.anytype.core_utils.ext.cancel
import com.anytypeio.anytype.core_utils.ui.TextInputDialogBottomBehaviorApplier
@ -155,7 +156,6 @@ open class ObjectSearchViewModel(
val target = view.id
sendSearchResultEvent(target)
when (view.layout) {
ObjectType.Layout.PROFILE,
ObjectType.Layout.BASIC,
ObjectType.Layout.TODO,
ObjectType.Layout.NOTE,
@ -164,6 +164,18 @@ open class ObjectSearchViewModel(
ObjectType.Layout.BOOKMARK -> {
navigate(EventWrapper(AppNavigation.Command.LaunchDocument(id = target)))
}
ObjectType.Layout.PROFILE -> {
val obj = objects
.value
.getOrNull()
?.find { obj -> obj.id == view.id }
val identity = obj?.getValue<Id>(Relations.IDENTITY_PROFILE_LINK)
if (identity != null) {
navigate(EventWrapper(AppNavigation.Command.LaunchDocument(id = identity)))
} else {
navigate(EventWrapper(AppNavigation.Command.LaunchDocument(id = target)))
}
}
ObjectType.Layout.SET, ObjectType.Layout.COLLECTION -> {
navigate(EventWrapper(AppNavigation.Command.LaunchObjectSet(target = target)))
}
@ -190,11 +202,22 @@ open class ObjectSearchViewModel(
open suspend fun getSearchObjectsParams(ignore: Id?) = SearchObjects.Params(
limit = SEARCH_LIMIT,
filters = ObjectSearchConstants.filterSearchObjects(
space = spaceManager.get()
spaces = buildList {
val config = spaceManager.getConfig()
if (config != null) {
add(config.space)
add(config.techSpace)
} else {
add(spaceManager.get())
}
}
),
sorts = ObjectSearchConstants.sortsSearchObjects,
fulltext = EMPTY_QUERY,
keys = ObjectSearchConstants.defaultKeys
keys = buildList {
addAll(ObjectSearchConstants.defaultKeys)
add("identityProfileLink")
}
)
override fun onDialogCancelled() {

View file

@ -11,6 +11,7 @@ import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_models.SearchResult
import com.anytypeio.anytype.core_models.StubConfig
import com.anytypeio.anytype.core_models.primitives.TypeId
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.core_models.restrictions.DataViewRestrictions
@ -206,17 +207,7 @@ open class ObjectSetViewModelTestSetup {
computation = rule.dispatcher,
main = rule.dispatcher
)
spaceConfig = Config(
home = "morbi",
profile = "indoctum",
gateway = "luctus",
space = "nonumy",
spaceView = "etiam",
widgets = "eloquentiam",
analytics = "quem",
device = "elaboraret",
network = "network"
)
spaceConfig = StubConfig()
spaceManager = SpaceManager.Impl(
repo = repo,
dispatchers = dispatchers,
@ -320,19 +311,9 @@ open class ObjectSetViewModelTestSetup {
suspend fun stubSpaceManager(space: Id) {
repo.stub {
onBlocking { getSpaceConfig(space) } doReturn Config(
home = "morbi",
profile = "indoctum",
gateway = "luctus",
space = space,
spaceView = "etiam",
widgets = "eloquentiam",
analytics = "quem",
device = "elaboraret",
network = "network"
)
onBlocking { getSpaceConfig(space) } doReturn spaceConfig
spaceManager.set(space)
}
spaceManager.set(space)
}
suspend fun stubSubscriptionResults(
@ -340,7 +321,7 @@ open class ObjectSetViewModelTestSetup {
spaceId: Id,
collection: Id? = null,
objects: List<ObjectWrapper.Basic> = emptyList(),
dependencies: List<ObjectWrapper.Basic> = listOf(),
dependencies: List<ObjectWrapper.Basic> = listOf(),
dvFilters: List<Block.Content.DataView.Filter> = emptyList(),
dvSorts: List<Block.Content.DataView.Sort> = emptyList(),
storeOfRelations: StoreOfRelations,
@ -378,7 +359,7 @@ open class ObjectSetViewModelTestSetup {
}
}
protected suspend fun stubStoreOfRelations(mockObjectCollection: MockCollection) {
suspend fun stubStoreOfRelations(mockObjectCollection: MockCollection) {
storeOfRelations.merge(
listOf(
mockObjectCollection.relationObject1,
@ -391,7 +372,7 @@ open class ObjectSetViewModelTestSetup {
)
}
protected suspend fun stubStoreOfRelations(mockObjectSet: MockSet) {
suspend fun stubStoreOfRelations(mockObjectSet: MockSet) {
storeOfRelations.merge(
listOf(
mockObjectSet.relationObject1,
@ -412,7 +393,7 @@ open class ObjectSetViewModelTestSetup {
name: String = defaultObjectPageTypeName,
id: TypeId = TypeId(MockDataFactory.randomString()),
template: Id? = null
) {
) {
getDefaultObjectType.stub {
onBlocking { run(Unit) } doReturn GetDefaultObjectType.Response(
type = type,

View file

@ -152,10 +152,10 @@ class ObjectTypeChangeViewModelTest {
// SETUP
val marketplaceType1 = StubObjectType()
val marketplaceType2 = StubObjectType()
val installedType1 = StubObjectType(sourceObject = marketplaceType1.id)
val installedType2 = StubObjectType(sourceObject = marketplaceType2.id)
val marketplaceType1 = StubObjectType(uniqueKey = MockDataFactory.randomUuid())
val marketplaceType2 = StubObjectType(uniqueKey = MockDataFactory.randomUuid())
val installedType1 = StubObjectType(uniqueKey = marketplaceType1.uniqueKey)
val installedType2 = StubObjectType(uniqueKey = marketplaceType2.uniqueKey)
stubSpaceManager(spaceId)
val vm = givenViewModel()
@ -179,11 +179,11 @@ class ObjectTypeChangeViewModelTest {
addAll(ObjectSearchConstants.filterObjectTypeMarketplace)
add(
DVFilter(
relation = Relations.ID,
relation = Relations.UNIQUE_KEY,
condition = DVFilterCondition.NOT_IN,
value = listOf(
marketplaceType1.id,
marketplaceType2.id,
marketplaceType1.uniqueKey,
marketplaceType2.uniqueKey,
MarketplaceObjectTypeIds.BOOKMARK
)
)
@ -258,10 +258,10 @@ class ObjectTypeChangeViewModelTest {
// SETUP
val marketplaceType1 = StubObjectType()
val marketplaceType2 = StubObjectType()
val installedType1 = StubObjectType(sourceObject = marketplaceType1.id)
val installedType2 = StubObjectType(sourceObject = marketplaceType2.id)
val marketplaceType1 = StubObjectType(uniqueKey = MockDataFactory.randomUuid())
val marketplaceType2 = StubObjectType(uniqueKey = MockDataFactory.randomUuid())
val installedType1 = StubObjectType(uniqueKey = marketplaceType1.uniqueKey)
val installedType2 = StubObjectType(uniqueKey = marketplaceType2.uniqueKey)
stubSpaceManager(spaceId)
val vm = givenViewModel()
@ -285,11 +285,11 @@ class ObjectTypeChangeViewModelTest {
addAll(ObjectSearchConstants.filterObjectTypeMarketplace)
add(
DVFilter(
relation = Relations.ID,
relation = Relations.UNIQUE_KEY,
condition = DVFilterCondition.NOT_IN,
value = listOf(
marketplaceType1.id,
marketplaceType2.id,
marketplaceType1.uniqueKey,
marketplaceType2.uniqueKey,
MarketplaceObjectTypeIds.BOOKMARK
)
)

View file

@ -30,18 +30,20 @@ fun StubConfig(
home: Id = MockDataFactory.randomUuid(),
profile: Id = MockDataFactory.randomUuid(),
gateway: Url = MockDataFactory.randomUuid(),
workspace: Id = MockDataFactory.randomUuid(),
spaceView: Id = MockDataFactory.randomUuid(),
widgets: Id = MockDataFactory.randomUuid(),
analytics: Id = MockDataFactory.randomUuid(),
device: Id = MockDataFactory.randomUuid(),
space: Id = MockDataFactory.randomUuid(),
techSpace: Id = MockDataFactory.randomUuid(),
network: Id = MockDataFactory.randomUuid()
) : Config = Config(
home = home,
profile = profile,
gateway = gateway,
spaceView = workspace,
spaceView = spaceView,
space = space,
techSpace = techSpace,
widgets = widgets,
analytics = analytics,
device = device,