From 524e15d26eaa0c5b0d529b33647ef3f0fa3011e6 Mon Sep 17 00:00:00 2001 From: Konstantin Ivanov <54908981+konstantiniiv@users.noreply.github.com> Date: Mon, 27 Jan 2025 13:04:14 +0100 Subject: [PATCH] DROID-1992 Tech | Objects details refactoring (#1997) --- .../features/editor/DeleteBlockTesting.kt | 6 +- .../features/editor/DescriptionTesting.kt | 6 +- .../editor/FeaturedRelationTesting.kt | 11 +- .../anytype/features/editor/LayoutTesting.kt | 36 +- .../anytype/features/editor/MarkupTesting.kt | 5 +- .../features/editor/MentionUpdateTesting.kt | 5 +- .../anytype/features/editor/ProfileTesting.kt | 15 +- .../features/editor/RelationBlockUITesting.kt | 49 +- .../editor/SlashTextWatcherTesting.kt | 6 +- .../features/editor/SlashWidgetTesting.kt | 11 +- .../features/editor/SplitTitleTesting.kt | 11 +- .../features/editor/base/EditorTestSetup.kt | 5 +- .../editor/base/MentionWidgetTesting.kt | 6 +- .../dv/ObjectSetGridColumnRenderingTest.kt | 1 - .../dv/ObjectSetGridFileCellRenderingTest.kt | 13 +- .../ObjectSetGridNumberCellRenderingTest.kt | 13 +- .../ObjectSetGridObjectCellRenderingTest.kt | 23 +- .../dv/ObjectSetGridPrimitiveRelationTest.kt | 1 - .../dv/ObjectSetGridTagCellRenderingTest.kt | 4 +- .../features/sets/dv/ObjectSetHeaderTest.kt | 3 +- .../features/sets/dv/TestObjectSetSetup.kt | 22 +- .../sets/sort/ViewerObjectSortTest.kt | 4 +- .../anytypeio/anytype/di/feature/EditorDI.kt | 16 +- .../anytype/di/feature/ObjectMenuDI.kt | 19 +- .../di/feature/ObjectRelationListDI.kt | 6 +- .../anytype/di/feature/ObjectSetDI.kt | 20 +- .../anytypeio/anytype/core_models/Block.kt | 6 - .../anytypeio/anytype/core_models/Event.kt | 27 +- .../anytype/core_models/ObjectViewDetails.kt | 7 + .../anytype/core_models/ObjectWrapper.kt | 14 +- .../anytype/core_models/ext/DetailsExt.kt | 70 -- .../anytype/core_models/ext/MarkupExt.kt | 1 - .../anytype/core_models/ext/StructExt.kt | 43 +- .../domain/dashboard/model/HomeDashboard.kt | 11 - .../domain/page/AddBackLinkToObject.kt | 2 +- .../interactor/MiddlewareEventMapper.kt | 3 +- .../middleware/mappers/ToCoreModelMappers.kt | 10 +- .../anytype/MiddlewareEventChannelTest.kt | 2 +- .../presentation/editor/EditorViewModel.kt | 243 +++---- .../presentation/editor/editor/Store.kt | 23 +- .../editor/editor/ext/BlockViewExt.kt | 9 +- .../editor/editor/ext/ContentTextExt.kt | 40 +- .../editor/layout/ObjectLayoutViewModel.kt | 3 +- .../editor/render/BlockViewRenderer.kt | 3 +- .../editor/render/DefaultBlockViewRenderer.kt | 126 ++-- .../extension/AllObjectsDetailsExt.kt | 115 +++ .../presentation/extension/AnalyticsExt.kt | 26 +- .../presentation/extension/FileUrlExt.kt | 2 +- .../history/VersionHistoryViewModel.kt | 9 +- .../presentation/mapper/MapperExtension.kt | 68 +- .../menu/ObjectMenuOptionsProviderImpl.kt | 19 +- .../objects/menu/ObjectMenuViewModel.kt | 62 +- .../objects/menu/ObjectMenuViewModelBase.kt | 4 +- .../objects/menu/ObjectSetMenuViewModel.kt | 10 +- .../presentation/relations/CoverTypeMapper.kt | 14 - .../ObjectRelationListViewModelFactory.kt | 6 +- .../relations/ObjectSetRenderMapper.kt | 16 +- .../relations/RelationExtensions.kt | 55 +- .../relations/RelationListViewModel.kt | 96 +-- .../relations/RelationObjectExtensions.kt | 47 +- .../DataViewObjectRelationProvider.kt | 4 +- .../providers/DataViewObjectValueProvider.kt | 15 +- .../DefaultObjectRelationProvider.kt | 2 +- .../providers/DefaultObjectValueProvider.kt | 6 +- .../providers/ObjectDetailProvider.kt | 8 - .../providers/ObjectRelationListProvider.kt | 47 ++ .../providers/RelationListProvider.kt | 53 -- .../ObjectSetCreateBookmarkRecordViewModel.kt | 6 +- .../presentation/sets/ObjectSetExtension.kt | 184 ++--- .../presentation/sets/ObjectSetViewModel.kt | 29 +- .../presentation/sets/SetsExtension.kt | 26 +- .../sets/state/DefaultObjectStateReducer.kt | 70 +- .../presentation/sets/state/ObjectState.kt | 7 +- .../templates/TemplateBlankViewModel.kt | 12 +- .../collections/CollectionAddRelationTest.kt | 41 +- .../collections/MockCollection.kt | 13 +- .../presentation/collections/MockSet.kt | 34 +- .../ObjectStateCollectionViewTest.kt | 5 +- .../collections/ObjectStateSetViewTest.kt | 27 +- .../DataViewBlockTargetObjectSetTest.kt | 38 +- .../editor/DefaultBlockViewRendererTest.kt | 281 ++++---- .../editor/EditorViewModelTest.kt | 14 +- .../editor/EditorBackspaceDeleteTest.kt | 37 +- .../editor/editor/EditorErrorMessageTest.kt | 7 +- .../editor/EditorFeaturedRelationsTest.kt | 388 ++++++----- .../editor/editor/EditorInternalFlagsTest.kt | 71 +- .../editor/editor/EditorLockPageTest.kt | 28 +- .../editor/editor/EditorMarkupObjectTest.kt | 14 +- .../editor/editor/EditorMentionTest.kt | 59 +- .../editor/editor/EditorMenuTest.kt | 32 +- .../editor/editor/EditorNoteLayoutTest.kt | 30 +- .../EditorObjectTypeChangeWidgetTest.kt | 11 +- .../editor/EditorPresentationTestSetup.kt | 10 +- .../editor/editor/EditorRelationBlockTest.kt | 33 +- .../editor/EditorSlashWidgetClicksTest.kt | 17 +- .../editor/EditorSlashWidgetFilterTest.kt | 264 +++---- .../editor/EditorSlashWidgetRelationsTest.kt | 30 +- .../editor/editor/EditorSplitTest.kt | 38 +- .../editor/EditorTableOfContentsBlockTest.kt | 12 +- .../editor/editor/EditorTitleTest.kt | 10 +- .../editor/file_layout/FileLayoutTest.kt | 19 +- .../editor/table/TableBlockRendererTest.kt | 15 +- .../editor/template/EditorTemplateTest.kt | 31 +- .../home/HomeScreenViewModelTest.kt | 2 +- .../linking/LinkToObjectOrWebViewModelTest.kt | 2 +- .../mapper/MapperExtensionKtTest.kt | 83 ++- ...earanceChoosePreviewLayoutViewModelTest.kt | 3 +- .../menu/ObjectMenuOptionsProviderImplTest.kt | 63 +- .../presentation/sets/MockObjectSetFactory.kt | 7 +- .../presentation/sets/ObjectSetReducerTest.kt | 655 +++++++++--------- .../main/ObjectSetDataViewObjectCreateTest.kt | 35 +- .../sets/main/ObjectSetViewModelTestSetup.kt | 10 +- .../sets/main/ObjectSetZeroViewTest.kt | 13 +- .../CollectionViewerTypeAndTemplateTest.kt | 39 +- .../SetByRelationViewerTypeAndTemplateTest.kt | 77 +- .../SetByTypeViewerTypeAndTemplateTest.kt | 41 +- 116 files changed, 2197 insertions(+), 2420 deletions(-) create mode 100644 core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectViewDetails.kt delete mode 100644 core-models/src/main/java/com/anytypeio/anytype/core_models/ext/DetailsExt.kt delete mode 100644 domain/src/main/java/com/anytypeio/anytype/domain/dashboard/model/HomeDashboard.kt create mode 100644 presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AllObjectsDetailsExt.kt delete mode 100644 presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectDetailProvider.kt create mode 100644 presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectRelationListProvider.kt delete mode 100644 presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/RelationListProvider.kt diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DeleteBlockTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DeleteBlockTesting.kt index d1ba3cce0e..cc79902c0a 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DeleteBlockTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DeleteBlockTesting.kt @@ -24,6 +24,7 @@ import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.MockBlockFactory.text import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.TestUtils.withRecyclerView import com.anytypeio.anytype.ui.editor.EditorFragment @@ -536,12 +537,11 @@ class DeleteBlockTesting : EditorTestSetup() { stubOpenDocument( document = document, - details = Block.Details( + details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf("name" to title) ) - ) ) ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DescriptionTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DescriptionTesting.kt index 6085c8d5ea..36d3778068 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DescriptionTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/DescriptionTesting.kt @@ -15,6 +15,7 @@ import com.anytypeio.anytype.features.editor.base.EditorTestSetup import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory import com.anytypeio.anytype.presentation.MockBlockFactory +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText import com.anytypeio.anytype.test_utils.utils.checkIsRecyclerSize @@ -119,16 +120,15 @@ class DescriptionTesting : EditorTestSetup() { val document = listOf(page, header, title, description) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "featuredRelations" to listOf(Relations.DESCRIPTION), "description" to description.content().text ) ) - ) ) stubInterceptEvents() diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/FeaturedRelationTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/FeaturedRelationTesting.kt index 1ac71db5cd..adc74453bd 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/FeaturedRelationTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/FeaturedRelationTesting.kt @@ -15,6 +15,7 @@ import com.anytypeio.anytype.features.editor.base.EditorTestSetup import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory import com.anytypeio.anytype.presentation.MockBlockFactory +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasViewGroupChildWithText import com.anytypeio.anytype.test_utils.utils.matchView @@ -100,9 +101,9 @@ class FeaturedRelationTesting : EditorTestSetup() { val value4 = "https://anytype.io/" val value5 = "team@anytype.io" - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to value1, @@ -116,7 +117,6 @@ class FeaturedRelationTesting : EditorTestSetup() { relation5.key ) ) - ) ) ) @@ -203,9 +203,9 @@ class FeaturedRelationTesting : EditorTestSetup() { val value4 = "https://anytype.io/" val value5 = "team@anytype.io" - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to value1, @@ -220,7 +220,6 @@ class FeaturedRelationTesting : EditorTestSetup() { ) ) ) - ) ) val paragraph = MockBlockFactory.paragraph(text = "Foo") diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/LayoutTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/LayoutTesting.kt index 13af94ba9a..602a433f33 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/LayoutTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/LayoutTesting.kt @@ -13,6 +13,7 @@ import com.anytypeio.anytype.features.editor.base.EditorTestSetup import com.anytypeio.anytype.presentation.MockBlockContentFactory import com.anytypeio.anytype.presentation.MockBlockFactory import com.anytypeio.anytype.presentation.editor.cover.CoverColor +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText import com.anytypeio.anytype.test_utils.utils.checkIsDisplayed @@ -79,15 +80,14 @@ class LayoutTesting : EditorTestSetup() { val document = listOf(page, header, title, paragraph) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "layout" to ObjectType.Layout.TODO.code.toDouble() ) ) - ) ) stubInterceptEvents() @@ -130,15 +130,14 @@ class LayoutTesting : EditorTestSetup() { val document = listOf(page, header, checkedTitle, paragraph) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "layout" to ObjectType.Layout.TODO.code.toDouble() ) ) - ) ) stubInterceptEvents() @@ -176,9 +175,9 @@ class LayoutTesting : EditorTestSetup() { val document = listOf(page, header, title, paragraph) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "layout" to ObjectType.Layout.TODO.code.toDouble(), @@ -186,7 +185,6 @@ class LayoutTesting : EditorTestSetup() { "coverId" to CoverColor.BLUE.code, ) ) - ) ) stubInterceptEvents() @@ -223,15 +221,14 @@ class LayoutTesting : EditorTestSetup() { val document = listOf(page, header, title, paragraph) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "layout" to ObjectType.Layout.PROFILE.code.toDouble() ) ) - ) ) stubInterceptEvents() @@ -268,9 +265,9 @@ class LayoutTesting : EditorTestSetup() { val document = listOf(page, header, title, paragraph) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "layout" to ObjectType.Layout.PROFILE.code.toDouble(), @@ -278,7 +275,6 @@ class LayoutTesting : EditorTestSetup() { "coverId" to CoverColor.BLUE.code, ) ) - ) ) stubInterceptEvents() @@ -315,15 +311,14 @@ class LayoutTesting : EditorTestSetup() { val document = listOf(page, header, title, paragraph) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "layout" to ObjectType.Layout.BASIC.code.toDouble() ) ) - ) ) stubInterceptEvents() @@ -360,9 +355,9 @@ class LayoutTesting : EditorTestSetup() { val document = listOf(page, header, title, paragraph) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), "layout" to ObjectType.Layout.BASIC.code.toDouble(), @@ -370,7 +365,6 @@ class LayoutTesting : EditorTestSetup() { "coverId" to CoverColor.BLUE.code, ) ) - ) ) stubInterceptEvents() diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MarkupTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MarkupTesting.kt index b9de7cb077..6a736fb3d2 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MarkupTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MarkupTesting.kt @@ -13,6 +13,7 @@ import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.MockBlockFactory import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText import com.anytypeio.anytype.test_utils.utils.onItemView @@ -94,14 +95,14 @@ class MarkupTesting : EditorTestSetup() { val document = listOf(page, a) - val fields = Block.Fields(mapOf(Block.Fields.NAME_KEY to "FooBa")) + val fields = mapOf(Block.Fields.NAME_KEY to "FooBa") stubInterceptEvents() stubInterceptThreadStatus() stubAnalytics() stubOpenDocument( document = document, - details = Block.Details(mapOf(mentionTarget to fields)) + details = ObjectViewDetails(mapOf(mentionTarget to fields)) ) stubUpdateText() diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MentionUpdateTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MentionUpdateTesting.kt index 692f660ce9..fcf9e50326 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MentionUpdateTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/MentionUpdateTesting.kt @@ -16,6 +16,7 @@ import com.anytypeio.anytype.features.editor.base.EditorTestSetup import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText import com.anytypeio.anytype.test_utils.utils.onItemView @@ -106,7 +107,7 @@ class MentionUpdateTesting : EditorTestSetup() { ) val document = listOf(page, header, title, block) - val customDetails = Block.Details() + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubInterceptThreadStatus() @@ -120,7 +121,7 @@ class MentionUpdateTesting : EditorTestSetup() { Event.Command.ShowObject( context = root, root = root, - details = customDetails, + details = customDetails.details, blocks = document, objectRestrictions = emptyList() ), diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/ProfileTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/ProfileTesting.kt index f79361621d..ce5e2e3a7d 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/ProfileTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/ProfileTesting.kt @@ -13,6 +13,7 @@ import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.features.editor.base.EditorTestSetup import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.editor.cover.CoverColor +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText import com.anytypeio.anytype.test_utils.utils.checkIsDisplayed @@ -174,11 +175,11 @@ class ProfileTesting : EditorTestSetup() { } } - private fun givenBlockDetailsWithImage(): Block.Details { + private fun givenBlockDetailsWithImage(): ObjectViewDetails { val context = InstrumentationRegistry.getInstrumentation().targetContext - return Block.Details( + return ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconImage" to "anyimage", "layout" to ObjectType.Layout.PROFILE.code.toDouble(), @@ -186,21 +187,19 @@ class ProfileTesting : EditorTestSetup() { "coverId" to CoverColor.BLUE.code, ) ) - ) ) } - private fun givenBlockDetailsWithOutImage(): Block.Details { - return Block.Details( + private fun givenBlockDetailsWithOutImage(): ObjectViewDetails { + return ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "layout" to ObjectType.Layout.PROFILE.code.toDouble(), "coverType" to CoverType.COLOR.code.toDouble(), "coverId" to CoverColor.BLUE.code, ) ) - ) ) } } \ No newline at end of file diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/RelationBlockUITesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/RelationBlockUITesting.kt index 3a13f3b869..31c3fe9d4f 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/RelationBlockUITesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/RelationBlockUITesting.kt @@ -20,6 +20,7 @@ import com.anytypeio.anytype.features.editor.base.EditorTestSetup import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasBackgroundColor import com.anytypeio.anytype.test_utils.utils.checkHasNoBackground @@ -53,14 +54,13 @@ class RelationBlockUITesting : EditorTestSetup() { private val args = bundleOf(EditorFragment.CTX_KEY to root) - private val defaultDetails = Block.Details( + private val defaultDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() ) ) - ) ) private val title = Block( @@ -184,9 +184,9 @@ class RelationBlockUITesting : EditorTestSetup() { val value4 = "https://anytype.io/" val value5 = "team@anytype.io" - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to value1, @@ -196,7 +196,6 @@ class RelationBlockUITesting : EditorTestSetup() { relation5.key to value5, ) ) - ) ) val paragraph = Block( @@ -348,9 +347,9 @@ class RelationBlockUITesting : EditorTestSetup() { val background3 = ThemeColor.BLUE val background4 = ThemeColor.ORANGE - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to value1, @@ -360,7 +359,6 @@ class RelationBlockUITesting : EditorTestSetup() { relation5.key to value5, ) ) - ) ) val paragraph = Block( @@ -482,15 +480,14 @@ class RelationBlockUITesting : EditorTestSetup() { selections = listOf(option) ) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to option.id ) ) - ) ) val a = Block( @@ -557,29 +554,28 @@ class RelationBlockUITesting : EditorTestSetup() { selections = emptyList() ) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to listOf(file1, file2) ) - ), - file1 to Block.Fields( + , + file1 to mapOf( "name" to "Document", "ext" to "pdf", "mime" to "application/pdf" ) - ), - file2 to Block.Fields( + , + file2 to mapOf( "name" to "Image", "ext" to "jpg", "mime" to "image/jpeg" ) ) - ) ) val a = Block( @@ -793,9 +789,9 @@ class RelationBlockUITesting : EditorTestSetup() { val value4 = "https://anytype.io/" val value5 = "team@anytype.io" - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to value1, @@ -805,7 +801,6 @@ class RelationBlockUITesting : EditorTestSetup() { relation5.key to value5, ) ) - ) ) val block1 = Block( @@ -907,15 +902,14 @@ class RelationBlockUITesting : EditorTestSetup() { selections = listOf(option1) ) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to option1.id ) ) - ) ) val block1 = Block( @@ -1011,9 +1005,9 @@ class RelationBlockUITesting : EditorTestSetup() { val value4 = "https://anytype.io/" val value5 = "team@anytype.io" - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to value1, @@ -1023,7 +1017,6 @@ class RelationBlockUITesting : EditorTestSetup() { relation5.key to value5, ) ) - ) ) val paragraph = Block( diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashTextWatcherTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashTextWatcherTesting.kt index 7a0662cc8a..cb96d903ef 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashTextWatcherTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashTextWatcherTesting.kt @@ -16,6 +16,7 @@ import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.MockBlockFactory.paragraph import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkIsDisplayed import com.anytypeio.anytype.test_utils.utils.checkIsNotDisplayed @@ -42,13 +43,12 @@ class SlashTextWatcherTesting : EditorTestSetup() { private val args = bundleOf(EditorFragment.CTX_KEY to root) - private val defaultDetails = Block.Details( + private val defaultDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() ) - ) ) ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashWidgetTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashWidgetTesting.kt index 2f7a0a8ac5..1f011e2414 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashWidgetTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SlashWidgetTesting.kt @@ -29,6 +29,7 @@ import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.MockBlockFactory.paragraph import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.number.NumberParser import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText @@ -59,14 +60,13 @@ class SlashWidgetTesting : EditorTestSetup() { private val args = bundleOf(EditorFragment.CTX_KEY to root) - private val defaultDetails = Block.Details( + private val defaultDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() ) ) - ) ) private val title = Block( @@ -413,16 +413,15 @@ class SlashWidgetTesting : EditorTestSetup() { val relations = listOf(relation1, relation2) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random(), relation1.key to relation1Value, relation2.key to relation2Value ) ) - ) ) stubInterceptEvents() stubInterceptThreadStatus() diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SplitTitleTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SplitTitleTesting.kt index e37c3c42c5..f83488aea3 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SplitTitleTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/SplitTitleTesting.kt @@ -19,6 +19,7 @@ import com.anytypeio.anytype.features.editor.base.EditorTestSetup import com.anytypeio.anytype.features.editor.base.TestEditorFragment import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText import com.anytypeio.anytype.test_utils.utils.checkIsDisplayed @@ -115,11 +116,10 @@ class SplitTitleTesting : EditorTestSetup() { ) val document = listOf(page, header, title, description, featured, block) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf(Relations.FEATURED_RELATIONS to listOf(description.id, relation2.key)) - ) ) ) @@ -225,12 +225,11 @@ class SplitTitleTesting : EditorTestSetup() { ) val document = listOf(page, header, title, description, featured, block) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf(Relations.FEATURED_RELATIONS to listOf(description.id, relation2.key)) ) - ) ) stubInterceptEvents() diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/EditorTestSetup.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/EditorTestSetup.kt index f6494157f3..54788c2024 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/EditorTestSetup.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/EditorTestSetup.kt @@ -101,6 +101,7 @@ import com.anytypeio.anytype.presentation.editor.Editor import com.anytypeio.anytype.presentation.editor.EditorViewModel import com.anytypeio.anytype.presentation.editor.EditorViewModelFactory import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.Interactor import com.anytypeio.anytype.presentation.editor.editor.Orchestrator import com.anytypeio.anytype.presentation.editor.editor.Proxy @@ -532,7 +533,7 @@ open class EditorTestSetup { fun stubOpenDocument( document: List, - details: Block.Details = Block.Details(), + details: ObjectViewDetails = ObjectViewDetails.EMPTY, relations: List = emptyList() ) { openPage.stub { @@ -544,7 +545,7 @@ open class EditorTestSetup { Event.Command.ShowObject( context = root, root = root, - details = details, + details = details.details, blocks = document, ) ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/MentionWidgetTesting.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/MentionWidgetTesting.kt index 1562a552b4..25043df172 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/MentionWidgetTesting.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/editor/base/MentionWidgetTesting.kt @@ -12,6 +12,7 @@ import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.emojifier.data.DefaultDocumentEmojiIconProvider import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasChildViewWithText import com.anytypeio.anytype.test_utils.utils.checkIsDisplayed @@ -40,14 +41,13 @@ class MentionWidgetTesting : EditorTestSetup() { private val args = bundleOf(EditorFragment.CTX_KEY to root) - private val defaultDetails = Block.Details( + private val defaultDetails = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() ) ) - ) ) private val title = Block( diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridColumnRenderingTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridColumnRenderingTest.kt index 2ca9cc1789..3dc1088fcb 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridColumnRenderingTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridColumnRenderingTest.kt @@ -134,7 +134,6 @@ class ObjectSetGridColumnRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation1, relation2, relation3, relation4, relation5), details = defaultDetails ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridFileCellRenderingTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridFileCellRenderingTest.kt index ab45ea8165..8b74271de2 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridFileCellRenderingTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridFileCellRenderingTest.kt @@ -12,6 +12,7 @@ import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.emojifier.data.DefaultDocumentEmojiIconProvider import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.relations.ObjectSetConfig import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText @@ -124,22 +125,19 @@ class ObjectSetGridFileCellRenderingTest : TestObjectSetSetup() { ) ) - val details = Block.Details( + val details = ObjectViewDetails( details = defaultDetails.details + mapOf( - file1Id to Block.Fields( - mapOf( + file1Id to mapOf( ObjectSetConfig.NAME_KEY to file1Name, ObjectSetConfig.TYPE_KEY to objectType.url, "fileExt" to file1Ext - ) - ), - file2Id to Block.Fields( + ), + file2Id to mapOf( ObjectSetConfig.NAME_KEY to file2Name, ObjectSetConfig.TYPE_KEY to objectType.url, "fileExt" to file2Ext ) - ) ) ) @@ -156,7 +154,6 @@ class ObjectSetGridFileCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), details = details, ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridNumberCellRenderingTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridNumberCellRenderingTest.kt index 65fa53949b..49ea46110d 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridNumberCellRenderingTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridNumberCellRenderingTest.kt @@ -121,8 +121,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() { stubInterceptEvents() stubInterceptThreadStatus() stubOpenObjectSetWithRecord( - set = set, - relations = listOf(relation), + set = set ) // TESTING @@ -216,7 +215,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), + ) // TESTING @@ -310,7 +309,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), + ) // TESTING @@ -404,7 +403,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), + ) // TESTING @@ -498,7 +497,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), + ) // TESTING @@ -592,7 +591,7 @@ class ObjectSetGridNumberCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), + ) // TESTING diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridObjectCellRenderingTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridObjectCellRenderingTest.kt index 4478044ce9..0259f139b5 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridObjectCellRenderingTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridObjectCellRenderingTest.kt @@ -13,6 +13,7 @@ import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.emojifier.data.DefaultDocumentEmojiIconProvider import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.relations.ObjectSetConfig import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText @@ -109,20 +110,19 @@ class ObjectSetGridObjectCellRenderingTest : TestObjectSetSetup() { ) ) - val details = Block.Details( + val details = ObjectViewDetails( details = defaultDetails.details + mapOf( - object1Id to Block.Fields( + object1Id to mapOf( ObjectSetConfig.NAME_KEY to object1Name, "iconEmoji" to "👤" ) - ), - object2Id to Block.Fields( + , + object2Id to mapOf( ObjectSetConfig.NAME_KEY to object2Name, "iconEmoji" to "👤" ) - ) ) ) @@ -139,7 +139,6 @@ class ObjectSetGridObjectCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), details = details ) @@ -221,22 +220,20 @@ class ObjectSetGridObjectCellRenderingTest : TestObjectSetSetup() { ) ) - val details = Block.Details( + val details = ObjectViewDetails( details = defaultDetails.details + mapOf( - object1Id to Block.Fields( + object1Id to mapOf( ObjectSetConfig.NAME_KEY to object1Name, ObjectSetConfig.TYPE_KEY to objectType.url, "iconEmoji" to "👤" - ) - ), - object2Id to Block.Fields( + ), + object2Id to mapOf( ObjectSetConfig.NAME_KEY to object2Name, ObjectSetConfig.TYPE_KEY to objectType.url, "iconEmoji" to "👤" ) - ) ) ) @@ -253,7 +250,7 @@ class ObjectSetGridObjectCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), + details = details, ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridPrimitiveRelationTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridPrimitiveRelationTest.kt index b084ca6b48..833608bc83 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridPrimitiveRelationTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridPrimitiveRelationTest.kt @@ -169,7 +169,6 @@ class ObjectSetGridPrimitiveRelationTest : TestObjectSetSetup() { val set = listOf(root, header, title, dataview) stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation1, relation2, relation3, relation4, relation5), details = defaultDetails, ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridTagCellRenderingTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridTagCellRenderingTest.kt index 749c07f38e..2533f21a3f 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridTagCellRenderingTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetGridTagCellRenderingTest.kt @@ -11,6 +11,7 @@ import com.anytypeio.anytype.core_models.DVViewerRelation import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.emojifier.data.DefaultDocumentEmojiIconProvider import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubTextContent +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.relations.ObjectSetConfig import com.anytypeio.anytype.test_utils.MockDataFactory import com.anytypeio.anytype.test_utils.utils.checkHasText @@ -120,7 +121,7 @@ class ObjectSetGridTagCellRenderingTest : TestObjectSetSetup() { ) ) - val details = Block.Details() + val details = ObjectViewDetails.EMPTY val root = Block( id = ctx, @@ -135,7 +136,6 @@ class ObjectSetGridTagCellRenderingTest : TestObjectSetSetup() { stubInterceptThreadStatus() stubOpenObjectSetWithRecord( set = set, - relations = listOf(relation), details = details ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetHeaderTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetHeaderTest.kt index 0c39b7d96d..457ae0d8eb 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetHeaderTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/ObjectSetHeaderTest.kt @@ -79,8 +79,7 @@ class ObjectSetHeaderTest : TestObjectSetSetup() { stubSubscriptionEventChannel() stubOpenObjectSet( set = set, - relations = emptyList(), - details = defaultDetails + details = defaultDetails.details ) // TESTING diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/TestObjectSetSetup.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/TestObjectSetSetup.kt index bc70801e56..2a7a278d95 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/TestObjectSetSetup.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/dv/TestObjectSetSetup.kt @@ -10,7 +10,9 @@ import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.Relation +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.SearchResult +import com.anytypeio.anytype.core_models.Struct import com.anytypeio.anytype.core_models.SubscriptionEvent import com.anytypeio.anytype.core_models.primitives.SpaceId import com.anytypeio.anytype.device.providers.AppDefaultDateFormatProviderImpl @@ -66,6 +68,7 @@ import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate import com.anytypeio.anytype.presentation.common.Action import com.anytypeio.anytype.presentation.common.Delegator import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.ObjectSetDatabase import com.anytypeio.anytype.presentation.sets.ObjectSetPaginator import com.anytypeio.anytype.presentation.sets.ObjectSetSession @@ -216,13 +219,12 @@ abstract class TestObjectSetSetup { children = listOf(title.id) ) - val defaultDetails = Block.Details( + val defaultDetails = ObjectViewDetails( mapOf( - ctx to Block.Fields( - mapOf( - "iconEmoji" to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - ) - ) + ctx to + mapOf( + Relations.ICON_EMOJI to DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() + ) ) ) @@ -347,8 +349,7 @@ abstract class TestObjectSetSetup { fun stubOpenObjectSet( set: List, - details: Block.Details = Block.Details(), - relations: List = emptyList() + details: Map = emptyMap() ) { repo.stub { onBlocking { openObjectSet(ctx, SpaceId(defaultSpace)) } doReturn Result.Success( @@ -369,8 +370,7 @@ abstract class TestObjectSetSetup { fun stubOpenObjectSetWithRecord( set: List, - details: Block.Details = Block.Details(), - relations: List = emptyList() + details: ObjectViewDetails = ObjectViewDetails.EMPTY ) { repo.stub { onBlocking { openObjectSet(ctx, SpaceId(defaultSpace)) } doReturn Result.Success( @@ -380,7 +380,7 @@ abstract class TestObjectSetSetup { Event.Command.ShowObject( context = ctx, root = ctx, - details = details, + details = details.details, blocks = set, ) ) diff --git a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/sort/ViewerObjectSortTest.kt b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/sort/ViewerObjectSortTest.kt index dc4b13ec2e..77624893c6 100644 --- a/app/src/androidTest/java/com/anytypeio/anytype/features/sets/sort/ViewerObjectSortTest.kt +++ b/app/src/androidTest/java/com/anytypeio/anytype/features/sets/sort/ViewerObjectSortTest.kt @@ -19,6 +19,7 @@ import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers import com.anytypeio.anytype.domain.block.repo.BlockRepository import com.anytypeio.anytype.domain.dataview.interactor.UpdateDataViewViewer import com.anytypeio.anytype.domain.objects.StoreOfRelations +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.sort.ViewerSortViewModel import com.anytypeio.anytype.presentation.sets.state.ObjectState import com.anytypeio.anytype.presentation.util.Dispatcher @@ -131,7 +132,8 @@ class ViewerObjectSortTest { ) ) - ) + ), + details = ObjectViewDetails.EMPTY ) // Launching fragment diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/EditorDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/EditorDI.kt index 74e0007279..f2f72d37cf 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/EditorDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/EditorDI.kt @@ -2,8 +2,6 @@ package com.anytypeio.anytype.di.feature import android.content.Context import com.anytypeio.anytype.analytics.base.Analytics -import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_utils.di.scope.PerScreen import com.anytypeio.anytype.core_utils.tools.FeatureToggles @@ -119,11 +117,10 @@ import com.anytypeio.anytype.presentation.editor.toggle.ToggleStateHolder import com.anytypeio.anytype.presentation.objects.LockedStateProvider import com.anytypeio.anytype.presentation.relations.providers.DefaultObjectRelationProvider import com.anytypeio.anytype.presentation.relations.providers.DefaultObjectValueProvider -import com.anytypeio.anytype.presentation.relations.providers.ObjectDetailProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider.Companion.INTRINSIC_PROVIDER_TYPE import com.anytypeio.anytype.presentation.relations.providers.ObjectValueProvider -import com.anytypeio.anytype.presentation.relations.providers.RelationListProvider +import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationListProvider import com.anytypeio.anytype.presentation.templates.ObjectTypeTemplatesContainer import com.anytypeio.anytype.presentation.util.CopyFileToCacheDirectory import com.anytypeio.anytype.presentation.util.DefaultCopyFileToCacheDirectory @@ -230,7 +227,7 @@ object EditorSessionModule { @PerScreen fun relationListProvider( storage: Editor.Storage - ) : RelationListProvider = RelationListProvider.EditorRelationListProvider( + ) : ObjectRelationListProvider = ObjectRelationListProvider.EditorRelationListProvider( storage = storage ) @@ -902,15 +899,6 @@ object EditorUseCaseModule { storage: Editor.Storage ): ObjectValueProvider = DefaultObjectValueProvider(storage.details) - @JvmStatic - @Provides - @PerScreen - fun provideObjectDetailProvider( - storage: Editor.Storage - ): ObjectDetailProvider = object : ObjectDetailProvider { - override fun provide(): Map = storage.details.current().details - } - @JvmStatic @Provides @PerScreen diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectMenuDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectMenuDI.kt index e232014272..100a3caece 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectMenuDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectMenuDI.kt @@ -12,7 +12,6 @@ import com.anytypeio.anytype.domain.block.repo.BlockRepository import com.anytypeio.anytype.domain.collections.AddObjectToCollection import com.anytypeio.anytype.domain.config.UserSettingsRepository import com.anytypeio.anytype.domain.dashboard.interactor.SetObjectListIsFavorite -import com.anytypeio.anytype.domain.misc.DateProvider import com.anytypeio.anytype.domain.misc.DeepLinkResolver import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.multiplayer.GetSpaceInviteLink @@ -135,7 +134,7 @@ object ObjectMenuModule { dispatcher = dispatcher, updateFields = updateFields, delegator = delegator, - menuOptionsProvider = createMenuOptionsProvider(storage, featureToggles), + menuOptionsProvider = createMenuOptionsProvider(storage), addObjectToCollection = addObjectToCollection, createTemplateFromObject = createTemplateFromObject, setObjectDetails = setObjectDetails, @@ -163,11 +162,10 @@ object ObjectMenuModule { ) @JvmStatic - private fun createMenuOptionsProvider(storage: Editor.Storage, featureToggles: FeatureToggles) = + private fun createMenuOptionsProvider(storage: Editor.Storage): ObjectMenuOptionsProvider = ObjectMenuOptionsProviderImpl( - details = storage.details.stream().map { it.details }, - restrictions = storage.objectRestrictions.stream(), - featureToggles = featureToggles + objectViewDetailsFlow = storage.details.stream(), + restrictions = storage.objectRestrictions.stream() ) @JvmStatic @@ -254,7 +252,7 @@ object ObjectSetMenuModule { analytics = analytics, objectState = state, dispatcher = dispatcher, - menuOptionsProvider = createMenuOptionsProvider(state, featureToggles), + menuOptionsProvider = createMenuOptionsProvider(state), addObjectToCollection = addObjectToCollection, debugGoroutinesShareDownloader = debugGoroutinesShareDownloader, createWidget = createWidget, @@ -323,18 +321,15 @@ object ObjectSetMenuModule { @JvmStatic private fun createMenuOptionsProvider( state: StateFlow, - featureToggles: FeatureToggles ): ObjectMenuOptionsProvider { return when (val currentState = state.value) { is ObjectState.DataView -> ObjectMenuOptionsProviderImpl( - details = state.map { currentState.details }.distinctUntilChanged(), + objectViewDetailsFlow = state.map { currentState.details }.distinctUntilChanged(), restrictions = state.map { currentState.objectRestrictions }.distinctUntilChanged(), - featureToggles = featureToggles ) else -> ObjectMenuOptionsProviderImpl( - details = emptyFlow(), + objectViewDetailsFlow = emptyFlow(), restrictions = emptyFlow(), - featureToggles = featureToggles ) } } diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectRelationListDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectRelationListDI.kt index a7467b1382..444fc471df 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectRelationListDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectRelationListDI.kt @@ -16,7 +16,7 @@ import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate import com.anytypeio.anytype.presentation.objects.LockedStateProvider import com.anytypeio.anytype.presentation.relations.ObjectRelationListViewModelFactory import com.anytypeio.anytype.presentation.relations.RelationListViewModel -import com.anytypeio.anytype.presentation.relations.providers.RelationListProvider +import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationListProvider import com.anytypeio.anytype.presentation.util.Dispatcher import com.anytypeio.anytype.ui.relations.ObjectRelationListFragment import dagger.BindsInstance @@ -47,7 +47,7 @@ object ObjectRelationListModule { fun factory( vmParams: RelationListViewModel.VmParams, lockedStateProvider: LockedStateProvider, - relationListProvider: RelationListProvider, + objectRelationListProvider: ObjectRelationListProvider, urlBuilder: UrlBuilder, dispatcher: Dispatcher, updateDetail: UpdateDetail, @@ -63,7 +63,7 @@ object ObjectRelationListModule { return ObjectRelationListViewModelFactory( vmParams = vmParams, lockedStateProvider = lockedStateProvider, - relationListProvider = relationListProvider, + objectRelationListProvider = objectRelationListProvider, urlBuilder = urlBuilder, dispatcher = dispatcher, updateDetail = updateDetail, diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectSetDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectSetDI.kt index 19d2b76e1d..ed8d4b63e7 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectSetDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/ObjectSetDI.kt @@ -2,7 +2,6 @@ package com.anytypeio.anytype.di.feature import android.content.Context import com.anytypeio.anytype.analytics.base.Analytics -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.primitives.Space @@ -69,12 +68,11 @@ import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider import com.anytypeio.anytype.presentation.objects.LockedStateProvider import com.anytypeio.anytype.presentation.relations.providers.DataViewObjectRelationProvider import com.anytypeio.anytype.presentation.relations.providers.DataViewObjectValueProvider -import com.anytypeio.anytype.presentation.relations.providers.ObjectDetailProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider.Companion.DATA_VIEW_PROVIDER_TYPE import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider.Companion.INTRINSIC_PROVIDER_TYPE import com.anytypeio.anytype.presentation.relations.providers.ObjectValueProvider -import com.anytypeio.anytype.presentation.relations.providers.RelationListProvider +import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationListProvider import com.anytypeio.anytype.presentation.relations.providers.SetOrCollectionObjectValueProvider import com.anytypeio.anytype.presentation.relations.providers.SetOrCollectionRelationProvider import com.anytypeio.anytype.presentation.sets.ObjectSetDatabase @@ -421,20 +419,6 @@ object ObjectSetModule { db = db ) - @JvmStatic - @Provides - @PerScreen - fun provideObjectDetailProvider( - objectState: MutableStateFlow, - ): ObjectDetailProvider = object : ObjectDetailProvider { - override fun provide(): Map { - return when (val state = objectState.value) { - is ObjectState.DataView -> state.details - else -> emptyMap() - } - } - } - @JvmStatic @Provides @PerScreen @@ -572,7 +556,7 @@ object ObjectSetModule { @PerScreen fun dataViewRelationListProvider( objectStateFlow: MutableStateFlow - ) : RelationListProvider = RelationListProvider.ObjectSetRelationListProvider( + ) : ObjectRelationListProvider = ObjectRelationListProvider.ObjectSetRelationListProvider( objectStates = objectStateFlow ) diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/Block.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/Block.kt index 79c1ba1713..a1377a581c 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/Block.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/Block.kt @@ -73,12 +73,6 @@ data class Block( } } - /** - * Document metadata - * @property details maps id of the block to its details (contained as fields) - */ - data class Details(val details: Map = emptyMap()) - /** * Block's content. */ diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/Event.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/Event.kt index 4e76bb561d..aee35fa8aa 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/Event.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/Event.kt @@ -22,7 +22,7 @@ sealed class Event { data class ShowObject( override val context: Id, val root: Id, - val details: Block.Details = Block.Details(emptyMap()), + val details: Map = emptyMap(), val blocks: List, val objectRestrictions: List = emptyList(), val dataViewRestrictions: List = emptyList() @@ -30,8 +30,7 @@ sealed class Event { data class AddBlock( override val context: String, - val blocks: List, - val details: Block.Details = Block.Details(emptyMap()) + val blocks: List ) : Command() /** @@ -128,39 +127,38 @@ sealed class Event { val fields: Block.Fields ) : Command() - sealed class Details : Command() { /** - * Command to set details (metadata) of the target block. + * Command to set details (metadata) of the target Object. * Overwrites existing state. * @property context id of the context - * @property target id of the target block, whose details we need to update - * @property details details of the target block + * @property target id of the target object, whose details we need to update + * @property details details of the target object */ data class Set( override val context: Id, val target: Id, - val details: Block.Fields + val details: Struct ) : Details() /** - * Command to amend details (metadata) of the target block. + * Command to amend details (metadata) of the target object. * Amend existing state. * @property context id of the context - * @property target id of the target block, whose details we need to update - * @property details slide of details of the target block + * @property target id of the target object, whose details we need to update + * @property details slide of details of the target object */ data class Amend( override val context: Id, val target: Id, - val details: Map + val details: Struct ) : Details() /** - * Command to unset details (metadata) of the target block. + * Command to unset details (metadata) of the target object. * Unset existing detail keys. * @property context id of the context - * @property target id of the target block, whose details we need to update + * @property target id of the target object, whose details we need to update * @property keys */ data class Unset( @@ -170,7 +168,6 @@ sealed class Event { ) : Details() } - /** * Command to update file block content */ diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectViewDetails.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectViewDetails.kt new file mode 100644 index 0000000000..f180229bcb --- /dev/null +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectViewDetails.kt @@ -0,0 +1,7 @@ +package com.anytypeio.anytype.core_models + +data class ObjectViewDetails(val details: Map) { + companion object { + val EMPTY = ObjectViewDetails(emptyMap()) + } +} \ No newline at end of file diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectWrapper.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectWrapper.kt index 84631ee433..0ff50435d0 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectWrapper.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/ObjectWrapper.kt @@ -35,7 +35,7 @@ sealed class ObjectWrapper { val coverType: CoverType get() = when (val value = map[Relations.COVER_TYPE]) { - is Double -> CoverType.values().find { type -> + is Double -> CoverType.entries.find { type -> type.code == value.toInt() } ?: CoverType.NONE else -> CoverType.NONE @@ -372,6 +372,18 @@ sealed class ObjectWrapper { val globalName: String? by default } + + data class Date(override val map: Struct) : ObjectWrapper() { + private val default = map.withDefault { null } + val id: Id by default + val name: String? by default + val timestamp: Double? + get() = when (val value = map[Relations.TIMESTAMP]) { + is Double -> value + is Int -> value.toDouble() + else -> null + } + } } inline fun Struct.getSingleValue(relation: Key): T? = diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/DetailsExt.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/DetailsExt.kt deleted file mode 100644 index 5d2b282dfd..0000000000 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/DetailsExt.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.anytypeio.anytype.core_models.ext - -import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.core_models.Event -import com.anytypeio.anytype.core_models.Id - -fun Block.Details.process(event: Event.Command.Details) = when (event) { - is Event.Command.Details.Set -> set(event.target, event.details) - is Event.Command.Details.Amend -> amend(event.target, event.details) - is Event.Command.Details.Unset -> unset(event.target, event.keys) -} - -fun Block.Details.set( - target: Id, - fields: Block.Fields -): Block.Details = Block.Details(details + mapOf(target to fields)) - -fun Map.amend( - target: Id, - slice: Map -) : Map { - return toMutableMap().apply { - val current = getOrDefault(target, Block.Fields.empty()) - val new = Block.Fields(current.map + slice) - set(target, new) - } -} - -fun Block.Details.amend( - target: Id, - slice: Map -): Block.Details { - val updated = details.toMutableMap().apply { - val current = getOrDefault(target, Block.Fields.empty()) - val new = Block.Fields(current.map + slice) - set(target, new) - } - return Block.Details(updated) -} - -fun Block.Details.unset( - target: Id, - keys: List -): Block.Details { - val updated = details.toMutableMap().apply { - val current = getOrDefault(target, Block.Fields.empty()) - val new = Block.Fields( - current.map.toMutableMap().apply { - keys.forEach { key -> remove(key) } - } - ) - set(target, new) - } - return Block.Details(updated) -} - -fun Map.unset( - target: Id, - keys: List -) : Map { - return toMutableMap().apply { - val current = getOrDefault(target, Block.Fields.empty()) - val new = Block.Fields( - current.map.toMutableMap().apply { - keys.forEach { key -> remove(key) } - } - ) - set(target, new) - } -} diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/MarkupExt.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/MarkupExt.kt index 5905bf6185..9ef1c73587 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/MarkupExt.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/MarkupExt.kt @@ -1,6 +1,5 @@ package com.anytypeio.anytype.core_models.ext -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Block.Content.Text.Mark import com.anytypeio.anytype.core_models.misc.Overlap diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/StructExt.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/StructExt.kt index b6a1d6a4f3..d5daca26e6 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/StructExt.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/ext/StructExt.kt @@ -6,8 +6,8 @@ import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.Struct -fun Map.process(event: Event.Command.Details) = when (event) { - is Event.Command.Details.Set -> set(event.target, event.details.map) +fun Map.process(event: Event.Command.Details): Map = when (event) { + is Event.Command.Details.Set -> set(event.target, event.details) is Event.Command.Details.Amend -> amend(event.target, event.details) is Event.Command.Details.Unset -> unset(event.target, event.keys) } @@ -45,10 +45,37 @@ fun Struct.mapToObjectWrapperType(): ObjectWrapper.Type? = if (containsKey(Relations.ID) && containsKey(Relations.UNIQUE_KEY)) ObjectWrapper.Type(this) else null -inline fun Struct.getValues(key: String): List { - return when (val value = getOrDefault(key, emptyList())) { - is T -> listOf(value) - is List<*> -> value.typeOf() - else -> emptyList() - } +fun Struct?.toObject(): ObjectWrapper.Basic? { + if (this == null || !isValidObject()) return null + return ObjectWrapper.Basic(this) +} + +fun Struct?.mapToOptionObject(): ObjectWrapper.Option? { + if (this == null) return null + return ObjectWrapper.Option(this) +} + +fun Struct?.toFileObject(): ObjectWrapper.File? { + if (this == null || !isValidObject()) return null + return ObjectWrapper.File(this) +} + + +fun Struct?.toDateObject(): ObjectWrapper.Date? { + if (this == null || !isValidObject()) return null + return ObjectWrapper.Date(this) +} + +fun Struct?.toBookmarkObject(): ObjectWrapper.Bookmark? { + if (this == null || !isValidObject()) return null + return ObjectWrapper.Bookmark(this) +} + +fun Struct?.toInternalFlagsObject(): ObjectWrapper.ObjectInternalFlags? { + if (this.isNullOrEmpty()) return null + return ObjectWrapper.ObjectInternalFlags(this) +} + +fun Struct.isValidObject(): Boolean { + return contains(Relations.ID) } \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/model/HomeDashboard.kt b/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/model/HomeDashboard.kt deleted file mode 100644 index 054b9850f0..0000000000 --- a/domain/src/main/java/com/anytypeio/anytype/domain/dashboard/model/HomeDashboard.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.anytypeio.anytype.domain.dashboard.model - -import com.anytypeio.anytype.core_models.Block - -data class HomeDashboard( - val id: String, - val blocks: List, - val children: List, - val fields: Block.Fields, - val details: Block.Details = Block.Details(emptyMap()) -) \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/page/AddBackLinkToObject.kt b/domain/src/main/java/com/anytypeio/anytype/domain/page/AddBackLinkToObject.kt index b57cc3a78b..51227bb63e 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/page/AddBackLinkToObject.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/page/AddBackLinkToObject.kt @@ -41,7 +41,7 @@ class AddBackLinkToObject( ?.children ?.last() - val objectDetails = event.details.details[params.objectToPlaceLink]?.map + val objectDetails = event.details[params.objectToPlaceLink] require(targetBlock != null) { "Target block is missing" } require(objectDetails != null) { "Object details is missing" } diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/MiddlewareEventMapper.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/MiddlewareEventMapper.kt index c90f031d60..c688d9877a 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/MiddlewareEventMapper.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/MiddlewareEventMapper.kt @@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.middleware.BuildConfig import com.anytypeio.anytype.middleware.mappers.MWidgetLayout import com.anytypeio.anytype.middleware.mappers.core +import com.anytypeio.anytype.middleware.mappers.toCoreFieldsModel import com.anytypeio.anytype.middleware.mappers.toCoreModel import com.anytypeio.anytype.middleware.mappers.toCoreModels import com.anytypeio.anytype.middleware.mappers.toCoreModelsAlign @@ -118,7 +119,7 @@ fun anytype.Event.Message.toCoreModels( Event.Command.UpdateFields( context = context, target = event.id, - fields = event.fields.toCoreModel() + fields = event.fields.toCoreFieldsModel() ) } blockSetFile != null -> { diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToCoreModelMappers.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToCoreModelMappers.kt index 5ecfe54462..aa0052eab3 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToCoreModelMappers.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToCoreModelMappers.kt @@ -89,11 +89,7 @@ fun MObjectView.toPayload(): Payload { context = rootId, root = rootId, blocks = blocks.toCoreModels(), - details = Block.Details( - details.associate { details -> - details.id to details.details.toCoreModel() - } - ), + details = details.associate { d -> d.id to d.details.orEmpty() }, objectRestrictions = restrictions?.object_?.map { it.toCoreModel() }.orEmpty(), dataViewRestrictions = restrictions?.dataview?.map { it.toCoreModel() }.orEmpty() ) @@ -299,7 +295,9 @@ fun List.toCoreModels(): List = mapNotNull { block -> } } -fun Map?.toCoreModel(): Block.Fields = Block.Fields(this?.toMap().orEmpty()) +fun Map?.toCoreFieldsModel(): Block.Fields = Block.Fields(this?.toMap().orEmpty()) + +fun Map?.toCoreModel(): Map = this?.toMap().orEmpty() fun MBlock.toCoreModelsText(): Block.Content.Text { val content = checkNotNull(text) diff --git a/middleware/src/test/java/com/anytypeio/anytype/MiddlewareEventChannelTest.kt b/middleware/src/test/java/com/anytypeio/anytype/MiddlewareEventChannelTest.kt index d7b5d6d3d7..228e2c829d 100644 --- a/middleware/src/test/java/com/anytypeio/anytype/MiddlewareEventChannelTest.kt +++ b/middleware/src/test/java/com/anytypeio/anytype/MiddlewareEventChannelTest.kt @@ -276,7 +276,7 @@ class MiddlewareEventChannelTest { val icon = Pair("icon", ":package:") val name = Pair("name", "Document I") - val details = com.anytypeio.anytype.core_models.Block.Fields(map = mutableMapOf(icon, name)) + val details = mutableMapOf(icon, name) val msg = anytype.Event.Object.Details.Set( id = id, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt index 9c427be232..11e19b07e2 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/EditorViewModel.kt @@ -29,7 +29,6 @@ import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.Position import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.core_models.RelationFormat -import com.anytypeio.anytype.core_models.RelationLink import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.Struct import com.anytypeio.anytype.core_models.TextBlock @@ -41,7 +40,6 @@ import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.core_models.ext.descendants import com.anytypeio.anytype.core_models.ext.isAllTextAndNoneCodeBlocks import com.anytypeio.anytype.core_models.ext.isAllTextBlocks -import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType import com.anytypeio.anytype.core_models.ext.parents import com.anytypeio.anytype.core_models.ext.process import com.anytypeio.anytype.core_models.ext.sortByType @@ -247,15 +245,24 @@ import com.anytypeio.anytype.presentation.objects.ObjectTypeView import com.anytypeio.anytype.core_models.SupportedLayouts import com.anytypeio.anytype.core_models.TimeInMillis import com.anytypeio.anytype.core_models.TimeInSeconds +import com.anytypeio.anytype.core_models.ext.toObject import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions import com.anytypeio.anytype.presentation.editor.ControlPanelMachine.Event.SAM.* -import com.anytypeio.anytype.presentation.editor.editor.Intent.Clipboard.* +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.editor.editor.Intent.Clipboard.Copy +import com.anytypeio.anytype.presentation.editor.editor.Intent.Clipboard.Paste import com.anytypeio.anytype.presentation.editor.editor.ext.isAllowedToShowTypesWidget +import com.anytypeio.anytype.presentation.extension.getBookmarkObject +import com.anytypeio.anytype.presentation.extension.getInternalFlagsObject +import com.anytypeio.anytype.presentation.extension.getObject +import com.anytypeio.anytype.presentation.extension.getTypeObject import com.anytypeio.anytype.presentation.editor.model.OnEditorDatePickerEvent.OnDatePickerDismiss import com.anytypeio.anytype.presentation.editor.model.OnEditorDatePickerEvent.OnDateSelected import com.anytypeio.anytype.presentation.editor.model.OnEditorDatePickerEvent.OnTodayClick import com.anytypeio.anytype.presentation.editor.model.OnEditorDatePickerEvent.OnTomorrowClick import com.anytypeio.anytype.presentation.extension.getFileDetailsForBlock +import com.anytypeio.anytype.presentation.extension.getObjRelationsViews +import com.anytypeio.anytype.presentation.extension.getRecommendedRelations import com.anytypeio.anytype.presentation.extension.getUrlForFileContent import com.anytypeio.anytype.presentation.navigation.NavPanelState import com.anytypeio.anytype.presentation.objects.getCreateObjectParams @@ -264,9 +271,6 @@ import com.anytypeio.anytype.presentation.objects.getProperType import com.anytypeio.anytype.presentation.objects.isTemplatesAllowed import com.anytypeio.anytype.presentation.objects.toViews import com.anytypeio.anytype.presentation.relations.ObjectRelationView -import com.anytypeio.anytype.presentation.relations.getNotIncludedRecommendedRelations -import com.anytypeio.anytype.presentation.relations.getObjectRelations -import com.anytypeio.anytype.presentation.relations.views import com.anytypeio.anytype.presentation.search.ObjectSearchConstants import com.anytypeio.anytype.presentation.search.ObjectSearchViewModel import com.anytypeio.anytype.presentation.sync.SyncStatusWidgetState @@ -485,7 +489,7 @@ class EditorViewModel( override fun onPickedDocImageFromDevice(ctx: Id, path: String) { viewModelScope.launch { - val obj = orchestrator.stores.details.getAsObject(ctx) + val obj = orchestrator.stores.details.current().getObject(vmParams.ctx) val space = obj?.spaceId if (space != null) { setDocImageIcon( @@ -526,7 +530,7 @@ class EditorViewModel( success = { hash -> setDocCoverImage( SetDocCoverImage.Params.FromHash( - context = context, + context = vmParams.ctx, hash = hash ) ).process( @@ -602,11 +606,17 @@ class EditorViewModel( events.forEach { event -> when (event) { is Event.Command.ShowObject -> { - orchestrator.stores.details.update(event.details) + orchestrator.stores.details.update( + ObjectViewDetails( + details = event.details + ) + ) orchestrator.stores.objectRestrictions.update(event.objectRestrictions) } is Event.Command.Details -> { - orchestrator.stores.details.apply { update(current().process(event)) } + orchestrator.stores.details.apply { + update(ObjectViewDetails(details = current().details.process(event))) + } } else -> { // do nothing @@ -617,7 +627,7 @@ class EditorViewModel( if (featureToggles.isLogEditorViewModelEvents) { Timber.d("Blocks after handling events: ${blocks.toPrettyString()}") } - return events.flags(context) + return events.flags(vmParams.ctx) } private fun startProcessingControlPanelViewState() { @@ -679,7 +689,7 @@ class EditorViewModel( rerenderingBlocks(newBlock) proceedWithUpdatingText( intent = Intent.Text.UpdateText( - context = context, + context = vmParams.ctx, text = newBlock.content.asText().text, target = targetBlock.id, marks = sortedMarks @@ -757,7 +767,8 @@ class EditorViewModel( .withLatestFrom( orchestrator.stores.focus.stream(), orchestrator.stores.details.stream() - ) { models, focus, details -> + ) { models, focus, objectViewDetails -> + val currentObj = objectViewDetails.getObject(vmParams.ctx) val permission = permission.value val root = models.first { it.id == context } if (mode == EditorMode.Locked) { @@ -781,7 +792,7 @@ class EditorViewModel( } } - footers.value = getFooterState(root, details) + footers.value = getFooterState(root, currentObj) val flags = mutableListOf() Timber.d("Rendering starting...") val doc = models.asMap().render( @@ -791,7 +802,7 @@ class EditorViewModel( focus = focus, anchor = context, indent = INITIAL_INDENT, - details = details, + details = objectViewDetails, restrictions = orchestrator.stores.objectRestrictions.current(), selection = currentSelection() ) { onRenderFlagFound -> flags.add(onRenderFlagFound) } @@ -1128,8 +1139,8 @@ class EditorViewModel( } } root.children.size == 2 -> { - val layout = event.details.details[root.id]?.layout - if (layout == ObjectType.Layout.NOTE.code.toDouble()) { + val layout = event.details[root.id].toObject()?.layout + if (layout == ObjectType.Layout.NOTE) { val block = event.blocks.firstOrNull { it.content is Content.Text } if (block != null && block.content().text.isEmpty()) { val focus = Editor.Focus( @@ -1544,15 +1555,10 @@ class EditorViewModel( } private fun proceedWithOpeningObjectMenu() { - if (context.isEmpty()) { - sendToast("Your object is not initialized. Please, try again later.") - return - } controlPanelInteractor.onEvent(ControlPanelMachine.Event.OnDocumentMenuClicked) - val details = orchestrator.stores.details.current().details - val wrapper = ObjectWrapper.Basic(details[context]?.map.orEmpty()) + val wrapper = orchestrator.stores.details.current().getObject(vmParams.ctx) val isTemplate = isObjectTemplate() - val space = wrapper.spaceId + val space = wrapper?.spaceId if (space == null) { sendToast("Space not found") return @@ -1565,7 +1571,7 @@ class EditorViewModel( dispatch( command = Command.OpenDocumentMenu( ctx = context, - space = space, + space = vmParams.space.id, isArchived = false, isFavorite = false, isLocked = false, @@ -1578,9 +1584,9 @@ class EditorViewModel( dispatch( command = Command.OpenDocumentMenu( ctx = context, - space = space, - isArchived = details[context]?.isArchived ?: false, - isFavorite = details[context]?.isFavorite ?: false, + space = vmParams.space.id, + isArchived = wrapper?.isArchived == true, + isFavorite = wrapper?.isFavorite == true, isLocked = mode == EditorMode.Locked, isReadOnly = isReadOnly, isTemplate = isObjectTemplate() @@ -1877,19 +1883,19 @@ class EditorViewModel( is Content.Bookmark -> { excludedActions.add(ActionItemType.Download) if (!isMultiMode) { - if (content.targetObjectId != null) { - val details = orchestrator.stores.details.current().details - val obj = ObjectWrapper.Basic( - details[content.targetObjectId]?.map ?: emptyMap() - ) - val isReady = content.state == Content.Bookmark.State.DONE - val isActive = obj.isArchived != true && obj.isDeleted != true - val idx = targetActions.indexOf(ActionItemType.OpenObject) - if (idx == NO_POSITION && isReady && isActive) { - targetActions.add( - OPEN_OBJECT_POSITION, - ActionItemType.OpenObject - ) + val targetObjectId = content.targetObjectId + if (targetObjectId != null) { + val obj = orchestrator.stores.details.current().getObject(targetObjectId) + if (obj != null) { + val isReady = content.state == Content.Bookmark.State.DONE + val isActive = obj.isArchived != true && obj.isDeleted != true + val idx = targetActions.indexOf(ActionItemType.OpenObject) + if (idx == NO_POSITION && isReady && isActive) { + targetActions.add( + OPEN_OBJECT_POSITION, + ActionItemType.OpenObject + ) + } } } } @@ -3168,12 +3174,9 @@ class EditorViewModel( } is Content.Bookmark -> { val target = content.targetObjectId - val details = orchestrator.stores.details.current().details[target] if (target != null) { - val obj = ObjectWrapper.Bookmark(details?.map ?: mapOf()) - if (obj.isArchived != true && obj.isDeleted != true) { - proceedWithOpeningObjectByLayout(target = target) - } else { + val obj = orchestrator.stores.details.current().getBookmarkObject(target) + if (obj?.isArchived == true || obj?.isDeleted == true) { val source = obj.source if (!source.isNullOrBlank()) { commands.postValue( @@ -3184,6 +3187,8 @@ class EditorViewModel( } else { sendToast("Source is missing for this object") } + } else { + proceedWithOpeningObjectByLayout(target = target) } } else { sendToast("Couldn't find the target of the link") @@ -3200,15 +3205,9 @@ class EditorViewModel( private fun proceedWithOpeningDataViewBlock(dv: Content.DataView) { if (dv.targetObjectId.isNotEmpty()) { - val targetSpace = orchestrator.stores.details.current().let { details -> - val detail = details.details[dv.targetObjectId] - if (detail != null && detail.map.isNotEmpty()) { - val wrapper = ObjectWrapper.Basic(detail.map) - wrapper.spaceId ?: vmParams.space.id - } else { - vmParams.space.id - } - } + val targetSpace = + orchestrator.stores.details.current().getObject(dv.targetObjectId)?.spaceId + ?: vmParams.space.id proceedWithOpeningDataViewObject( target = dv.targetObjectId, space = SpaceId(targetSpace) @@ -3229,9 +3228,8 @@ class EditorViewModel( private fun proceedWithOpeningObjectByLayout(target: String) { proceedWithClearingFocus() - val details = orchestrator.stores.details.current() - val wrapper = ObjectWrapper.Basic(map = details.details[target]?.map ?: emptyMap()) - if (wrapper.spaceId != vmParams.space.id) { + val wrapper = orchestrator.stores.details.current().getObject(target) + if (wrapper?.spaceId != vmParams.space.id) { sendToast("Cannot open object from another space from here.") } else { when (wrapper.layout) { @@ -3288,7 +3286,7 @@ class EditorViewModel( } else -> { - sendToast("Cannot open object with layout: ${wrapper.layout}") + sendToast("Cannot open object with layout: ${wrapper?.layout}") } } } @@ -3420,7 +3418,7 @@ class EditorViewModel( fun onSetObjectIconClicked() { viewModelScope.launch { - val obj = orchestrator.stores.details.getAsObject(context) + val obj = orchestrator.stores.details.current().getObject(vmParams.ctx) val space = obj?.spaceId if (space != null) { dispatch(Command.SetObjectIcon(ctx = context, space = space)) @@ -4254,7 +4252,7 @@ class EditorViewModel( val isDetailsAllowed = restrictions.none { it == ObjectRestriction.DETAILS } if (isDetailsAllowed) { controlPanelInteractor.onEvent(ControlPanelMachine.Event.OnDocumentIconClicked) - val obj = orchestrator.stores.details.getAsObject(context) + val obj = orchestrator.stores.details.current().getObject(vmParams.ctx) val space = obj?.spaceId if (space != null) { dispatch( @@ -4332,7 +4330,7 @@ class EditorViewModel( private fun proceedWithDownloadCurrentObjectAsFile() { - val fileObject = orchestrator.stores.details.getAsObject(target = context) + val fileObject = orchestrator.stores.details.current().getObject(vmParams.ctx) if (fileObject == null) { Timber.e("Object with id $context not found.") return @@ -5263,24 +5261,21 @@ class EditorViewModel( } private fun getRelations(action: (List) -> Unit) { - val details = orchestrator.stores.details.current() - val objectDetails = details.details[context]?.map ?: emptyMap() - val objectWrapper = ObjectWrapper.Basic(objectDetails) - val objectType = objectWrapper.getProperType() + val objectViewDetails = orchestrator.stores.details.current() viewModelScope.launch { - val objectRelationViews = getObjectRelationsView( - ctx = context, - objectDetails = objectDetails, - details = details, - objectWrapper = objectWrapper + val objectRelationViews = objectViewDetails.getObjRelationsViews( + ctx = vmParams.ctx, + urlBuilder = urlBuilder, + storeOfRelations = storeOfRelations, + fieldParser = fieldParser ) - val recommendedRelationViews = getRecommendedRelations( - ctx = context, - objectDetails = objectDetails, - objectTypeStruct = details.details[objectType]?.map, - details = details + val recommendedRelationViews = objectViewDetails.getRecommendedRelations( + ctx = vmParams.ctx, + storeOfRelations = storeOfRelations, + fieldParser = fieldParser, + urlBuilder = urlBuilder ) val update = (objectRelationViews + recommendedRelationViews).map { SlashRelationView.Item(it) } @@ -5289,47 +5284,6 @@ class EditorViewModel( } } - private suspend fun getObjectRelationsView( - ctx: Id, - objectDetails: Map, - details: Block.Details, - objectWrapper: ObjectWrapper.Basic - ): List { - return getObjectRelations( - systemRelations = listOf(), - storeOfRelations = storeOfRelations, - relationKeys = objectDetails.keys - ).views( - context = ctx, - details = details, - values = objectDetails, - urlBuilder = urlBuilder, - featured = objectWrapper.featuredRelations, - fieldParser = fieldParser - ) - } - - private suspend fun getRecommendedRelations( - ctx: Id, - objectDetails: Map, - objectTypeStruct: Struct?, - details: Block.Details - ): List { - val objType = objectTypeStruct?.mapToObjectWrapperType() - val recommendedRelations = objType?.recommendedRelations ?: emptyList() - return getNotIncludedRecommendedRelations( - recommendedRelations = recommendedRelations, - storeOfRelations = storeOfRelations, - relationKeys = objectDetails.keys - ).views( - context = ctx, - details = details, - values = objectDetails, - urlBuilder = urlBuilder, - fieldParser = fieldParser - ) - } - private fun proceedWithObjectTypes(objectTypes: List) { onSlashWidgetStateChanged( SlashWidgetState.UpdateItems.empty().copy( @@ -6261,10 +6215,11 @@ class EditorViewModel( fun onMentionClicked(target: String) { if (isObjectTemplate()) return - val details = orchestrator.stores.details.current() - val objectDetails = details.details[target]?.map ?: return - if (objectDetails.isEmpty()) return - val obj = ObjectWrapper.Basic(objectDetails) + val obj = orchestrator.stores.details.current().getObject(target) + if (obj == null) { + Timber.w("Details missing for mentioned object") + return + } proceedWithClearingFocus() proceedWithOpeningObject(obj) } @@ -6413,7 +6368,7 @@ class EditorViewModel( private fun proceedWithGettingObjectTypesForTypesWidget() { viewModelScope.launch { - val excludeTypes = orchestrator.stores.details.current().details[context]?.type ?: emptyList() + val excludeTypes = orchestrator.stores.details.current().getObject(vmParams.ctx)?.type.orEmpty() val params = GetObjectTypes.Params( sorts = emptyList(), filters = ObjectSearchConstants.filterTypes( @@ -6454,7 +6409,7 @@ class EditorViewModel( fromFeatured: Boolean ) { val list = buildList { - val types = orchestrator.stores.details.current().details[context]?.type ?: emptyList() + val types = orchestrator.stores.details.current().getObject(vmParams.ctx)?.type.orEmpty() if (types.isNotEmpty()) { addAll(types) } @@ -6700,9 +6655,9 @@ class EditorViewModel( //endregion //region FOOTER - private fun getFooterState(root: Block, details: Block.Details): EditorFooter { - return when (details.details[root.id]?.layout?.toInt()) { - ObjectType.Layout.NOTE.code -> EditorFooter.Note + private fun getFooterState(root: Block, currentObj: ObjectWrapper.Basic?): EditorFooter { + return when (currentObj?.layout) { + ObjectType.Layout.NOTE -> EditorFooter.Note else -> EditorFooter.None } } @@ -6779,19 +6734,18 @@ class EditorViewModel( } private fun getObjectTypeUniqueKeyFromDetails(): Id? { - val details = orchestrator.stores.details.current() - val currentObject = ObjectWrapper.Basic(details.details[context]?.map ?: emptyMap()) - val currentObjectTypeId = currentObject.getProperType() ?: return null - val currentObjectType = ObjectWrapper.Basic(details.details[currentObjectTypeId]?.map ?: emptyMap()) - return currentObjectType.uniqueKey + val objectViewDetails = orchestrator.stores.details.current() + val currentObject = objectViewDetails.getObject(vmParams.ctx) + val currentObjectTypeId = currentObject?.getProperType() ?: return null + val currentObjectType = objectViewDetails.getTypeObject(currentObjectTypeId) + return currentObjectType?.uniqueKey } private fun getObjectTypeFromDetails(): ObjectWrapper.Type? { - val details = orchestrator.stores.details.current() - val currentObject = ObjectWrapper.Basic(details.details[context]?.map ?: emptyMap()) - val currentObjectTypeId = currentObject.getProperType() ?: return null - val struct = details.details[currentObjectTypeId]?.map - return struct?.mapToObjectWrapperType() + val objectViewDetails = orchestrator.stores.details.current() + val currentObject = objectViewDetails.getObject(vmParams.ctx) + val currentObjectTypeId = currentObject?.getProperType() ?: return null + return objectViewDetails.getTypeObject(currentObjectTypeId) } fun isObjectTemplate(): Boolean { @@ -7434,8 +7388,8 @@ class EditorViewModel( private fun checkRelationIsInObject( view: ObjectRelationView ): Boolean { - val currentObjectDetails = orchestrator.stores.details.getAsObject(vmParams.ctx) - return currentObjectDetails?.map?.keys?.any { it == view.key } ?: false + val currentObjectDetails = orchestrator.stores.details.current().getObject(vmParams.ctx) + return currentObjectDetails?.map?.keys?.any { it == view.key } == true } private suspend fun proceedWithAddingRelationToObject( @@ -7627,7 +7581,7 @@ class EditorViewModel( if (blocks.isAllowedToShowTypesWidget( objectRestrictions = orchestrator.stores.objectRestrictions.current(), isOwnerOrEditor = permission.value?.isOwnerOrEditor() == true, - objectLayout = orchestrator.stores.details.current().details[context]?.layout?.toInt() + objectLayout = orchestrator.stores.details.current().getObject(vmParams.ctx)?.layout ) ) { setTypesWidgetVisibility(true) @@ -7650,9 +7604,8 @@ class EditorViewModel( } private fun getInternalFlagsFromDetails(): List { - val details = orchestrator.stores.details.current() - val obj = ObjectWrapper.ObjectInternalFlags(details.details[context]?.map ?: emptyMap()) - return obj.internalFlags + val obj = orchestrator.stores.details.current().getInternalFlagsObject(vmParams.ctx) + return obj?.internalFlags ?: emptyList() } //endregion @@ -7675,11 +7628,11 @@ class EditorViewModel( spaceSyncAndP2PStatusProvider.observe(), orchestrator.stores.details.stream() ) { state, details -> - state to details.details[context]?.map + state to details.getObject(context) }.catch { Timber.e(it, "Error while observing sync status") - }.collect { (syncAndP2pState, struct) -> - if (!struct.isNullOrEmpty() && !struct.isObjectParticipant()) { + }.collect { (syncAndP2pState, obj) -> + if (obj != null && obj.layout != ObjectType.Layout.PARTICIPANT) { spaceSyncStatus.value = syncAndP2pState syncStatusWidget.value = syncStatusWidget.value.updateStatus(syncAndP2pState) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt index 0496bfa6bb..0c7bbb9226 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/Store.kt @@ -1,10 +1,6 @@ package com.anytypeio.anytype.presentation.editor.editor -import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.core_models.Id -import com.anytypeio.anytype.core_models.ObjectWrapper -import com.anytypeio.anytype.core_models.Relation -import com.anytypeio.anytype.core_models.RelationLink +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction import com.anytypeio.anytype.domain.editor.Editor import com.anytypeio.anytype.presentation.editor.editor.model.BlockView @@ -57,22 +53,7 @@ interface Store { class Screen : State>(emptyList()) - class Details : State(Block.Details()) { - suspend fun add(target: Id, fields: Block.Fields) { - update(current().copy(details = current().details + mapOf(target to fields))) - } - fun getAsObject(target: Id) : ObjectWrapper.Basic? { - val struct = current().details[target] - return if (struct != null && struct.map.isNotEmpty()) { - ObjectWrapper.Basic(struct.map) - } else { - null - } - } - } - - class Relations : State>(emptyList()) + class Details : State(ObjectViewDetails.EMPTY) class ObjectRestrictions : State>(emptyList()) class TextSelection : State(Editor.TextSelection.empty()) - class RelationLinks : State>(emptyList()) } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/BlockViewExt.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/BlockViewExt.kt index c54ddf6e03..bbc2c02826 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/BlockViewExt.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/BlockViewExt.kt @@ -3,9 +3,10 @@ package com.anytypeio.anytype.presentation.editor.editor.ext import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Document import com.anytypeio.anytype.core_models.Id -import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.presentation.editor.ControlPanelMachine +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.control.ControlPanelState +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.editor.model.BlockView.Media.Bookmark.Companion.SEARCH_FIELD_DESCRIPTION_KEY import com.anytypeio.anytype.presentation.editor.editor.model.BlockView.Media.Bookmark.Companion.SEARCH_FIELD_TITLE_KEY @@ -1194,16 +1195,16 @@ fun List.update(blockView: BlockView) = this.map { fun Document.getLinkAppearanceMenu( blockId: Id, - details: Block.Details + details: ObjectViewDetails ): BlockView.Appearance.Menu? { val block = this.find { it.id == blockId } val content = block?.content return if (block != null && content is Block.Content.Link) { val target = content.asLink().target - val obj = ObjectWrapper.Basic(details.details[target]?.map ?: emptyMap()) + val obj = details.getObject(target) val factory = LinkAppearanceFactory( content = content, - layout = obj.layout + layout = obj?.layout ) return factory.createAppearanceMenuItems() } else { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt index 2c87145a6c..e73c6c1594 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/editor/ext/ContentTextExt.kt @@ -2,8 +2,6 @@ package com.anytypeio.anytype.presentation.editor.editor.ext import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Block.Content -import com.anytypeio.anytype.core_models.Id -import com.anytypeio.anytype.core_models.MAX_SNIPPET_SIZE import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.core_models.ext.replaceRangeWithWord @@ -11,19 +9,22 @@ import com.anytypeio.anytype.core_models.ext.title import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction import com.anytypeio.anytype.domain.primitives.FieldParser import com.anytypeio.anytype.presentation.BuildConfig +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.Markup +import com.anytypeio.anytype.presentation.extension.getDateObject +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.extension.shift import com.anytypeio.anytype.presentation.widgets.collection.ResourceProvider import timber.log.Timber fun Block.Content.Text.getTextAndMarks( - details: Block.Details, + details: ObjectViewDetails, marks: List, fieldParser: FieldParser, resourceProvider: ResourceProvider ): Pair> { - if (details.details.isEmpty() || marks.none { it is Markup.Mark.Mention }) { + if (marks.none { it is Markup.Mark.Mention }) { return text to marks } var updatedText = text @@ -40,7 +41,14 @@ fun Block.Content.Text.getTextAndMarks( resourceProvider = resourceProvider ) is Markup.Mark.Mention.Deleted -> resourceProvider.getNonExistentObjectTitle() - else -> details.details.getProperObjectName(id = mark.param) ?: return@forEach + else -> { + val obj = details.getObject(mark.param) + if (obj != null) { + fieldParser.getObjectName(obj) + } else { + return@forEach + } + } } val oldName = updatedText.substring(mark.from, mark.to) val finalName = @@ -68,38 +76,28 @@ fun Block.Content.Text.getTextAndMarks( private fun Block.Content.Text.getFormattedDateMention( mark: Markup.Mark.Mention.Date, - details: Block.Details, + details: ObjectViewDetails, fieldParser: FieldParser, resourceProvider: ResourceProvider ): String? { + val dateObject = details.getDateObject(id = mark.param) return if (BuildConfig.ENABLE_RELATIVE_DATES_IN_MENTIONS) { - val dateObject = details.details[mark.param] ?: return null - val timestamp = dateObject.timestamp ?: return null + val timestamp = dateObject?.timestamp val relativeDate = fieldParser.toDate(timestamp)?.relativeDate resourceProvider.toFormattedString(relativeDate = relativeDate).takeIf { it.isNotEmpty() } } else { - details.details[mark.param]?.name - } -} - -private fun Map.getProperObjectName(id: Id?): String? { - if (id == null) return null - val layoutCode = this[id]?.layout?.toInt() - return if (layoutCode == ObjectType.Layout.NOTE.code) { - this[id]?.snippet?.replace("\n", " ")?.take(MAX_SNIPPET_SIZE) - } else { - this[id]?.name + dateObject?.name } } fun List.isAllowedToShowTypesWidget( objectRestrictions: List, isOwnerOrEditor: Boolean, - objectLayout: Int? + objectLayout: ObjectType.Layout? ): Boolean { if (objectRestrictions.any { it == ObjectRestriction.TYPE_CHANGE }) return false if (!isOwnerOrEditor) return false - return if (objectLayout == ObjectType.Layout.NOTE.code) { + return if (objectLayout == ObjectType.Layout.NOTE) { return true } else { return title()?.content()?.text?.isEmpty() == true diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/layout/ObjectLayoutViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/layout/ObjectLayoutViewModel.kt index 5169e9124a..9272ec5875 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/layout/ObjectLayoutViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/layout/ObjectLayoutViewModel.kt @@ -11,6 +11,7 @@ import com.anytypeio.anytype.domain.layout.GetSupportedObjectLayouts import com.anytypeio.anytype.domain.layout.SetObjectLayout import com.anytypeio.anytype.presentation.common.BaseViewModel import com.anytypeio.anytype.presentation.editor.Editor +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.extension.sendAnalyticsObjectLayoutChangeEvent import com.anytypeio.anytype.presentation.mapper.toObjectLayout import com.anytypeio.anytype.presentation.mapper.toView @@ -67,7 +68,7 @@ class ObjectLayoutViewModel( private fun proceedWithObjectLayout(ctx: Id) { viewModelScope.launch { storage.details.stream().collect { details -> - val code = details.details[ctx]?.layout?.toInt() + val code = details.getObject(ctx)?.layout?.code selectedLayout.value = code ?: ObjectType.Layout.BASIC.code } } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/BlockViewRenderer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/BlockViewRenderer.kt index e463ee71e4..345c519614 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/BlockViewRenderer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/BlockViewRenderer.kt @@ -4,6 +4,7 @@ import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction import com.anytypeio.anytype.domain.editor.Editor +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.Editor.Mode as EditorMode @@ -27,7 +28,7 @@ interface BlockViewRenderer { focus: Editor.Focus, anchor: Id, indent: Int, - details: Block.Details = Block.Details(emptyMap()), + details: ObjectViewDetails, restrictions: List, selection: Set, count: Int = 0, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt index 7e894ec801..73e54b6c7c 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/render/DefaultBlockViewRenderer.kt @@ -20,7 +20,10 @@ import com.anytypeio.anytype.domain.objects.StoreOfRelations import com.anytypeio.anytype.domain.primitives.FieldParser import com.anytypeio.anytype.presentation.editor.Editor import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.ext.getTextAndMarks +import com.anytypeio.anytype.presentation.extension.getBookmarkObject +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.editor.editor.model.Alignment import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.editor.model.BlockView.Appearance.InEditor @@ -34,8 +37,8 @@ import com.anytypeio.anytype.presentation.mapper.toVideoView import com.anytypeio.anytype.presentation.mapper.toView import com.anytypeio.anytype.presentation.objects.ObjectIcon import com.anytypeio.anytype.presentation.objects.appearance.LinkAppearanceFactory +import com.anytypeio.anytype.presentation.objects.getProperType import com.anytypeio.anytype.presentation.relations.BasicObjectCoverWrapper -import com.anytypeio.anytype.presentation.relations.BlockFieldsCoverWrapper import com.anytypeio.anytype.presentation.relations.ObjectRelationView import com.anytypeio.anytype.presentation.relations.getCover import com.anytypeio.anytype.presentation.relations.linksFeaturedRelation @@ -63,7 +66,7 @@ class DefaultBlockViewRenderer @Inject constructor( focus: Focus, anchor: Id, indent: Int, - details: Block.Details, + details: ObjectViewDetails, restrictions: List, selection: Set, count: Int, @@ -416,10 +419,9 @@ class DefaultBlockViewRenderer @Inject constructor( } } Content.Text.Style.DESCRIPTION -> { - val detail = details.details.getOrDefault(root.id, Block.Fields.empty()) - val obj = ObjectWrapper.Basic(detail.map) - val featured = obj.featuredRelations - if (featured.contains(Relations.DESCRIPTION)) { + val obj = details.getObject(id = context) + val featured = obj?.featuredRelations + if (featured?.contains(Relations.DESCRIPTION) == true) { if (obj.layout == ObjectType.Layout.PARTICIPANT && content.text.isEmpty()) { Timber.d("Skipping description rendering for object with participant layout: text is empty") } else { @@ -606,9 +608,7 @@ class DefaultBlockViewRenderer @Inject constructor( } is Content.Link -> { mCounter = 0 - val obj = ObjectWrapper.Basic( - map = details.details[content.target]?.map ?: emptyMap() - ) + val obj = details.getObject(content.target) val link = toLinks( block = block, content = content, @@ -798,7 +798,7 @@ class DefaultBlockViewRenderer @Inject constructor( content: Content.Text, focus: Focus, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.Text.Paragraph { @@ -861,7 +861,7 @@ class DefaultBlockViewRenderer @Inject constructor( focus: Focus, content: Content.Text, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.Text.Header.Three { @@ -898,7 +898,7 @@ class DefaultBlockViewRenderer @Inject constructor( focus: Focus, content: Content.Text, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.Text.Header.Two { @@ -935,7 +935,7 @@ class DefaultBlockViewRenderer @Inject constructor( focus: Focus, content: Content.Text, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.Text.Header.One { @@ -972,7 +972,7 @@ class DefaultBlockViewRenderer @Inject constructor( content: Content.Text, focus: Focus, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.Text.Checkbox { @@ -1009,7 +1009,7 @@ class DefaultBlockViewRenderer @Inject constructor( content: Content.Text, focus: Focus, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.Text.Bulleted { @@ -1070,7 +1070,7 @@ class DefaultBlockViewRenderer @Inject constructor( focus: Focus, content: Content.Text, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, scheme: NestedDecorationData ): BlockView.Text.Highlight { @@ -1114,7 +1114,7 @@ class DefaultBlockViewRenderer @Inject constructor( focus: Focus, content: Content.Text, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, scheme: NestedDecorationData ): BlockView.Text.Callout { @@ -1169,7 +1169,7 @@ class DefaultBlockViewRenderer @Inject constructor( indent: Int, focus: Focus, isEmpty: Boolean, - details: Block.Details, + details: ObjectViewDetails, selection: Set, scheme: NestedDecorationData ): BlockView.Text.Toggle { @@ -1208,7 +1208,7 @@ class DefaultBlockViewRenderer @Inject constructor( number: Int, focus: Focus, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.Text.Numbered { @@ -1247,7 +1247,7 @@ class DefaultBlockViewRenderer @Inject constructor( selection: Set, isPreviousBlockMedia: Boolean, schema: NestedDecorationData, - details: Block.Details + details: ObjectViewDetails, ): BlockView = when (content.state) { Content.Bookmark.State.EMPTY -> { BlockView.MediaPlaceholder.Bookmark( @@ -1281,10 +1281,14 @@ class DefaultBlockViewRenderer @Inject constructor( ) } Content.Bookmark.State.DONE -> { - val obj = ObjectWrapper.Bookmark( - details.details[content.targetObjectId]?.map ?: emptyMap() - ) - if (obj.isDeleted == true) { + val targetObjectId = content.targetObjectId + val obj = if (targetObjectId != null) { + details.getBookmarkObject(targetObjectId) + } else { + null + } + + if (obj == null || obj.isDeleted == true) { linkDeleted( block = block, indent = indent, @@ -1380,7 +1384,7 @@ class DefaultBlockViewRenderer @Inject constructor( selection: Set, isPreviousBlockMedia: Boolean, schema: NestedDecorationData, - details: Block.Details, + details: ObjectViewDetails, fieldParser: FieldParser ): BlockView { @@ -1404,11 +1408,11 @@ class DefaultBlockViewRenderer @Inject constructor( content: Content.Text, root: Block, focus: Focus, - details: Block.Details, + details: ObjectViewDetails, restrictions: List ): BlockView.Title { - val currentObject = ObjectWrapper.Basic(details.details[context]?.map.orEmpty()) + val currentObject = details.getObject(id = context) val focusTarget = focus.target @@ -1425,11 +1429,10 @@ class DefaultBlockViewRenderer @Inject constructor( } val rootContent = root.content - val rootDetails = details.details[root.id] check(rootContent is Content.Smart) - val coverContainer = BlockFieldsCoverWrapper(rootDetails) + val coverContainer = BasicObjectCoverWrapper(currentObject) .getCover(urlBuilder, coverImageHashProvider) val blockMode = if (restrictions.contains(ObjectRestriction.DETAILS)) { @@ -1438,7 +1441,7 @@ class DefaultBlockViewRenderer @Inject constructor( if (mode == EditorMode.Edit) Mode.EDIT else Mode.READ } - return when (currentObject.layout) { + return when (currentObject?.layout) { ObjectType.Layout.BASIC -> { BlockView.Title.Basic( mode = blockMode, @@ -1527,13 +1530,13 @@ class DefaultBlockViewRenderer @Inject constructor( ) } else -> { - // Fallback to basic title in case of unexpected layout + // Fallback to basic title in case of unexpected layout or when wrapper is null BlockView.Title.Basic( mode = blockMode, id = block.id, text = content.text, - emoji = currentObject.iconEmoji?.takeIf { it.isNotBlank() }, - image = currentObject.iconImage?.takeIf { it.isNotBlank() }?.let { + emoji = currentObject?.iconEmoji?.takeIf { it.isNotBlank() }, + image = currentObject?.iconImage?.takeIf { it.isNotBlank() }?.let { urlBuilder.medium(it) }, isFocused = resolveIsFocused(focus, block), @@ -1544,7 +1547,7 @@ class DefaultBlockViewRenderer @Inject constructor( background = block.parseThemeBackgroundColor(), color = block.textColor() ).also { - Timber.w("Unexpected layout for title: ${currentObject.layout}") + Timber.w("Unexpected layout for title: ${currentObject?.layout}") } } } @@ -1567,21 +1570,13 @@ class DefaultBlockViewRenderer @Inject constructor( block: Block, content: Content.Link, indent: Int, - obj: ObjectWrapper.Basic, + obj: ObjectWrapper.Basic?, mode: EditorMode, selection: Set, isPreviousBlockMedia: Boolean, parentSchema: NestedDecorationData ): BlockView.LinkToObject { - if (obj.isEmpty()) { - return BlockView.LinkToObject.Loading( - id = block.id, - indent = indent - ) - } - val isDeleted = obj.isDeleted - val isArchived = obj.isArchived - return if (isDeleted == true) { + return if (obj == null || obj.isDeleted == true) { linkDeleted( block = block, indent = indent, @@ -1590,7 +1585,7 @@ class DefaultBlockViewRenderer @Inject constructor( parentSchema = parentSchema ) } else { - if (isArchived == true) { + if (obj.isArchived == true) { linkArchive( block = block, indent = indent, @@ -1907,7 +1902,7 @@ class DefaultBlockViewRenderer @Inject constructor( block: Block, focus: Focus, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set, blocks: Map>, decorations: List @@ -1974,7 +1969,7 @@ class DefaultBlockViewRenderer @Inject constructor( mode: EditorMode, focus: Focus, indent: Int, - details: Block.Details, + details: ObjectViewDetails, selection: Set ): List { val cells = mutableListOf() @@ -2023,7 +2018,7 @@ class DefaultBlockViewRenderer @Inject constructor( block: Block, content: Content.RelationBlock, indent: Int, - details: Block.Details, + details: ObjectViewDetails, urlBuilder: UrlBuilder, schema: NestedDecorationData, fieldParser: FieldParser @@ -2039,9 +2034,10 @@ class DefaultBlockViewRenderer @Inject constructor( } else { val relation = storeOfRelations.getByKey(relationKey) if (relation != null) { + val values = details.getObject(ctx)?.map.orEmpty() val view = relation.view( - details = details.details, - values = details.details[ctx]?.map ?: emptyMap(), + details = details, + values = values, urlBuilder = urlBuilder, fieldParser = fieldParser ) @@ -2066,12 +2062,11 @@ class DefaultBlockViewRenderer @Inject constructor( private suspend fun featured( ctx: Id, block: Block, - details: Block.Details, + details: ObjectViewDetails, fieldParser: FieldParser, ): BlockView.FeaturedRelation { - val map = details.details[ctx]?.map ?: emptyMap() - val obj = ObjectWrapper.Basic(map) - val featuredKeys = workaroundGlobalNameOrIdentityRelation(obj.featuredRelations, map) + val obj = details.getObject(ctx) + val featuredKeys = workaroundGlobalNameOrIdentityRelation(obj?.featuredRelations.orEmpty(), obj?.map.orEmpty()) val views = mapFeaturedRelations( ctx = ctx, keys = featuredKeys, @@ -2082,8 +2077,8 @@ class DefaultBlockViewRenderer @Inject constructor( return BlockView.FeaturedRelation( id = block.id, relations = views, - allowChangingObjectType = !obj.type.contains(BOOKMARK), - isTodoLayout = obj.layout == ObjectType.Layout.TODO + allowChangingObjectType = obj?.type?.contains(BOOKMARK) != true, + isTodoLayout = obj?.layout == ObjectType.Layout.TODO ) } @@ -2113,13 +2108,13 @@ class DefaultBlockViewRenderer @Inject constructor( private suspend fun mapFeaturedRelations( ctx: Id, keys: List, - details: Block.Details, + details: ObjectViewDetails, fieldParser: FieldParser ): List = keys.mapNotNull { key -> when (key) { Relations.DESCRIPTION -> null Relations.TYPE -> { - val objectTypeId = details.details[ctx]?.type?.firstOrNull() + val objectTypeId = details.getObject(ctx)?.getProperType() if (objectTypeId != null) { details.objectTypeRelation( relationKey = key, @@ -2140,9 +2135,10 @@ class DefaultBlockViewRenderer @Inject constructor( } else -> { val relation = storeOfRelations.getByKey(key) + val values = details.getObject(ctx)?.map.orEmpty() relation?.view( - details = details.details, - values = details.details[ctx]?.map ?: emptyMap(), + details = details, + values = values, urlBuilder = urlBuilder, isFeatured = true, fieldParser = fieldParser @@ -2177,7 +2173,7 @@ class DefaultBlockViewRenderer @Inject constructor( mode: EditorMode, block: Block, content: Content.DataView, - details: Block.Details, + details: ObjectViewDetails, selection: Set, schema: NestedDecorationData ): BlockView.DataView { @@ -2208,10 +2204,8 @@ class DefaultBlockViewRenderer @Inject constructor( isCollection = isCollection ) } else { - val targetSet = ObjectWrapper.Basic( - map = details.details[content.targetObjectId]?.map ?: emptyMap() - ) - if (targetSet.isDeleted == true) { + val targetSet = details.getObject(targetObjectId) + if (targetSet == null || targetSet.isDeleted == true) { return BlockView.DataView.Deleted( id = block.id, decorations = decorations, @@ -2223,7 +2217,7 @@ class DefaultBlockViewRenderer @Inject constructor( ) } val icon = targetSet.objectIcon(urlBuilder) - val isSetNoQuery = targetSet.setOf.all { it.isNullOrBlank() } + val isSetNoQuery = targetSet.setOf.all { it.isBlank() } if (isSetNoQuery && !content.isCollection) { return BlockView.DataView.EmptyData( id = block.id, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AllObjectsDetailsExt.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AllObjectsDetailsExt.kt new file mode 100644 index 0000000000..e3f27d9765 --- /dev/null +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AllObjectsDetailsExt.kt @@ -0,0 +1,115 @@ +package com.anytypeio.anytype.presentation.extension + +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.core_models.Id +import com.anytypeio.anytype.core_models.ObjectWrapper +import com.anytypeio.anytype.core_models.Struct +import com.anytypeio.anytype.core_models.ext.isValidObject +import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType +import com.anytypeio.anytype.core_models.ext.mapToOptionObject +import com.anytypeio.anytype.core_models.ext.toBookmarkObject +import com.anytypeio.anytype.core_models.ext.toDateObject +import com.anytypeio.anytype.core_models.ext.toFileObject +import com.anytypeio.anytype.core_models.ext.toInternalFlagsObject +import com.anytypeio.anytype.core_models.ext.toObject +import com.anytypeio.anytype.domain.misc.UrlBuilder +import com.anytypeio.anytype.domain.objects.StoreOfRelations +import com.anytypeio.anytype.domain.primitives.FieldParser +import com.anytypeio.anytype.presentation.objects.getProperType +import com.anytypeio.anytype.presentation.relations.ObjectRelationView +import com.anytypeio.anytype.presentation.relations.getNotIncludedRecommendedRelations +import com.anytypeio.anytype.presentation.relations.view + +fun ObjectViewDetails.getStruct(id: Id): Struct? = details[id] +fun ObjectViewDetails.containsObject(id: Id): Boolean { + return details.containsKey(id) && details[id]?.isValidObject() == true +} + +fun ObjectViewDetails.getObject(id: Id): ObjectWrapper.Basic? { + return details[id]?.toObject() +} + +fun ObjectViewDetails.getOptionObject(id: Id): ObjectWrapper.Option? { + return details[id]?.mapToOptionObject() +} + +fun ObjectViewDetails.getFileObject(id: Id): ObjectWrapper.File? { + return details[id]?.toFileObject() +} + +fun ObjectViewDetails.getTypeObject(id: Id): ObjectWrapper.Type? { + return details[id]?.mapToObjectWrapperType() +} + +fun ObjectViewDetails.getDateObject(id: Id): ObjectWrapper.Date? { + return details[id]?.toDateObject() +} + +fun ObjectViewDetails.getBookmarkObject(id: Id): ObjectWrapper.Bookmark? { + return details[id]?.toBookmarkObject() +} + +fun ObjectViewDetails.getInternalFlagsObject(id: Id): ObjectWrapper.ObjectInternalFlags? { + return details[id]?.toInternalFlagsObject() +} + +suspend fun ObjectViewDetails.getObjRelationsViews( + ctx: Id, + storeOfRelations: StoreOfRelations, + fieldParser: FieldParser, + urlBuilder: UrlBuilder +): List { + val currentObject = getObject(ctx) + if (currentObject == null || !currentObject.isValid) return emptyList() + val keys = currentObject.map.keys.toList() + return storeOfRelations.getByKeys(keys).map { + it.view( + details = this, + values = currentObject.map, + urlBuilder = urlBuilder, + fieldParser = fieldParser, + isFeatured = currentObject.featuredRelations.contains(it.key) + ) + } +} + +suspend fun ObjectViewDetails.getRecommendedRelations( + ctx: Id, + storeOfRelations: StoreOfRelations, + fieldParser: FieldParser, + urlBuilder: UrlBuilder +): List { + val currentObject = getObject(ctx) + if (currentObject == null || !currentObject.isValid) return emptyList() + val typeObjectId = currentObject.getProperType() + if (typeObjectId == null) return emptyList() + val typeObject = getTypeObject(typeObjectId) + if (typeObject == null) return emptyList() + val recommendedRelations = typeObject.recommendedRelations + val notIncludedRecommendedRelations = getNotIncludedRecommendedRelations( + relationKeys = currentObject.map.keys, + recommendedRelations = recommendedRelations, + storeOfRelations = storeOfRelations + ) + return notIncludedRecommendedRelations.map { + it.view( + details = this, + values = currentObject.map, + urlBuilder = urlBuilder, + fieldParser = fieldParser, + isFeatured = currentObject.featuredRelations.contains(it.key) + ) + } +} + +fun ObjectViewDetails.getTypeForObject(currentObjectId: Id): ObjectWrapper.Type? { + val currentObject = getObject(currentObjectId) + val type = currentObject?.getProperType() + if (type != null) { + val objType = getTypeObject(type) + if (objType != null) { + return objType + } + } + return null +} \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt index 819eeb4fc6..db107ff823 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt @@ -46,13 +46,14 @@ import com.anytypeio.anytype.core_models.Key import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Relation +import com.anytypeio.anytype.core_models.Relations +import com.anytypeio.anytype.core_models.Struct import com.anytypeio.anytype.core_models.TextStyle import com.anytypeio.anytype.core_models.ThemeMode import com.anytypeio.anytype.core_models.WidgetLayout -import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType +import com.anytypeio.anytype.core_models.getSingleValue import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions import com.anytypeio.anytype.core_models.primitives.RelationKey -import com.anytypeio.anytype.core_models.primitives.TypeKey import com.anytypeio.anytype.core_utils.ext.Mimetype import com.anytypeio.anytype.domain.config.ConfigStorage import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes @@ -65,7 +66,6 @@ import com.anytypeio.anytype.presentation.sets.viewerByIdOrFirst import com.anytypeio.anytype.presentation.widgets.Widget import com.anytypeio.anytype.presentation.widgets.source.BundledWidgetSourceView import kotlinx.coroutines.CoroutineScope -import timber.log.Timber fun Block.Prototype.getAnalyticsEvent( eventName: String, @@ -290,7 +290,7 @@ fun Relation.Format.getPropName() = when (this) { fun CoroutineScope.sendAnalyticsObjectShowEvent( ctx: Id, - details: Map?, + details: Map, analytics: Analytics, startTime: Long, spaceParams: AnalyticSpaceHelperDelegate.Params @@ -474,7 +474,7 @@ fun CoroutineScope.sendAnalyticsMoveToBinEvent( fun CoroutineScope.sendAnalyticsDuplicateEvent( analytics: Analytics, - details: Map?, + details: Map, ctx: Id, startTime: Long, count: Int = 1, @@ -1933,7 +1933,7 @@ fun CoroutineScope.sendAnalyticsSelectTemplateEvent( fun CoroutineScope.sendAnalyticsCreateTemplateEvent( analytics: Analytics, - details: Map, + details: Map, ctx: Id, startTime: Long, spaceParams: AnalyticSpaceHelperDelegate.Params @@ -1980,14 +1980,16 @@ fun CoroutineScope.sendAnalyticsDefaultTemplateEvent( } private fun getAnalyticsObjectType( - details: Map?, + details: Map, ctx: Id ): String? { - if (details == null) return null - val objTypeId = details[ctx]?.type?.firstOrNull() - val typeStruct = details[objTypeId]?.map - val objType = typeStruct?.mapToObjectWrapperType() - return objType?.sourceObject ?: OBJ_TYPE_CUSTOM + val objTypeId = details[ctx]?.getSingleValue(Relations.TYPE) + val sourceObject = if (objTypeId != null){ + details[objTypeId]?.getSingleValue(Relations.SOURCE_OBJECT) + } else { + null + } + return sourceObject ?: OBJ_TYPE_CUSTOM } fun CoroutineScope.sendAnalyticsCreateLink( diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/FileUrlExt.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/FileUrlExt.kt index bff85bb254..1b6377ed45 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/FileUrlExt.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/extension/FileUrlExt.kt @@ -105,7 +105,7 @@ fun List.getFileDetailsForBlock( return null } - val fileObject = orchestrator.stores.details.getAsObject(target = targetObjectId) + val fileObject = orchestrator.stores.details.current().getObject(targetObjectId) if (fileObject == null) { Timber.e("Object with id $targetObjectId not found.") return null diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/history/VersionHistoryViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/history/VersionHistoryViewModel.kt index bd60bd8877..94c0d5682e 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/history/VersionHistoryViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/history/VersionHistoryViewModel.kt @@ -26,7 +26,7 @@ import com.anytypeio.anytype.domain.objects.StoreOfRelations import com.anytypeio.anytype.domain.search.SearchObjects import com.anytypeio.anytype.presentation.editor.Editor.Mode import com.anytypeio.anytype.presentation.editor.EditorViewModel.Companion.INITIAL_INDENT -import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.listener.ListenerType import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.render.BlockViewRenderer @@ -502,8 +502,7 @@ class VersionHistoryViewModel( val event = payload.events .filterIsInstance() .first() - val obj = - ObjectWrapper.Basic(event.details.details[vmParams.objectId]?.map.orEmpty()) + val obj = ObjectWrapper.Basic(event.details[vmParams.objectId].orEmpty()) val currentState = _previewViewState.value if (currentState !is VersionHistoryPreviewScreen.Hidden) { parseObject( @@ -535,7 +534,7 @@ class VersionHistoryViewModel( focus = Editor.Focus.empty(), anchor = vmParams.objectId, indent = INITIAL_INDENT, - details = event.details, + details = ObjectViewDetails(event.details), restrictions = event.objectRestrictions, selection = emptySet() ).filterNot { it is BlockView.DataView } @@ -572,7 +571,7 @@ class VersionHistoryViewModel( focus = Editor.Focus.empty(), anchor = vmParams.objectId, indent = INITIAL_INDENT, - details = event.details, + details = ObjectViewDetails(event.details), restrictions = event.objectRestrictions, selection = emptySet() ) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt index f658bb3af0..9f64c508aa 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/mapper/MapperExtension.kt @@ -15,7 +15,9 @@ import com.anytypeio.anytype.domain.config.DebugSettings import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.objects.ObjectStore import com.anytypeio.anytype.domain.primitives.FieldParser +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.Markup +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.editor.editor.mention.createMentionMarkup import com.anytypeio.anytype.presentation.editor.editor.model.Alignment import com.anytypeio.anytype.presentation.editor.editor.model.BlockView @@ -41,7 +43,7 @@ fun Block.Content.File.toPictureView( background: ThemeColor, isPreviousBlockMedia: Boolean, decorations: List, - details: Block.Details = Block.Details(), + details: ObjectViewDetails, fieldParser: FieldParser ): BlockView = when (state) { Block.Content.File.State.EMPTY -> BlockView.MediaPlaceholder.Picture( @@ -64,11 +66,11 @@ fun Block.Content.File.toPictureView( Block.Content.File.State.DONE -> { val url = urlBuilder.getUrlForFileContent(this) - val currentObject = ObjectWrapper.Basic(details.details[context]?.map.orEmpty()) - val targetObject = ObjectWrapper.Basic(details.details[targetObjectId]?.map.orEmpty()) + val currentObject = details.getObject(id = context) + val targetObject = details.getObject(id = targetObjectId) - if (url != null && targetObject.isValid && targetObject.notDeletedNorArchived) { - if (currentObject.layout == ObjectType.Layout.IMAGE) { + if (url != null && targetObject != null && targetObject.isValid && targetObject.notDeletedNorArchived) { + if (currentObject?.layout == ObjectType.Layout.IMAGE) { BlockView.ButtonOpenFile.ImageButton( id = blockId, targetId = targetObjectId @@ -121,7 +123,7 @@ fun Block.Content.File.toVideoView( background: ThemeColor, isPrevBlockMedia: Boolean, decorations: List, - details: Block.Details = Block.Details(), + details: ObjectViewDetails, fieldParser: FieldParser ): BlockView = when (state) { Block.Content.File.State.EMPTY -> BlockView.MediaPlaceholder.Video( @@ -144,11 +146,11 @@ fun Block.Content.File.toVideoView( Block.Content.File.State.DONE -> { val url = urlBuilder.getUrlForFileContent(this) - val currentObject = ObjectWrapper.Basic(details.details[context]?.map.orEmpty()) - val targetObject = ObjectWrapper.Basic(details.details[targetObjectId]?.map.orEmpty()) + val currentObject = details.getObject(id = context) + val targetObject = details.getObject(id = targetObjectId) - if (url != null && targetObject.isValid && targetObject.notDeletedNorArchived) { - if (currentObject.layout == ObjectType.Layout.VIDEO) { + if (url != null && targetObject != null && targetObject.isValid && targetObject.notDeletedNorArchived) { + if (currentObject?.layout == ObjectType.Layout.VIDEO) { BlockView.ButtonOpenFile.FileButton( id = blockId, targetId = targetObjectId @@ -201,7 +203,7 @@ fun Block.Content.File.toFileView( background: ThemeColor, isPrevBlockMedia: Boolean, decorations: List, - details: Block.Details = Block.Details(), + details: ObjectViewDetails, fieldParser: FieldParser ): BlockView = when (state) { Block.Content.File.State.EMPTY -> BlockView.MediaPlaceholder.File( @@ -224,11 +226,12 @@ fun Block.Content.File.toFileView( Block.Content.File.State.DONE -> { val url = urlBuilder.getUrlForFileContent(this) - val currentObject = ObjectWrapper.Basic(details.details[context]?.map.orEmpty()) - val targetObject = ObjectWrapper.Basic(details.details[targetObjectId]?.map.orEmpty()) + val currentObject = details.getObject(id = context) + val targetObject = details.getObject(id = targetObjectId) - if (url != null && targetObject.isValid && targetObject.notDeletedNorArchived) { - if (SupportedLayouts.fileLayouts.contains(currentObject.layout)) { + if (url != null && targetObject != null && targetObject.isValid && targetObject.notDeletedNorArchived) { + val layout = currentObject?.layout + if (layout != null && SupportedLayouts.fileLayouts.contains(layout)) { BlockView.ButtonOpenFile.FileButton( id = blockId, targetId = targetObjectId @@ -282,7 +285,7 @@ fun Block.Align.toView(): Alignment = when (this) { fun Block.Content.Text.marks( urlBuilder: UrlBuilder, - details: Block.Details + details: ObjectViewDetails ): List = marks .filterByRange(text.length) .mapNotNull { mark -> @@ -345,32 +348,29 @@ fun Block.Content.Text.marks( ) } Block.Content.Text.Mark.Type.MENTION -> { - - val wrapper = if (!details.details.containsKey(mark.param)) { + val param = mark.param + if (param.isNullOrBlank()) { null } else { - ObjectWrapper.Basic(map = details.details[mark.param]?.map ?: emptyMap()) + mark.createMentionMarkup( + obj = details.getObject(id = param), + urlBuilder = urlBuilder + ) } - - mark.createMentionMarkup( - obj = wrapper, - urlBuilder = urlBuilder - ) } Block.Content.Text.Mark.Type.OBJECT -> { - val wrapper = if (!details.details.containsKey(mark.param)) { + val param = mark.param + if (param.isNullOrBlank()) { null } else { - ObjectWrapper.Basic(map = details.details[mark.param]?.map ?: emptyMap()) + val wrapper = details.getObject(id = param) + Markup.Mark.Object( + from = mark.range.first, + to = mark.range.last, + param = param, + isArchived = wrapper?.isArchived == true + ) } - val param = mark.param - if (param.isNullOrBlank()) null - else Markup.Mark.Object( - from = mark.range.first, - to = mark.range.last, - param = param, - isArchived = wrapper?.isArchived == true - ) } else -> null } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImpl.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImpl.kt index 53853be17f..6a5c8289ea 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImpl.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImpl.kt @@ -1,12 +1,11 @@ package com.anytypeio.anytype.presentation.objects.menu -import com.anytypeio.anytype.core_models.Block 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.restrictions.ObjectRestriction -import com.anytypeio.anytype.core_utils.tools.FeatureToggles import com.anytypeio.anytype.core_models.SupportedLayouts +import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.objects.menu.ObjectMenuOptionsProvider.Options import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine @@ -15,20 +14,18 @@ import kotlinx.coroutines.flow.map import timber.log.Timber class ObjectMenuOptionsProviderImpl( - private val details: Flow>, - private val restrictions: Flow>, - private val featureToggles: FeatureToggles, + private val objectViewDetailsFlow: Flow, + private val restrictions: Flow> ) : ObjectMenuOptionsProvider { - private fun observeLayout(ctx: Id): Flow = details + private fun observeLayout(ctx: Id): Flow = objectViewDetailsFlow .filter { details -> - details.containsKey(ctx).also { isValuePresent -> + details.details.containsKey(ctx).also { isValuePresent -> if (!isValuePresent) Timber.w("Details missing for object: $ctx") } } .map { details -> - val fields = requireNotNull(details[ctx]) - ObjectWrapper.Basic(fields.map).layout + details.getObject(ctx)?.layout } override fun provide(ctx: Id, isLocked: Boolean, isReadOnly: Boolean): Flow { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModel.kt index 9f0f550a9c..eb39ae8d08 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModel.kt @@ -8,10 +8,8 @@ import com.anytypeio.anytype.analytics.base.EventsDictionary import com.anytypeio.anytype.analytics.base.sendEvent import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id -import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.Relations -import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType import com.anytypeio.anytype.core_models.primitives.SpaceId import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction import com.anytypeio.anytype.domain.base.fold @@ -38,9 +36,11 @@ import com.anytypeio.anytype.presentation.extension.sendAnalyticsDefaultTemplate import com.anytypeio.anytype.presentation.objects.ObjectAction import com.anytypeio.anytype.core_models.SupportedLayouts.fileLayouts import com.anytypeio.anytype.core_models.SupportedLayouts.systemLayouts -import com.anytypeio.anytype.core_models.multiplayer.SpaceAccessType import com.anytypeio.anytype.domain.multiplayer.GetSpaceInviteLink import com.anytypeio.anytype.domain.multiplayer.SpaceViewSubscriptionContainer +import com.anytypeio.anytype.presentation.extension.getObject +import com.anytypeio.anytype.presentation.extension.getTypeObject +import com.anytypeio.anytype.presentation.objects.getProperType import com.anytypeio.anytype.presentation.objects.isTemplatesAllowed import com.anytypeio.anytype.presentation.util.Dispatcher import com.anytypeio.anytype.presentation.util.downloader.DebugGoroutinesShareDownloader @@ -112,8 +112,8 @@ class ObjectMenuViewModel( isReadOnly: Boolean ): List = buildList { - val wrapper = ObjectWrapper.Basic(storage.details.current().details[ctx]?.map.orEmpty()) - val layout = wrapper.layout + val wrapper = storage.details.current().getObject(ctx) + val layout = wrapper?.layout if (isReadOnly) { add(ObjectAction.COPY_LINK) @@ -152,15 +152,15 @@ class ObjectMenuViewModel( add(ObjectAction.UNDO_REDO) - val details = storage.details.current().details - val objTypeId = details[ctx]?.type?.firstOrNull() - val typeStruct = details[objTypeId]?.map - val objType = typeStruct?.mapToObjectWrapperType() + val objTypeId = wrapper?.getProperType() + if (objTypeId != null) { + val objType = storage.details.current().getTypeObject(objTypeId) if (objType != null) { val isTemplateAllowed = objType.isTemplatesAllowed() if (isTemplateAllowed && !isTemplate) { add(ObjectAction.USE_AS_TEMPLATE) } + } } if (!isTemplate) { add(ObjectAction.LINK_TO) @@ -340,9 +340,8 @@ class ObjectMenuViewModel( proceedWithSettingAsDefaultTemplate(ctx = ctx) } ObjectAction.CREATE_WIDGET -> { - val details = storage.details.current().details[ctx] - val wrapper = ObjectWrapper.Basic(details?.map ?: emptyMap()) - proceedWithCreatingWidget(obj = wrapper) + val wrapper = storage.details.current().getObject(ctx) + if (wrapper != null) proceedWithCreatingWidget(obj = wrapper) } ObjectAction.MOVE_TO, ObjectAction.MOVE_TO_BIN, @@ -361,9 +360,8 @@ class ObjectMenuViewModel( private fun proceedWithSettingAsDefaultTemplate(ctx: Id) { val startTime = System.currentTimeMillis() - val details = storage.details.current().details - val objTemplate = ObjectWrapper.Basic(details[ctx]?.map ?: emptyMap()) - val targetObjectTypeId = objTemplate.targetObjectType ?: return + val objTemplate = storage.details.current().getObject(ctx) + val targetObjectTypeId = objTemplate?.targetObjectType ?: return viewModelScope.launch { val params = SetObjectDetails.Params( ctx = targetObjectTypeId, @@ -371,7 +369,7 @@ class ObjectMenuViewModel( ) setObjectDetails.async(params).fold( onSuccess = { - val objType = details[targetObjectTypeId]?.map?.mapToObjectWrapperType() + val objType = storage.details.current().getTypeObject(targetObjectTypeId) sendAnalyticsDefaultTemplateEvent(analytics, objType, startTime) _toasts.emit("The template was set as default") isDismissed.value = true @@ -413,22 +411,24 @@ class ObjectMenuViewModel( } private suspend fun buildOpenTemplateCommand(ctx: Id, space: Id, template: Id) { - val details = storage.details.current().details - val type = details[ctx]?.type?.firstOrNull() - val typeStruct = details[type]?.map - val objType = typeStruct?.mapToObjectWrapperType() - if (objType != null) { - val objTypeKey = objType.uniqueKey - val command = Command.OpenTemplate( - templateId = template, - typeId = objType.id, - typeKey = objTypeKey, - typeName = objType.name.orEmpty(), - space = space - ) - commands.emit(command) + val type = storage.details.current().getObject(ctx)?.getProperType() + if (type != null) { + val objType = storage.details.current().getTypeObject(type) + if (objType != null) { + val objTypeKey = objType.uniqueKey + val command = Command.OpenTemplate( + templateId = template, + typeId = objType.id, + typeKey = objTypeKey, + typeName = objType.name.orEmpty(), + space = space + ) + commands.emit(command) + } else { + Timber.e("Error while opening template from object, type:$type hasn't key") + } } else { - Timber.e("Error while opening template from object, type:$type hasn't key") + Timber.e("Error while opening template from object, object hasn't type") } } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModelBase.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModelBase.kt index 5a818c7e1e..9bb68a50d9 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModelBase.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuViewModelBase.kt @@ -3,12 +3,12 @@ package com.anytypeio.anytype.presentation.objects.menu import android.net.Uri import androidx.lifecycle.viewModelScope import com.anytypeio.anytype.analytics.base.Analytics -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Key import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Payload +import com.anytypeio.anytype.core_models.Struct import com.anytypeio.anytype.core_models.WidgetLayout import com.anytypeio.anytype.core_models.isDataView import com.anytypeio.anytype.core_models.multiplayer.SpaceAccessType @@ -354,7 +354,7 @@ abstract class ObjectMenuViewModelBase( } } - fun proceedWithDuplication(ctx: Id, space: Id, details: Map?) { + fun proceedWithDuplication(ctx: Id, space: Id, details: Map) { Timber.d("proceedWithDuplication, ctx:[$ctx]") val startTime = System.currentTimeMillis() viewModelScope.launch { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectSetMenuViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectSetMenuViewModel.kt index 7041261815..7d0ac9dfc9 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectSetMenuViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/menu/ObjectSetMenuViewModel.kt @@ -5,7 +5,6 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.anytypeio.anytype.analytics.base.Analytics import com.anytypeio.anytype.core_models.Id -import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.primitives.SpaceId import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction @@ -25,6 +24,7 @@ import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate import com.anytypeio.anytype.presentation.common.Action import com.anytypeio.anytype.presentation.common.Delegator import com.anytypeio.anytype.presentation.common.PayloadDelegator +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.objects.ObjectAction import com.anytypeio.anytype.presentation.sets.dataViewState import com.anytypeio.anytype.presentation.sets.state.ObjectState @@ -208,6 +208,7 @@ class ObjectSetMenuViewModel( } override fun onActionClicked(ctx: Id, space: Id, action: ObjectAction) { + val state = objectState.value.dataViewState() ?: return when (action) { ObjectAction.DELETE -> { proceedWithUpdatingArchivedStatus(ctx = ctx, isArchived = true) @@ -228,13 +229,12 @@ class ObjectSetMenuViewModel( proceedWithDuplication( ctx = ctx, space = space, - details = objectState.value.dataViewState()?.details + details = state.details.details ) } ObjectAction.CREATE_WIDGET -> { - val details = objectState.value.dataViewState()?.details?.get(ctx) - val wrapper = ObjectWrapper.Basic(details?.map ?: emptyMap()) - proceedWithCreatingWidget(obj = wrapper) + val wrapper = state.details.getObject(ctx) + if (wrapper != null) proceedWithCreatingWidget(obj = wrapper) } ObjectAction.COPY_LINK -> { viewModelScope.launch { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/CoverTypeMapper.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/CoverTypeMapper.kt index f8c58f2073..a5fa285f40 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/CoverTypeMapper.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/CoverTypeMapper.kt @@ -1,6 +1,5 @@ package com.anytypeio.anytype.presentation.relations -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.CoverType import com.anytypeio.anytype.core_models.DVViewer import com.anytypeio.anytype.core_models.ObjectWrapper @@ -133,19 +132,6 @@ interface CoverWrapper { val coverId: String? } -class BlockFieldsCoverWrapper(val fields: Block.Fields?) : CoverWrapper { - - override val coverType: CoverType - get() { - val value = fields?.coverType?.toInt() ?: return CoverType.NONE - return CoverType.values().find { type -> - type.code == value - } ?: CoverType.NONE - } - - override val coverId = fields?.coverId -} - class BasicObjectCoverWrapper(val obj: ObjectWrapper.Basic?) : CoverWrapper { override val coverType = obj?.coverType ?: CoverType.NONE override val coverId = obj?.coverId diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectRelationListViewModelFactory.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectRelationListViewModelFactory.kt index f258b6d81b..ebc6e83937 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectRelationListViewModelFactory.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectRelationListViewModelFactory.kt @@ -15,12 +15,12 @@ import com.anytypeio.anytype.domain.relations.RemoveFromFeaturedRelations import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate import com.anytypeio.anytype.presentation.objects.LockedStateProvider import com.anytypeio.anytype.presentation.relations.RelationListViewModel.VmParams -import com.anytypeio.anytype.presentation.relations.providers.RelationListProvider +import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationListProvider import com.anytypeio.anytype.presentation.util.Dispatcher class ObjectRelationListViewModelFactory( private val vmParams: VmParams, - private val relationListProvider: RelationListProvider, + private val objectRelationListProvider: ObjectRelationListProvider, private val lockedStateProvider: LockedStateProvider, private val urlBuilder: UrlBuilder, private val dispatcher: Dispatcher, @@ -39,7 +39,7 @@ class ObjectRelationListViewModelFactory( override fun create(modelClass: Class): T { return RelationListViewModel( vmParams = vmParams, - relationListProvider = relationListProvider, + objectRelationListProvider = objectRelationListProvider, lockedStateProvider = lockedStateProvider, urlBuilder = urlBuilder, dispatcher = dispatcher, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt index ee4c87b5f8..4178882213 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/ObjectSetRenderMapper.kt @@ -27,12 +27,13 @@ import com.anytypeio.anytype.core_utils.ext.TOMORROW import com.anytypeio.anytype.core_utils.ext.YESTERDAY import com.anytypeio.anytype.core_utils.ext.orNull import com.anytypeio.anytype.core_utils.ext.typeOf -import com.anytypeio.anytype.domain.misc.DateProvider import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.objects.ObjectStore import com.anytypeio.anytype.domain.objects.StoreOfRelations import com.anytypeio.anytype.domain.primitives.FieldParser import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.extension.isValueRequired import com.anytypeio.anytype.presentation.mapper.objectIcon @@ -202,19 +203,18 @@ fun title( ctx: Id, coverImageHashProvider: CoverImageHashProvider, urlBuilder: UrlBuilder, - details: Map + details: ObjectViewDetails ): BlockView.Title.Basic { - val wrapper = ObjectWrapper.Basic(details[ctx]?.map ?: emptyMap()) - val objectDetails = details[ctx] - val coverContainer = BlockFieldsCoverWrapper(objectDetails).getCover( + val wrapper = details.getObject(ctx) + val coverContainer = BasicObjectCoverWrapper(wrapper).getCover( urlBuilder = urlBuilder, coverImageHashProvider = coverImageHashProvider ) return BlockView.Title.Basic( id = title.id, - text = wrapper.name.orEmpty(), - emoji = wrapper.iconEmoji.orNull(), - image = wrapper.iconImage?.takeIf { it.isNotBlank() }?.let { urlBuilder.medium(it) }, + text = wrapper?.name.orEmpty(), + emoji = wrapper?.iconEmoji.orNull(), + image = wrapper?.iconImage?.takeIf { it.isNotBlank() }?.let { urlBuilder.medium(it) }, coverImage = coverContainer.coverImage, coverColor = coverContainer.coverColor, coverGradient = coverContainer.coverGradient diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationExtensions.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationExtensions.kt index 61477f6c55..8c902a6e63 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationExtensions.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationExtensions.kt @@ -6,6 +6,8 @@ import com.anytypeio.anytype.core_utils.const.DateConst import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.objects.StoreOfRelations import com.anytypeio.anytype.domain.primitives.FieldParser +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getOptionObject import com.anytypeio.anytype.presentation.extension.hasValue import com.anytypeio.anytype.presentation.number.NumberParser import com.anytypeio.anytype.presentation.sets.* @@ -14,14 +16,14 @@ import com.anytypeio.anytype.presentation.sets.model.Viewer import java.util.* fun List.views( - details: Block.Details, + details: ObjectViewDetails, values: Map, urlBuilder: UrlBuilder, featured: List = emptyList(), fieldParser: FieldParser ): List = mapNotNull { relation -> relation.view( - details = details.details, + details = details, values = values, urlBuilder = urlBuilder, isFeatured = featured.contains(relation.key), @@ -32,7 +34,7 @@ fun List.views( fun Key.isSystemKey() : Boolean = Relations.systemRelationKeys.contains(this) fun ObjectWrapper.Relation.view( - details: Map, + details: ObjectViewDetails, values: Map, urlBuilder: UrlBuilder, isFeatured: Boolean = false, @@ -86,24 +88,11 @@ fun ObjectWrapper.Relation.view( } RelationFormat.STATUS -> { val options = buildList { - when(val value = values[relation.key]) { - is Id -> { - val status = details[value] - if (status != null && status.map.isNotEmpty()) { - add( - ObjectWrapper.Option(status.map) - ) - } - } - is List<*> -> { - value.forEach { id -> - val status = details[id] - if (status != null && status.map.isNotEmpty()) { - add( - ObjectWrapper.Option(status.map) - ) - } - } + val statusValue = values.getSingleValue(relation.key) + if (statusValue != null) { + val status = details.getOptionObject(statusValue) + if (status != null) { + add(status) } } } @@ -123,25 +112,9 @@ fun ObjectWrapper.Relation.view( } RelationFormat.TAG -> { val options = buildList { - when(val value = values[relation.key]) { - is Id -> { - val status = details[value] - if (status != null && status.map.isNotEmpty()) { - add( - ObjectWrapper.Option(status.map) - ) - } - } - is List<*> -> { - value.forEach { id -> - val status = details[id] - if (status != null && status.map.isNotEmpty()) { - add( - ObjectWrapper.Option(status.map) - ) - } - } - } + values[relation.key].values().forEach { id -> + val status = details.getOptionObject(id) + if (status != null) add(status) } } val tags = values.buildTagViews( @@ -235,7 +208,7 @@ fun ColumnView.getDateRelationFormat(): String { } /** - * Retrieves a list of distinct [ObjectWrapper.Relation] relations of Object using the given relation links filtered by system relations. + * Retrieves a list of distinct [ObjectWrapper.Relation] relations of Object using the given relation keys filtered by system relations. * * @param relationKeys The list of object details keys * @param systemRelations The list of keys of the system relations. Final list will be filtered by this list. diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationListViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationListViewModel.kt index 625bdaf7fe..c1195f37d0 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationListViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationListViewModel.kt @@ -7,14 +7,12 @@ import com.anytypeio.anytype.analytics.base.EventsDictionary.objectRelationFeatu import com.anytypeio.anytype.analytics.base.EventsDictionary.objectRelationUnfeature import com.anytypeio.anytype.analytics.base.EventsDictionary.relationsScreenShow import com.anytypeio.anytype.analytics.base.sendEvent -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Key import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.RelationFormat import com.anytypeio.anytype.core_models.TimeInMillis -import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType import com.anytypeio.anytype.core_models.primitives.SpaceId import com.anytypeio.anytype.core_utils.diff.DefaultObjectDiffIdentifier import com.anytypeio.anytype.domain.base.fold @@ -29,11 +27,15 @@ import com.anytypeio.anytype.domain.relations.RemoveFromFeaturedRelations import com.anytypeio.anytype.presentation.BuildConfig import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate import com.anytypeio.anytype.presentation.common.BaseViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getStruct +import com.anytypeio.anytype.presentation.extension.getObjRelationsViews +import com.anytypeio.anytype.presentation.extension.getRecommendedRelations +import com.anytypeio.anytype.presentation.extension.getTypeForObject import com.anytypeio.anytype.presentation.extension.sendAnalyticsRelationEvent import com.anytypeio.anytype.presentation.objects.LockedStateProvider -import com.anytypeio.anytype.presentation.objects.getProperType import com.anytypeio.anytype.presentation.relations.model.RelationOperationError -import com.anytypeio.anytype.presentation.relations.providers.RelationListProvider +import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationListProvider import com.anytypeio.anytype.presentation.util.Dispatcher import kotlinx.coroutines.Job import kotlinx.coroutines.flow.MutableSharedFlow @@ -44,7 +46,7 @@ import timber.log.Timber class RelationListViewModel( private val vmParams: VmParams, - private val relationListProvider: RelationListProvider, + private val objectRelationListProvider: ObjectRelationListProvider, private val lockedStateProvider: LockedStateProvider, private val urlBuilder: UrlBuilder, private val dispatcher: Dispatcher, @@ -79,7 +81,7 @@ class RelationListViewModel( jobs += viewModelScope.launch { combine( storeOfRelations.trackChanges(), - relationListProvider.details + objectRelationListProvider.details ) { _, details -> constructViews(ctx, details) }.collect { views.value = it } @@ -88,88 +90,46 @@ class RelationListViewModel( private suspend fun constructViews( ctx: Id, - details: Block.Details + details: ObjectViewDetails ): List { - val objectDetails = details.details[ctx]?.map ?: emptyMap() - val objectWrapper = ObjectWrapper.Basic(objectDetails) - val objectTypeId = objectWrapper.getProperType() - val objectTypeWrapper = details.details[objectTypeId]?.map?.mapToObjectWrapperType() - if (objectTypeWrapper == null) { - Timber.e("Couldn't find valid object type for id: $objectTypeId") - return emptyList() - } - - val objectRelationViews = getObjectRelationsView( + val objectRelationViews = details.getObjRelationsViews( ctx = ctx, - objectDetails = objectDetails, - details = details, - objectWrapper = objectWrapper - ) - - val recommendedRelationViews = getRecommendedRelations( - ctx = ctx, - objectDetails = objectDetails, - objectTypeWrapper = objectTypeWrapper, - details = details - ) - - return buildFinalList(objectRelationViews, recommendedRelationViews, objectTypeWrapper) - } - - private suspend fun getObjectRelationsView( - ctx: Id, - objectDetails: Map, - details: Block.Details, - objectWrapper: ObjectWrapper.Basic - ): List { - return getObjectRelations( - systemRelations = listOf(), - relationKeys = objectDetails.keys, - storeOfRelations = storeOfRelations - ).views( - context = ctx, - details = details, - values = objectDetails, - urlBuilder = urlBuilder, - featured = objectWrapper.featuredRelations, + storeOfRelations = storeOfRelations, fieldParser = fieldParser, + urlBuilder = urlBuilder ).map { view -> Model.Item( view = view, isRemovable = isPossibleToRemoveRelation(view) ) } - } - private suspend fun getRecommendedRelations( - ctx: Id, - objectDetails: Map, - objectTypeWrapper: ObjectWrapper.Type, - details: Block.Details - ): List { - return getNotIncludedRecommendedRelations( - relationKeys = objectDetails.keys, - recommendedRelations = objectTypeWrapper.recommendedRelations, - storeOfRelations = storeOfRelations - ).views( - context = ctx, - details = details, - values = objectDetails, - urlBuilder = urlBuilder, - fieldParser = fieldParser + val recommendedRelationViews = details.getRecommendedRelations( + ctx = ctx, + storeOfRelations = storeOfRelations, + fieldParser = fieldParser, + urlBuilder = urlBuilder ).map { view -> Model.Item( view = view, isRecommended = true ) } + + val objectWrapperType = details.getTypeForObject(currentObjectId = ctx) + + return buildFinalList( + objectRelations = objectRelationViews, + recommendedRelations = recommendedRelationViews, + objectTypeWrapper = objectWrapperType + ) } private fun buildFinalList( objectRelations: List, recommendedRelations: List, - objectTypeWrapper: ObjectWrapper.Type + objectTypeWrapper: ObjectWrapper.Type? ): MutableList { return mutableListOf().apply { val (isFeatured, other) = objectRelations.partition { it.view.featured } @@ -182,7 +142,7 @@ class RelationListViewModel( addAll(other) } if (recommendedRelations.isNotEmpty()) { - add(Model.Section.TypeFrom(objectTypeWrapper.name.orEmpty())) + add(Model.Section.TypeFrom(objectTypeWrapper?.name.orEmpty())) addAll(recommendedRelations) } } @@ -227,7 +187,7 @@ class RelationListViewModel( } private fun checkRelationIsInObject(view: ObjectRelationView): Boolean { - val objectRelations = relationListProvider.getDetails().details[vmParams.objectId]?.map?.keys + val objectRelations = objectRelationListProvider.getDetails().getStruct(vmParams.objectId)?.keys return objectRelations?.any { it == view.key } == true } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationObjectExtensions.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationObjectExtensions.kt index 8e4f8ee56c..a584501288 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationObjectExtensions.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/RelationObjectExtensions.kt @@ -1,15 +1,17 @@ package com.anytypeio.anytype.presentation.relations -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Key import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.RelationFormat import com.anytypeio.anytype.core_models.Relations -import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType import com.anytypeio.anytype.core_utils.ext.typeOf import com.anytypeio.anytype.domain.misc.UrlBuilder import com.anytypeio.anytype.domain.primitives.FieldParser +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getObject +import com.anytypeio.anytype.presentation.extension.getOptionObject +import com.anytypeio.anytype.presentation.extension.getTypeObject import com.anytypeio.anytype.presentation.number.NumberParser import com.anytypeio.anytype.presentation.sets.buildFileViews import com.anytypeio.anytype.presentation.sets.buildRelationValueObjectViews @@ -18,7 +20,7 @@ import com.anytypeio.anytype.presentation.sets.model.TagView fun List.views( context: Id, - details: Block.Details, + details: ObjectViewDetails, values: Map, urlBuilder: UrlBuilder, featured: List = emptyList(), @@ -36,7 +38,7 @@ fun List.views( fun ObjectWrapper.Relation.view( context: Id, - details: Block.Details, + details: ObjectViewDetails, values: Map, urlBuilder: UrlBuilder, isFeatured: Boolean = false, @@ -51,7 +53,7 @@ fun ObjectWrapper.Relation.view( RelationFormat.OBJECT -> { val objects = values.buildRelationValueObjectViews( relationKey = relation.key, - details = details.details, + details = details, builder = urlBuilder, fieldParser = fieldParser ) @@ -68,7 +70,7 @@ fun ObjectWrapper.Relation.view( RelationFormat.FILE -> { val files = values.buildFileViews( relationKey = relation.key, - details = details.details + details = details ) ObjectRelationView.File( id = relation.id, @@ -156,15 +158,14 @@ fun ObjectWrapper.Relation.view( fun statusRelation( context: Id, relationDetails: ObjectWrapper.Relation, - details: Block.Details, + details: ObjectViewDetails, isFeatured: Boolean ): ObjectRelationView? { - val objectDetails = details.details[context]?.map ?: return null + val objectDetails = details.getObject(context)?.map ?: return null val optionId = StatusParser.parse(objectDetails[relationDetails.key]) val statuses = buildList { if (optionId != null) { - val map = details.details[optionId]?.map ?: return null - val optionDetails = ObjectWrapper.Basic(map) + val optionDetails = details.getObject(optionId) ?: return null if (optionDetails.isDeleted != true) { add( StatusView( @@ -190,20 +191,19 @@ fun statusRelation( fun tagRelation( context: Id, relationDetails: ObjectWrapper.Relation, - details: Block.Details, + details: ObjectViewDetails, isFeatured: Boolean ): ObjectRelationView? { - val objectDetails = details.details[context]?.map ?: return null + val objectDetails = details.getObject(context)?.map ?: return null val tagViews = mutableListOf() val tagIds = TagParser.parse(objectDetails[relationDetails.key]) tagIds.forEach { id -> - val map = details.details[id]?.map ?: emptyMap() - val optionDetails = ObjectWrapper.Basic(map) - if (optionDetails.isDeleted != true) { + val optionDetails = details.getOptionObject(id) + if (optionDetails != null && optionDetails.isDeleted != true) { val tagView = TagView( id = id, tag = optionDetails.name.orEmpty(), - color = optionDetails.relationOptionColor.orEmpty() + color = optionDetails.color ) tagViews.add(tagView) } @@ -219,13 +219,12 @@ fun tagRelation( ) } -fun Block.Details.objectTypeRelation( +fun ObjectViewDetails.objectTypeRelation( relationKey: Key, isFeatured: Boolean, objectTypeId: Id ): ObjectRelationView { - val typeStruct = details[objectTypeId]?.map - val objectType = typeStruct?.mapToObjectWrapperType() + val objectType = getTypeObject(objectTypeId) return if (objectType == null || objectType.isDeleted == true) { ObjectRelationView.ObjectType.Deleted( id = objectTypeId, @@ -247,7 +246,7 @@ fun Block.Details.objectTypeRelation( } } -fun Block.Details.linksFeaturedRelation( +fun ObjectViewDetails.linksFeaturedRelation( relations: List, relationKey: Key, ctx: Id, @@ -256,8 +255,8 @@ fun Block.Details.linksFeaturedRelation( return when (relationKey) { Relations.BACKLINKS -> { val relation = relations.firstOrNull { it.key == relationKey } ?: return null - val objectDetails = ObjectWrapper.Basic(details[ctx]?.map ?: return null) - val backlinks = objectDetails.backlinks.filter { + val objectWrapper = getObject(ctx) ?: return null + val backlinks = objectWrapper.backlinks.filter { details.containsKey(it) } if (backlinks.isEmpty()) { @@ -277,8 +276,8 @@ fun Block.Details.linksFeaturedRelation( } Relations.LINKS -> { val relation = relations.firstOrNull { it.key == relationKey } ?: return null - val objectDetails = ObjectWrapper.Basic(details[ctx]?.map ?: return null) - val links = objectDetails.links.filter { + val objectWrapper = getObject(ctx) ?: return null + val links = objectWrapper.links.filter { details.containsKey(it) } if (links.isEmpty()) { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectRelationProvider.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectRelationProvider.kt index 7eb6ab3536..1f516555df 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectRelationProvider.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectRelationProvider.kt @@ -87,7 +87,7 @@ class SetOrCollectionRelationProvider( }.flatMapLatest { state -> when (state) { is ObjectState.DataView.Collection -> { - val objectKeys = state.details[id]?.map?.keys.orEmpty() + val objectKeys = state.details.details[id]?.keys.orEmpty() flow { objectKeys.mapNotNull { storeOfRelations.getByKey(it) @@ -95,7 +95,7 @@ class SetOrCollectionRelationProvider( } } is ObjectState.DataView.Set -> { - val objectKeys = state.details[id]?.map?.keys.orEmpty() + val objectKeys = state.details.details[id]?.keys.orEmpty() flow { objectKeys.mapNotNull { storeOfRelations.getByKey(it) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectValueProvider.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectValueProvider.kt index 6d27e2ae6f..d75d348140 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectValueProvider.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DataViewObjectValueProvider.kt @@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation.relations.providers import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Struct +import com.anytypeio.anytype.presentation.extension.getStruct import com.anytypeio.anytype.presentation.sets.ObjectSetDatabase import com.anytypeio.anytype.presentation.sets.state.ObjectState import kotlinx.coroutines.flow.Flow @@ -43,10 +44,9 @@ class DataViewObjectValueProvider( state: ObjectState, target: Id ) : Struct = when (state) { - is ObjectState.DataView.Collection -> state.details[target]?.map ?: emptyMap() - is ObjectState.DataView.Set -> state.details[target]?.map ?: emptyMap() - is ObjectState.ErrorLayout -> emptyMap() - is ObjectState.Init -> emptyMap() + is ObjectState.DataView.Collection -> state.details.getStruct(target).orEmpty() + is ObjectState.DataView.Set -> state.details.getStruct(target).orEmpty() + else -> emptyMap() } } @@ -79,10 +79,9 @@ class SetOrCollectionObjectValueProvider( state: ObjectState, target: Id ) : Struct = when (state) { - is ObjectState.DataView.Collection -> state.details[target]?.map ?: emptyMap() - is ObjectState.DataView.Set -> state.details[target]?.map ?: emptyMap() - is ObjectState.ErrorLayout -> emptyMap() - is ObjectState.Init -> emptyMap() + is ObjectState.DataView.Collection -> state.details.getStruct(target).orEmpty() + is ObjectState.DataView.Set -> state.details.getStruct(target).orEmpty() + else -> emptyMap() } } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectRelationProvider.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectRelationProvider.kt index a96f4001f4..9021a68c09 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectRelationProvider.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectRelationProvider.kt @@ -30,7 +30,7 @@ class DefaultObjectRelationProvider( ) { _, details -> details }.flatMapLatest { details -> - val objectKeys = details.details[id]?.map?.keys ?: emptyList() + val objectKeys = details.details[id]?.keys.orEmpty() flow { objectKeys.mapNotNull { storeOfRelations.getByKey(it) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectValueProvider.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectValueProvider.kt index 2b8c9e5017..056b835ce5 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectValueProvider.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/DefaultObjectValueProvider.kt @@ -1,9 +1,9 @@ package com.anytypeio.anytype.presentation.relations.providers -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Struct import com.anytypeio.anytype.presentation.editor.editor.Store +import kotlin.collections.orEmpty import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map @@ -11,12 +11,12 @@ class DefaultObjectValueProvider( private val details: Store.Details ) : ObjectValueProvider { override suspend fun get(ctx: Id, target: Id): Struct { - return details.current().details.getOrDefault(target, Block.Fields.empty()).map + return details.current().details[target].orEmpty() } override suspend fun subscribe(ctx: Id, target: Id): Flow { return details.stream().map { details -> - details.details.getOrDefault(target, Block.Fields.empty()).map + details.details[target].orEmpty() } } } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectDetailProvider.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectDetailProvider.kt deleted file mode 100644 index 93814315ec..0000000000 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectDetailProvider.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.anytypeio.anytype.presentation.relations.providers - -import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.core_models.Id - -interface ObjectDetailProvider { - fun provide() : Map -} \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectRelationListProvider.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectRelationListProvider.kt new file mode 100644 index 0000000000..bd14934686 --- /dev/null +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/ObjectRelationListProvider.kt @@ -0,0 +1,47 @@ +package com.anytypeio.anytype.presentation.relations.providers + +import com.anytypeio.anytype.presentation.editor.Editor +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.sets.state.ObjectState +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.map + +interface ObjectRelationListProvider { + + val details: Flow + + fun getDetails(): ObjectViewDetails + + class EditorRelationListProvider( + private val storage: Editor.Storage + ) : ObjectRelationListProvider { + override val details: Flow + get() = storage.details.stream() + + override fun getDetails() = storage.details.current() + } + + class ObjectSetRelationListProvider( + private val objectStates: StateFlow + ) : ObjectRelationListProvider { + + override val details = objectStates.map { state -> + mapDetails(state) + } + + override fun getDetails(): ObjectViewDetails = mapDetails(objectStates.value) + + private fun mapDetails(state: ObjectState) = when (state) { + is ObjectState.DataView.Collection -> { + state.details + } + + is ObjectState.DataView.Set -> { + state.details + } + + else -> ObjectViewDetails.EMPTY + } + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/RelationListProvider.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/RelationListProvider.kt deleted file mode 100644 index c7072083b0..0000000000 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/relations/providers/RelationListProvider.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.anytypeio.anytype.presentation.relations.providers - -import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.presentation.editor.Editor -import com.anytypeio.anytype.presentation.sets.state.ObjectState -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.map - -interface RelationListProvider { - - val details: Flow - - fun getDetails(): Block.Details - - class EditorRelationListProvider( - private val storage: Editor.Storage - ) : RelationListProvider { - override val details: Flow - get() = storage.details.stream() - - override fun getDetails() = storage.details.current() - } - - class ObjectSetRelationListProvider( - private val objectStates: StateFlow - ) : RelationListProvider { - - override val details = objectStates.map { state -> mapDetails(state) } - - override fun getDetails(): Block.Details = mapDetails(objectStates.value) - - private fun mapDetails(state: ObjectState) = when (state) { - is ObjectState.DataView.Collection -> { - Block.Details(state.details) - } - is ObjectState.DataView.Set -> { - Block.Details(state.details) - } - else -> Block.Details(emptyMap()) - } - - private fun mapLinks(state: ObjectState) = when (state) { - is ObjectState.DataView.Collection -> { - state.details.keys - } - is ObjectState.DataView.Set -> { - state.details.keys - } - else -> emptyList() - } - } -} \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetCreateBookmarkRecordViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetCreateBookmarkRecordViewModel.kt index 082ea3b483..c90c842b29 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetCreateBookmarkRecordViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetCreateBookmarkRecordViewModel.kt @@ -64,9 +64,9 @@ class ObjectSetCreateBookmarkRecordViewModel( is ObjectState.DataView.Set -> { val setOf = state.getSetOfValue(state.root) if (state.isSetByRelation(setOf)) { - val sourceDetails = state.details[setOf.firstOrNull()] - if (sourceDetails != null && sourceDetails.map.isNotEmpty()) { - val sourceObject = ObjectWrapper.Relation(sourceDetails.map) + val sourceDetails = state.details.details[setOf.firstOrNull()] + if (sourceDetails != null && sourceDetails.isNotEmpty()) { + val sourceObject = ObjectWrapper.Relation(sourceDetails) val viewer = state.viewerByIdOrFirst(session.currentViewerId.value) ?: return val details = viewer.resolveSetByRelationPrefilledObjectData( objSetByRelation = sourceObject, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetExtension.kt index 3926467ab5..a5d7b18350 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetExtension.kt @@ -27,7 +27,6 @@ import com.anytypeio.anytype.core_models.ext.DAYS_IN_WEEK import com.anytypeio.anytype.core_models.ext.DateParser import com.anytypeio.anytype.core_models.ext.EMPTY_STRING_VALUE import com.anytypeio.anytype.core_models.ext.SECONDS_IN_DAY -import com.anytypeio.anytype.core_models.ext.mapToObjectWrapperType import com.anytypeio.anytype.core_models.ext.title import com.anytypeio.anytype.core_models.primitives.TypeId import com.anytypeio.anytype.core_models.primitives.TypeKey @@ -41,8 +40,12 @@ import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes import com.anytypeio.anytype.domain.objects.StoreOfRelations import com.anytypeio.anytype.domain.primitives.FieldParser import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getObject +import com.anytypeio.anytype.presentation.extension.getTypeObject import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.mapper.objectIcon +import com.anytypeio.anytype.presentation.objects.getProperType import com.anytypeio.anytype.presentation.relations.BasicObjectCoverWrapper import com.anytypeio.anytype.presentation.relations.ObjectRelationView import com.anytypeio.anytype.presentation.relations.ObjectSetConfig.ID_KEY @@ -70,12 +73,13 @@ fun ObjectState.DataView.featuredRelations( val block = blocks.find { it.content is Block.Content.FeaturedRelations } if (block != null) { val views = mutableListOf() - val ids = details[ctx]?.featuredRelations ?: emptyList() + val currentObject = details.getObject(ctx) + val ids = currentObject?.featuredRelations views.addAll( mapFeaturedRelations( ctx = ctx, keys = ids, - details = Block.Details(details), + details = details, relations = relations, urlBuilder = urlBuilder, fieldParser = fieldParser @@ -98,10 +102,8 @@ fun ObjectState.DataView.header( ): SetOrCollectionHeaderState { val title = blocks.title() return if (title != null) { - val wrapper = ObjectWrapper.Basic( - map = details[ctx]?.map ?: emptyMap() - ) - val featured = wrapper.featuredRelations + val wrapper = details.getObject(ctx) + val featured = wrapper?.featuredRelations SetOrCollectionHeaderState.Default( title = title( ctx = ctx, @@ -110,7 +112,7 @@ fun ObjectState.DataView.header( details = details, coverImageHashProvider = coverImageHashProvider, ), - description = if (featured.contains(Relations.DESCRIPTION)) { + description = if (featured?.contains(Relations.DESCRIPTION) == true) { SetOrCollectionHeaderState.Description.Default( description = wrapper.description.orEmpty() ) @@ -126,94 +128,102 @@ fun ObjectState.DataView.header( private fun ObjectState.DataView.mapFeaturedRelations( ctx: Id, - keys: List, - details: Block.Details, + keys: List?, + details: ObjectViewDetails, relations: List, urlBuilder: UrlBuilder, fieldParser: FieldParser -): List = keys.mapNotNull { key -> - when (key) { - Relations.DESCRIPTION -> null - Relations.TYPE -> { +): List { + val currentObject = details.getObject(ctx) ?: return emptyList() + val featuredRelationsIds = currentObject.featuredRelations + return featuredRelationsIds.mapNotNull { key -> + when (key) { + Relations.DESCRIPTION -> null + Relations.TYPE -> { + val currentObjectType = currentObject.getProperType() + if (currentObjectType != null) { + val wrapper = details.getTypeObject(currentObjectType) + if (wrapper != null) { + val isDeleted = wrapper.isDeleted == true + if (isDeleted) { + ObjectRelationView.ObjectType.Deleted( + id = wrapper.id, + key = key, + featured = true, + readOnly = false, + system = key.isSystemKey() + ) + } else { + ObjectRelationView.ObjectType.Base( + id = wrapper.id, + key = key, + name = wrapper.name.orEmpty(), + featured = true, + readOnly = false, + type = wrapper.id, + system = key.isSystemKey() + ) + } + } else { + null + } + } else { + null + } + } + Relations.SET_OF -> { - val type = ObjectWrapper.Basic(details.details[ctx]?.map.orEmpty()).type.firstOrNull() - val typeMap = type?.let { details.details[it]?.map } + val source = currentObject.setOf.firstOrNull() - val isTypeMapValid = !typeMap.isNullOrEmpty() - val wrapper = if (isTypeMapValid) typeMap?.mapToObjectWrapperType() else null + val wrapper = if (source != null) { + details.getObject(source) + } else { + null + } - val isDeleted = wrapper == null || wrapper.isDeleted == true + val isValid = wrapper?.isValid == true + val isDeleted = wrapper?.isDeleted == true + val isReadOnly = wrapper?.relationReadonlyValue == true - if (wrapper != null && !isDeleted) { - ObjectRelationView.ObjectType.Base( - id = wrapper.id, + val sources = if (isValid && !isDeleted) { + listOf(wrapper.toObjectViewDefault(urlBuilder = urlBuilder, fieldParser = fieldParser)) + } else { + emptyList() + } + + ObjectRelationView.Source( + id = currentObject.id, key = key, - name = wrapper.name.orEmpty(), + name = Relations.RELATION_NAME_EMPTY, featured = true, - readOnly = false, - type = wrapper.id, - system = key.isSystemKey() - ) - } else { - ObjectRelationView.ObjectType.Deleted( - id = type.orEmpty(), - key = key, - featured = true, - readOnly = false, + readOnly = isReadOnly, + sources = sources, system = key.isSystemKey() ) } - } - Relations.SET_OF -> { - - val source = ObjectWrapper.Basic(details.details[ctx]?.map.orEmpty()).setOf.firstOrNull() - val sourceMap = source?.let { details.details[it]?.map } - - val isSourceMapValid = !sourceMap.isNullOrEmpty() - val wrapper = if (isSourceMapValid) ObjectWrapper.Basic(sourceMap) else null - - val isValid = wrapper?.isValid == true - val isDeleted = wrapper?.isDeleted == true - val isReadOnly = wrapper?.relationReadonlyValue == true - - val sources = if (isValid && !isDeleted) { - listOf(wrapper.toObjectViewDefault(urlBuilder = urlBuilder, fieldParser = fieldParser)) - } else { - emptyList() + Relations.BACKLINKS, Relations.LINKS -> { + details.linksFeaturedRelation( + relations = relations, + ctx = ctx, + relationKey = key, + isFeatured = true + ) + } + else -> { + val relation = relations.firstOrNull { it.key == key } + relation?.view( + details = details, + values = currentObject.map, + urlBuilder = urlBuilder, + isFeatured = true, + fieldParser = fieldParser + ) } - - ObjectRelationView.Source( - id = details.details[ctx]?.id.orEmpty(), - key = key, - name = Relations.RELATION_NAME_EMPTY, - featured = true, - readOnly = isReadOnly, - sources = sources, - system = key.isSystemKey() - ) - } - Relations.BACKLINKS, Relations.LINKS -> { - details.linksFeaturedRelation( - relations = relations, - ctx = ctx, - relationKey = key, - isFeatured = true - ) - } - else -> { - val relation = relations.firstOrNull { it.key == key } - relation?.view( - details = details.details, - values = details.details[ctx]?.map ?: emptyMap(), - urlBuilder = urlBuilder, - isFeatured = true, - fieldParser = fieldParser - ) } } + .sortedByDescending { it.key == Relations.SET_OF } + .sortedByDescending { it.key == Relations.TYPE } } - .sortedByDescending { it.key == Relations.SET_OF } - .sortedByDescending { it.key == Relations.TYPE } fun List.update(new: List): List { val update = new.associateBy { rec -> rec[ID_KEY] as String } @@ -400,7 +410,7 @@ fun List.updateViewerRelations(updates: List { - return ObjectWrapper.Basic(details[ctx]?.map.orEmpty()).setOf + return details.getObject(ctx)?.setOf.orEmpty() } fun ObjectState.DataView.filterOutDeletedAndMissingObjects(query: List): List { @@ -409,15 +419,13 @@ fun ObjectState.DataView.filterOutDeletedAndMissingObjects(query: List): Lis fun ObjectState.DataView.Set.isSetByRelation(setOfValue: List): Boolean { if (setOfValue.isEmpty()) return false - val objectDetails = details[setOfValue.first()]?.map.orEmpty() - val wrapper = ObjectWrapper.Basic(objectDetails) - return wrapper.layout == ObjectType.Layout.RELATION + val wrapper = details.getObject(setOfValue.first()) + return wrapper?.layout == ObjectType.Layout.RELATION } private fun ObjectState.DataView.isValidObject(objectId: Id): Boolean { - val objectDetails = details[objectId] ?: return false - val objectWrapper = ObjectWrapper.Basic(objectDetails.map) - return objectWrapper.isDeleted != true + val objectWrapper = details.getObject(objectId) + return objectWrapper?.isValid == true && objectWrapper.isDeleted != true } fun DVViewer.updateFields(fields: DVViewerFields?): DVViewer { @@ -549,7 +557,7 @@ suspend fun ObjectState.DataView.getActiveViewTypeAndTemplate( Timber.d("Set by type setOf param is null or empty, not possible to get Type and Template") Pair(null, null) } else { - val defaultSetObjectType = details[setOf]?.map?.mapToObjectWrapperType() + val defaultSetObjectType = details.getTypeObject(setOf) if (activeView.defaultTemplate.isNullOrEmpty()) { val defaultTemplateId = defaultSetObjectType?.defaultTemplateId Pair(defaultSetObjectType, defaultTemplateId) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt index fbefd671dd..6e63d980b9 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/ObjectSetViewModel.kt @@ -76,6 +76,7 @@ import com.anytypeio.anytype.presentation.navigation.AppNavigation import com.anytypeio.anytype.presentation.navigation.SupportNavigation import com.anytypeio.anytype.core_models.SupportedLayouts import com.anytypeio.anytype.core_models.TimeInMillis +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.navigation.NavPanelState import com.anytypeio.anytype.presentation.objects.getCreateObjectParams import com.anytypeio.anytype.presentation.objects.isCreateObjectAllowed @@ -104,7 +105,6 @@ import com.anytypeio.anytype.presentation.templates.TemplateView import com.anytypeio.anytype.presentation.util.Dispatcher import com.anytypeio.anytype.presentation.widgets.TypeTemplatesWidgetUI import com.anytypeio.anytype.presentation.widgets.TypeTemplatesWidgetUIAction -import com.anytypeio.anytype.presentation.widgets.collection.CollectionViewModel.Command.OpenShareScreen import com.anytypeio.anytype.presentation.widgets.enterEditing import com.anytypeio.anytype.presentation.widgets.exitEditing import com.anytypeio.anytype.presentation.widgets.hideMoreMenu @@ -1017,9 +1017,7 @@ class ObjectSetViewModel( if (isRestrictionPresent(DataViewRestriction.CREATE_OBJECT)) { toast(NOT_ALLOWED) } else { - val setObject = ObjectWrapper.Basic( - currentState.details[vmParams.ctx]?.map ?: emptyMap() - ) + val setObject = currentState.details.getObject(vmParams.ctx) val viewer = currentState.viewerByIdOrFirst(session.currentViewerId.value) if (viewer == null) { Timber.e("onCreateNewDataViewObject, Viewer is empty") @@ -1034,13 +1032,12 @@ class ObjectSetViewModel( val objectTypeUniqueKey = defaultObjectType?.uniqueKey - val sourceId = setObject.setOf.singleOrNull() - if (objectTypeUniqueKey == null) { + val sourceId = setObject?.setOf?.singleOrNull() + if (sourceId == null || objectTypeUniqueKey == null) { toast("Unable to define a source for a new object.") } else { - val sourceDetails = currentState.details[sourceId] - if (sourceDetails != null && sourceDetails.map.isNotEmpty()) { - val wrapper = ObjectWrapper.Basic(sourceDetails.map) + val wrapper = currentState.details.getObject(sourceId) + if (wrapper != null) { when (wrapper.layout) { ObjectType.Layout.OBJECT_TYPE -> { val uniqueKey = wrapper.getValue(Relations.UNIQUE_KEY) @@ -1088,7 +1085,7 @@ class ObjectSetViewModel( storeOfRelations = storeOfRelations, dateProvider = dateProvider, dataViewRelationLinks = currentState.dataViewContent.relationLinks, - objSetByRelation = ObjectWrapper.Relation(sourceDetails.map) + objSetByRelation = ObjectWrapper.Relation(wrapper.map) ) proceedWithCreatingDataViewObject( CreateDataViewObject.Params.SetByRelation( @@ -1244,8 +1241,7 @@ class ObjectSetViewModel( fun onMenuClicked() { Timber.d("onMenuClicked, ") val state = stateReducer.state.value.dataViewState() ?: return - val struct = state.details[vmParams.ctx]?.map ?: return - val wrapper = ObjectWrapper.Basic(struct) + val wrapper = state.details.getObject(vmParams.ctx) ?: return Timber.d("Wrapper: $wrapper") val space = wrapper.spaceId if (space != null) { @@ -1253,8 +1249,8 @@ class ObjectSetViewModel( ObjectSetCommand.Modal.Menu( ctx = vmParams.ctx, space = space, - isArchived = state.details[vmParams.ctx]?.isArchived ?: false, - isFavorite = state.details[vmParams.ctx]?.isFavorite ?: false, + isArchived = wrapper.isArchived == true, + isFavorite = wrapper.isFavorite == true, isReadOnly = !isOwnerOrEditor ) ) @@ -1268,9 +1264,8 @@ class ObjectSetViewModel( fun onObjectIconClicked() { Timber.d("onIconClicked, ") val state = stateReducer.state.value.dataViewState() ?: return - val struct = state.details[vmParams.ctx] - val wrapper = ObjectWrapper.Basic(struct?.map.orEmpty()) - val space = wrapper.spaceId + val wrapper = state.details.getObject(vmParams.ctx) + val space = wrapper?.spaceId if (space != null) { dispatch( ObjectSetCommand.Modal.OpenIconActionMenu( diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt index dde43665cf..89088db50a 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/SetsExtension.kt @@ -1,6 +1,5 @@ package com.anytypeio.anytype.presentation.sets -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Key import com.anytypeio.anytype.core_models.ObjectWrapper @@ -14,6 +13,9 @@ import com.anytypeio.anytype.presentation.mapper.objectIcon import com.anytypeio.anytype.presentation.number.NumberParser import com.anytypeio.anytype.presentation.objects.ObjectIcon import com.anytypeio.anytype.domain.primitives.FieldParser +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getFileObject +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.relations.getDateRelationFormat import com.anytypeio.anytype.presentation.sets.model.CellView import com.anytypeio.anytype.presentation.sets.model.ColumnView @@ -254,20 +256,18 @@ suspend fun List.buildGridRow( fun Struct.buildFileViews( relationKey: Id, - details: Map + details: ObjectViewDetails, ): List { val files = mutableListOf() val ids = getOrDefault(relationKey, null) ?: return emptyList() if (ids is Id) { - val map = details[ids]?.map ?: return emptyList() - val file = ObjectWrapper.File(map) - if (file.map.isEmpty() || file.isDeleted == true || file.isArchived == true) return emptyList() + val file = details.getFileObject(ids) + if (file == null || file.map.isEmpty() || file.isDeleted == true || file.isArchived == true) return emptyList() files.add(file.toView()) } else if (ids is List<*>) { ids.filterIsInstance().forEach { id -> - val map = details[id]?.map ?: return@forEach - val file = ObjectWrapper.File(map) - if (file.map.isEmpty() || file.isDeleted == true || file.isArchived == true) return@forEach + val file = details.getFileObject(id) + if (file == null || file.map.isEmpty() || file.isDeleted == true || file.isArchived == true) return@forEach files.add(file.toView()) } } @@ -290,21 +290,21 @@ private fun ObjectWrapper.File.toView() : FileView { fun Struct.buildRelationValueObjectViews( relationKey: Id, - details: Map, + details: ObjectViewDetails, builder: UrlBuilder, fieldParser: FieldParser ): List { val objects = mutableListOf() val value = this.getOrDefault(relationKey, null) if (value is Id) { - val wrapper = ObjectWrapper.Basic(details[value]?.map.orEmpty()) - if (wrapper.isValid) { + val wrapper = details.getObject(value) + if (wrapper != null) { objects.add(wrapper.toObjectView(urlBuilder = builder, fieldParser = fieldParser)) } } else if (value is List<*>) { value.typeOf().forEach { id -> - val wrapper = ObjectWrapper.Basic(details[id]?.map.orEmpty()) - if (wrapper.isValid) { + val wrapper = details.getObject(id) + if (wrapper != null) { objects.add(wrapper.toObjectView(urlBuilder = builder, fieldParser = fieldParser)) } } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/DefaultObjectStateReducer.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/DefaultObjectStateReducer.kt index 37fe500d2d..f633faeb17 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/DefaultObjectStateReducer.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/DefaultObjectStateReducer.kt @@ -6,9 +6,12 @@ import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.core_models.Event.Command import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.ObjectType +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.ext.amend import com.anytypeio.anytype.core_models.ext.unset +import com.anytypeio.anytype.core_models.getSingleValue import com.anytypeio.anytype.core_utils.ext.replace +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.updateFields import com.anytypeio.anytype.presentation.sets.updateFilters import com.anytypeio.anytype.presentation.sets.updateSorts @@ -116,17 +119,18 @@ class DefaultObjectStateReducer : ObjectStateReducer { * @see Command.ShowObject */ private fun handleShowObject(event: Command.ShowObject): ObjectState { - val objectState = when (val layout = event.details.details[event.root]?.layout?.toInt()) { + val objectState = when (val layout = event.details[event.root]?.getSingleValue( + Relations.LAYOUT)?.toInt()) { ObjectType.Layout.COLLECTION.code -> ObjectState.DataView.Collection( root = event.root, blocks = event.blocks, - details = event.details.details, + details = ObjectViewDetails(event.details), dataViewRestrictions = event.dataViewRestrictions ) ObjectType.Layout.SET.code -> ObjectState.DataView.Set( root = event.root, blocks = event.blocks, - details = event.details.details, + details = ObjectViewDetails(event.details), dataViewRestrictions = event.dataViewRestrictions ) else -> { @@ -368,16 +372,24 @@ class DefaultObjectStateReducer : ObjectStateReducer { event: Command.Details.Set ): ObjectState { return when (state) { - is ObjectState.DataView.Collection -> state.copy( - details = state.details.toMutableMap().apply { - put(event.target, event.details) - } - ) - is ObjectState.DataView.Set -> state.copy( - details = state.details.toMutableMap().apply { - put(event.target, event.details) - } - ) + is ObjectState.DataView.Collection -> { + state.copy( + details = ObjectViewDetails( + details = state.details.details.toMutableMap().apply { + put(event.target, event.details) + } + ) + ) + } + is ObjectState.DataView.Set -> { + state.copy( + details = ObjectViewDetails( + details = state.details.details.toMutableMap().apply { + put(event.target, event.details) + } + ) + ) + } else -> state } } @@ -391,15 +403,19 @@ class DefaultObjectStateReducer : ObjectStateReducer { ): ObjectState { return when (state) { is ObjectState.DataView.Collection -> state.copy( - details = state.details.amend( - target = event.target, - slice = event.details + details = state.details.copy( + details = state.details.details.amend( + target = event.target, + slice = event.details + ) ) ) is ObjectState.DataView.Set -> state.copy( - details = state.details.amend( - target = event.target, - slice = event.details + details = state.details.copy( + details = state.details.details.amend( + target = event.target, + slice = event.details + ) ) ) else -> state @@ -415,15 +431,19 @@ class DefaultObjectStateReducer : ObjectStateReducer { ): ObjectState { return when (state) { is ObjectState.DataView.Collection -> state.copy( - details = state.details.unset( - target = event.target, - keys = event.keys + details = state.details.copy( + details = state.details.details.unset( + target = event.target, + keys = event.keys + ) ) ) is ObjectState.DataView.Set -> state.copy( - details = state.details.unset( - target = event.target, - keys = event.keys + details = state.details.copy( + details = state.details.details.unset( + target = event.target, + keys = event.keys + ) ) ) else -> state diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/ObjectState.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/ObjectState.kt index b32b26b899..1006df5a87 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/ObjectState.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/sets/state/ObjectState.kt @@ -8,6 +8,7 @@ import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.restrictions.DataViewRestrictions import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction +import com.anytypeio.anytype.core_models.ObjectViewDetails sealed class ObjectState { @@ -17,7 +18,7 @@ sealed class ObjectState { abstract val root: Id abstract val blocks: List - abstract val details: Map + abstract val details: ObjectViewDetails abstract val objectRestrictions: List abstract val dataViewRestrictions: List @@ -28,7 +29,7 @@ sealed class ObjectState { data class Set( override val root: Id, override val blocks: List = emptyList(), - override val details: Map = emptyMap(), + override val details: ObjectViewDetails = ObjectViewDetails.EMPTY, override val objectRestrictions: List = emptyList(), override val dataViewRestrictions: List = emptyList(), ) : DataView() { @@ -42,7 +43,7 @@ sealed class ObjectState { data class Collection( override val root: Id, override val blocks: List = emptyList(), - override val details: Map = emptyMap(), + override val details: ObjectViewDetails = ObjectViewDetails.EMPTY, override val objectRestrictions: List = emptyList(), override val dataViewRestrictions: List = emptyList(), ) : DataView() { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/TemplateBlankViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/TemplateBlankViewModel.kt index 0bd8ab1d4a..cc2635f198 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/TemplateBlankViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/templates/TemplateBlankViewModel.kt @@ -10,6 +10,7 @@ import com.anytypeio.anytype.core_models.ext.asMap import com.anytypeio.anytype.presentation.common.BaseViewModel import com.anytypeio.anytype.presentation.editor.Editor import com.anytypeio.anytype.presentation.editor.EditorViewModel +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.render.BlockViewRenderer import com.anytypeio.anytype.presentation.editor.render.DefaultBlockViewRenderer @@ -70,8 +71,8 @@ class TemplateBlankViewModel( ) val featuredRelations = listOf(Relations.TYPE) val page = listOf(rootBlock, headerBlock, blockTitle, featuredRelationsBlock) - val objectDetails = Block.Fields( - mapOf( + val objectDetails = mapOf( + DEFAULT_TEMPLATE_ID_BLANK to mapOf( Relations.ID to DEFAULT_TEMPLATE_ID_BLANK, Relations.LAYOUT to layout, Relations.TYPE to typeId, @@ -80,8 +81,8 @@ class TemplateBlankViewModel( ) ) - val typeDetails = Block.Fields( - mapOf( + val typeDetails = mapOf( + typeId to mapOf( Relations.ID to typeId, Relations.UNIQUE_KEY to ObjectTypeIds.TEMPLATE, Relations.NAME to TEMPLATE_TYPE_NAME, @@ -90,7 +91,8 @@ class TemplateBlankViewModel( ) val customDetails = - Block.Details(mapOf(DEFAULT_TEMPLATE_ID_BLANK to objectDetails, typeId to typeDetails)) + ObjectViewDetails( + details = mapOf(DEFAULT_TEMPLATE_ID_BLANK to objectDetails, typeId to typeDetails)) viewModelScope.launch { state.value = page.asMap().render( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt index 3db0504e99..2685ea44f1 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/CollectionAddRelationTest.kt @@ -3,17 +3,16 @@ package com.anytypeio.anytype.presentation.collections import android.util.Log import app.cash.turbine.test import com.anytypeio.anytype.core_models.Block -import com.anytypeio.anytype.core_models.DVViewerRelation import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.core_models.ObjectType -import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.RelationLink import com.anytypeio.anytype.core_models.Relations -import com.anytypeio.anytype.core_models.Relations.ID import com.anytypeio.anytype.core_models.Relations.LAYOUT import com.anytypeio.anytype.core_models.StubRelationObject -import com.anytypeio.anytype.domain.primitives.FieldParserImpl +import com.anytypeio.anytype.core_models.DVViewerRelation +import com.anytypeio.anytype.core_models.ObjectViewDetails +import com.anytypeio.anytype.presentation.extension.getObject import com.anytypeio.anytype.presentation.objects.ObjectIcon import com.anytypeio.anytype.presentation.relations.model.DefaultObjectRelationValueView import com.anytypeio.anytype.presentation.sets.DataViewViewState @@ -77,11 +76,13 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() { stubInterceptEvents() stubInterceptThreadStatus() - val rootObject = ObjectWrapper.Basic( - map = mapOf( - ID to root, - Relations.NAME to objectCollection.details.details[root]?.name, - LAYOUT to COLLECTION_LAYOUT + val objectViewDetails = ObjectViewDetails( + details = mapOf( + root to mapOf( + Relations.ID to root, + Relations.NAME to objectCollection.details.getObject(root)?.name!!, + LAYOUT to COLLECTION_LAYOUT + ) ) ) @@ -91,7 +92,7 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() { objectCollection.title, objectCollection.dataView ), - details = objectCollection.details + details = objectViewDetails ) // TESTING @@ -192,9 +193,7 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() { objectCollection.title, objectCollection.dataView ), - details = mapOf( - rootObject.id to Block.Fields(rootObject.map) - ), + details = objectViewDetails, objectRestrictions = listOf(), dataViewRestrictions = listOf() ), @@ -202,11 +201,12 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() { ) //Add new relation from marketplace to object and view - val eventObjectDetailsSet = Event.Command.Details.Set( + val eventObjectDetailsSet = Event.Command.Details.Amend( context = root, - target = relationId4, - details = Block.Fields(relationObject4.map) + target = root, + details = mapOf(relationKey4 to "") ) + val eventDataViewRelationSet = Event.Command.DataView.SetRelation( context = root, dv = objectCollection.dataView.id, @@ -282,9 +282,12 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() { objectCollection.title, expectedDataView ), - details = mapOf( - rootObject.id to Block.Fields(rootObject.map), - relationObject4.id to Block.Fields(relationObject4.map) + details = objectViewDetails.copy( + details = objectViewDetails.details.toMutableMap().apply { + this[root] = this[root]!!.toMutableMap().apply { + put(relationKey4, "") + } + } ), objectRestrictions = listOf(), dataViewRestrictions = listOf() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt index 7418e47b98..be7957a803 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockCollection.kt @@ -19,6 +19,7 @@ import com.anytypeio.anytype.core_models.StubObject import com.anytypeio.anytype.core_models.StubRelationLink import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.StubTitle +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.subscription.DefaultDataViewSubscription import com.anytypeio.anytype.test_utils.MockDataFactory import net.bytebuddy.utility.RandomString @@ -242,14 +243,12 @@ class MockCollection( val subscriptionId = DefaultDataViewSubscription.getDataViewSubscriptionId(context) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields( - mapOf( - Relations.ID to root, - Relations.NAME to MockDataFactory.randomString(), - Relations.LAYOUT to ObjectType.Layout.COLLECTION.code.toDouble() - ) + root to mapOf( + Relations.ID to root, + Relations.NAME to MockDataFactory.randomString(), + Relations.LAYOUT to ObjectType.Layout.COLLECTION.code.toDouble() ) ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockSet.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockSet.kt index ae072735c5..8c6db58b00 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockSet.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/MockSet.kt @@ -18,6 +18,7 @@ import com.anytypeio.anytype.core_models.StubObject import com.anytypeio.anytype.core_models.StubRelationLink import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.StubTitle +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.subscription.DefaultDataViewSubscription import com.anytypeio.anytype.test_utils.MockDataFactory import net.bytebuddy.utility.RandomString @@ -189,18 +190,16 @@ class MockSet( ) // SET OBJECT DETAILS - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.SPACE_ID to spaceId, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to listOf(setOf) - ) ), - setOf to Block.Fields( - map = mapOf( + setOf to mapOf( Relations.ID to setOf, Relations.SPACE_ID to spaceId, Relations.UNIQUE_KEY to setOfKey, @@ -208,13 +207,12 @@ class MockSet( Relations.RECOMMENDED_LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), Relations.LAYOUT to ObjectType.Layout.OBJECT_TYPE.code.toDouble(), ) - ) ) ) - val detailsEmptySetOf = Block.Details( + val detailsEmptySetOf = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.SPACE_ID to spaceId, @@ -222,41 +220,37 @@ class MockSet( Relations.SET_OF to listOf() ) ) - ) ) - val detailsSetByRelation = Block.Details( + val detailsSetByRelation = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.SPACE_ID to spaceId, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to relationObject3.id - ) - ), - relationObject3.id to Block.Fields( + ), + relationObject3.id to mapOf( Relations.ID to relationObject3.id, Relations.SPACE_ID to spaceId, Relations.RELATION_KEY to relationObject3.key, Relations.LAYOUT to ObjectType.Layout.RELATION.code.toDouble() ) - ) ) ) - fun detailsSetByRelation(relationSetBy: ObjectWrapper.Relation) = Block.Details( + fun detailsSetByRelation(relationSetBy: ObjectWrapper.Relation) = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.SPACE_ID to spaceId, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to relationSetBy.id - ) ), - relationSetBy.id to Block.Fields( + relationSetBy.id to mapOf( Relations.ID to relationSetBy.id, Relations.SPACE_ID to spaceId, @@ -264,7 +258,7 @@ class MockSet( Relations.UNIQUE_KEY to relationSetBy.uniqueKey, Relations.LAYOUT to ObjectType.Layout.RELATION.code.toDouble(), ) - ) + ) ) } \ No newline at end of file diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt index 7503cfe95b..33628a7eeb 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateCollectionViewTest.kt @@ -10,6 +10,7 @@ import com.anytypeio.anytype.core_models.primitives.TypeKey import com.anytypeio.anytype.core_models.restrictions.DataViewRestriction import com.anytypeio.anytype.core_models.restrictions.DataViewRestrictions import com.anytypeio.anytype.core_models.SupportedLayouts +import com.anytypeio.anytype.core_models.getSingleValue import com.anytypeio.anytype.domain.primitives.FieldParserImpl import com.anytypeio.anytype.presentation.sets.DataViewViewState import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel @@ -76,7 +77,9 @@ class ObjectStateCollectionViewTest : ObjectSetViewModelTestSetup() { assertIs(stateFlow.awaitItem()) assertEquals( - expected = mockObjectCollection.details.details[mockObjectCollection.root]?.name, + expected = mockObjectCollection.details.details[mockObjectCollection.root]?.getSingleValue( + Relations.NAME + ), actual = (headerFlow.awaitItem() as SetOrCollectionHeaderState.Default).title.text ) viewerFlow.expectNoEvents() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateSetViewTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateSetViewTest.kt index fff90ae979..a3e8719e22 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateSetViewTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/collections/ObjectStateSetViewTest.kt @@ -3,14 +3,13 @@ package com.anytypeio.anytype.presentation.collections import app.cash.turbine.test import app.cash.turbine.testIn import app.cash.turbine.turbineScope -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.StubObject import com.anytypeio.anytype.core_models.primitives.SpaceId -import com.anytypeio.anytype.domain.primitives.FieldParserImpl +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.relations.ObjectSetConfig import com.anytypeio.anytype.presentation.search.ObjectSearchConstants import com.anytypeio.anytype.presentation.sets.DataViewViewState @@ -60,14 +59,13 @@ class ObjectStateSetViewTest : ObjectSetViewModelTestSetup() { stubInterceptEvents() stubInterceptThreadStatus() - val objectDetails = Block.Details( + val objectDetails = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble() ) - ) ) ) stubOpenObject( @@ -280,26 +278,23 @@ class ObjectStateSetViewTest : ObjectSetViewModelTestSetup() { ) ) - val detailsDeletedSetOf = Block.Details( + val detailsDeletedSetOf = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to listOf(typeDeleted1.id, type2.id, typeDeleted3.id) - ) ), - typeDeleted1.id to Block.Fields( + typeDeleted1.id to mapOf( Relations.ID to typeDeleted1.id, Relations.IS_DELETED to true - ) ), - type2.id to Block.Fields( + type2.id to mapOf( Relations.ID to type2.id, Relations.TYPE to ObjectTypeIds.OBJECT_TYPE - ) ) ) ) @@ -375,21 +370,19 @@ class ObjectStateSetViewTest : ObjectSetViewModelTestSetup() { ) ) - val detailsDeletedSetOf = Block.Details( + val detailsDeletedSetOf = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to listOf(typeDeleted1.id, typeDeleted3.id) - ) ), - typeDeleted1.id to Block.Fields( + typeDeleted1.id to mapOf( Relations.ID to typeDeleted1.id, Relations.IS_DELETED to true ) - ) ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DataViewBlockTargetObjectSetTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DataViewBlockTargetObjectSetTest.kt index ec7222c4d4..05d1d1ad2d 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DataViewBlockTargetObjectSetTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DataViewBlockTargetObjectSetTest.kt @@ -14,6 +14,7 @@ import com.anytypeio.anytype.core_models.StubTitle import com.anytypeio.anytype.core_models.ThemeColor import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.domain.event.interactor.InterceptEvents +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.EditorPresentationTestSetup import com.anytypeio.anytype.presentation.editor.editor.ViewState import com.anytypeio.anytype.presentation.editor.editor.model.BlockView @@ -118,15 +119,15 @@ class DataViewBlockTargetObjectSetTest : EditorPresentationTestSetup() { children = listOf(header.id, block.id, dv.id), content = Block.Content.Smart ) - val objectDetails = Block.Fields( + val objectDetails = mapOf( + Relations.ID to targetObjectId, Relations.TYPE to ObjectTypeIds.SET, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to listOf("") ) - ) - val detailsList = Block.Details(details = mapOf(targetObjectId to objectDetails)) + val detailsList = ObjectViewDetails(details = mapOf(targetObjectId to objectDetails)) stubOpenDocument(document = listOf(page, header, title, block, dv), details = detailsList) stubInterceptEvents(params = params) @@ -181,15 +182,15 @@ class DataViewBlockTargetObjectSetTest : EditorPresentationTestSetup() { children = listOf(header.id, block.id, dv.id), content = Block.Content.Smart ) - val objectDetails = Block.Fields( + val objectDetails = mapOf( + Relations.ID to targetObjectId, Relations.TYPE to ObjectTypeIds.SET, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to emptyList() ) - ) - val detailsList = Block.Details(details = mapOf(targetObjectId to objectDetails)) + val detailsList = ObjectViewDetails(details = mapOf(targetObjectId to objectDetails)) stubOpenDocument(document = listOf(page, header, title, block, dv), details = detailsList) stubInterceptEvents(params = params) @@ -244,15 +245,15 @@ class DataViewBlockTargetObjectSetTest : EditorPresentationTestSetup() { children = listOf(header.id, block.id, dv.id), content = Block.Content.Smart ) - val objectDetails = Block.Fields( + val objectDetails = mapOf( + Relations.ID to targetObjectId, Relations.TYPE to ObjectTypeIds.SET, Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), Relations.SET_OF to listOf("", " ", RandomString.make()) ) - ) - val detailsList = Block.Details(details = mapOf(targetObjectId to objectDetails)) + val detailsList = ObjectViewDetails(details = mapOf(targetObjectId to objectDetails)) stubOpenDocument(document = listOf(page, header, title, block, dv), details = detailsList) stubInterceptEvents(params = params) @@ -307,14 +308,14 @@ class DataViewBlockTargetObjectSetTest : EditorPresentationTestSetup() { children = listOf(header.id, block.id, dv.id), content = Block.Content.Smart ) - val objectDetails = Block.Fields( + val objectDetails = mapOf( + Relations.ID to targetObjectId, Relations.TYPE to ObjectTypeIds.COLLECTION, Relations.LAYOUT to ObjectType.Layout.COLLECTION.code.toDouble() ) - ) - val detailsList = Block.Details(details = mapOf(targetObjectId to objectDetails)) + val detailsList = ObjectViewDetails(details = mapOf(targetObjectId to objectDetails)) stubOpenDocument(document = listOf(page, header, title, block, dv), details = detailsList) stubInterceptEvents(params = params) @@ -444,7 +445,18 @@ class DataViewBlockTargetObjectSetTest : EditorPresentationTestSetup() { ) } - stubOpenDocument(document = listOf(page, header, title, block, dv)) + stubOpenDocument( + document = listOf(page, header, title, block, dv), + details = ObjectViewDetails( + details = mapOf( + targetObjectId to mapOf( + Relations.ID to targetObjectId, + Relations.UNIQUE_KEY to targetObjectId, + Relations.RECOMMENDED_LAYOUT to ObjectType.Layout.BASIC.code.toDouble() + ) + ) + ) + ) stubInterceptEvents( params = params, flow = events diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt index 5fbfcd76e0..db243c536d 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/DefaultBlockViewRendererTest.kt @@ -19,7 +19,6 @@ import com.anytypeio.anytype.core_models.ext.asMap import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.core_models.ext.parseThemeTextColor import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction -import com.anytypeio.anytype.core_utils.const.DetailsKeys import com.anytypeio.anytype.domain.config.Gateway import com.anytypeio.anytype.domain.debugging.Logger import com.anytypeio.anytype.domain.editor.Editor @@ -37,6 +36,7 @@ import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubLinkConten import com.anytypeio.anytype.presentation.MockBlockFactory.link import com.anytypeio.anytype.presentation.MockTypicalDocumentFactory import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.Markup import com.anytypeio.anytype.presentation.editor.editor.Markup.Companion.NON_EXISTENT_OBJECT_MENTION_NAME import com.anytypeio.anytype.presentation.editor.editor.model.Alignment @@ -73,7 +73,7 @@ class DefaultBlockViewRendererTest { anchor: Id, focus: Editor.Focus, indent: Int, - details: Block.Details, + details: ObjectViewDetails, schema: NestedDecorationData = emptyList() ): List = blocks.render( context = root.id, @@ -228,7 +228,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(paragraph.id), indent = 0, - details = Block.Details() + details = ObjectViewDetails.EMPTY ) } @@ -359,7 +359,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(paragraph.id), indent = 0, - details = Block.Details() + details = ObjectViewDetails.EMPTY ) } @@ -479,7 +479,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(paragraph.id), indent = 0, - details = Block.Details() + details = ObjectViewDetails.EMPTY ) } @@ -566,7 +566,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(paragraph.id), indent = 0, - details = Block.Details() + details = ObjectViewDetails.EMPTY ) } @@ -634,20 +634,18 @@ class DefaultBlockViewRendererTest { val name = MockDataFactory.randomString() val imageName = MockDataFactory.randomString() val pageId = MockDataFactory.randomUuid() - val fields = Block.Fields( - map = mapOf( - Relations.ID to pageId, - Relations.NAME to name, - Relations.ICON_IMAGE to imageName, - Relations.LAYOUT to ObjectType.Layout.PROFILE.code.toDouble() - ) + val struct = mapOf( + Relations.ID to pageId, + Relations.NAME to name, + Relations.ICON_IMAGE to imageName, + Relations.LAYOUT to Layout.PROFILE.code.toDouble() ) - val details = mapOf(pageId to fields) + val details = mapOf(pageId to struct) val page = Block( id = pageId, children = listOf(header.id, paragraph.id), - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -666,7 +664,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(paragraph.id), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails(details) ) } @@ -734,19 +732,16 @@ class DefaultBlockViewRendererTest { val name = MockDataFactory.randomString() val imageName = MockDataFactory.randomString() val pageId = MockDataFactory.randomUuid() - val fields = Block.Fields( - map = mapOf( - "name" to name, - "iconImage" to imageName - ) + val struct = mapOf( + Relations.ID to pageId, + "name" to name, + "iconImage" to imageName ) - val details = mapOf(pageId to fields) + val details = mapOf(pageId to struct) - val page = Block( + val page = StubSmartBlock( id = pageId, children = listOf(header.id, paragraph.id), - fields = fields, - content = Block.Content.Smart ) val blocks = listOf(page, header, title, paragraph) @@ -764,7 +759,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(paragraph.id), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails(details) ) } @@ -853,17 +848,11 @@ class DefaultBlockViewRendererTest { fields = Block.Fields.empty() ) - val fields = Block.Fields.empty() - - val page = Block( + val page = StubSmartBlock( id = MockDataFactory.randomUuid(), children = listOf(header.id, a.id), - fields = fields, - content = Block.Content.Smart ) - val details = mapOf(page.id to fields) - val blocks = listOf(page, header, title, a, b, c) val map = blocks.asMap() @@ -879,7 +868,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -1008,17 +997,11 @@ class DefaultBlockViewRendererTest { fields = Block.Fields.empty() ) - val fields = Block.Fields.empty() - - val page = Block( + val page = StubSmartBlock( id = MockDataFactory.randomUuid(), children = listOf(header.id, a.id), - fields = fields, - content = Block.Content.Smart ) - val details = mapOf(page.id to fields) - val blocks = listOf(page, header, title, a, b, c) val map = blocks.asMap() @@ -1034,7 +1017,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -1160,12 +1143,12 @@ class DefaultBlockViewRendererTest { fields = Block.Fields.empty() ) - val fields = Block.Fields.empty() + val fields = mapOf() val page = Block( id = MockDataFactory.randomUuid(), children = listOf(header.id, a.id), - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -1186,7 +1169,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails(details) ) } @@ -1276,12 +1259,12 @@ class DefaultBlockViewRendererTest { children = listOf(title.id) ) - val fields = Block.Fields.empty() + val fields = mapOf() val page = Block( id = MockDataFactory.randomUuid(), children = listOf(header.id), - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -1303,7 +1286,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details), + details = ObjectViewDetails(details), ) } @@ -1344,12 +1327,12 @@ class DefaultBlockViewRendererTest { children = listOf(title.id) ) - val fields = Block.Fields.empty() + val fields = mapOf() val page = Block( id = MockDataFactory.randomUuid(), children = listOf(header.id), - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -1371,7 +1354,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails(details) ) } @@ -1467,19 +1450,18 @@ class DefaultBlockViewRendererTest { ) val randomEmoji1 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( - Block.Fields.NAME_KEY to mentionTextUpdated1, - DetailsKeys.ICON_EMOJI to randomEmoji1 + Relations.ID to mentionTarget1, + Relations.NAME to mentionTextUpdated1, + Relations.ICON_EMOJI to randomEmoji1 ) - ) val randomEmoji2 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated2 = Block.Fields( - mapOf( - Block.Fields.NAME_KEY to mentionTextUpdated2, - DetailsKeys.ICON_EMOJI to randomEmoji2 - ) + val fieldsUpdated2 = mapOf( + Relations.ID to mentionTarget2, + Relations.NAME to mentionTextUpdated2, + Relations.ICON_EMOJI to randomEmoji2 ) val detailsAmend = mapOf( @@ -1502,7 +1484,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -1652,20 +1634,20 @@ class DefaultBlockViewRendererTest { ) val randomEmoji1 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( - Block.Fields.NAME_KEY to mentionTextUpdated1, - DetailsKeys.ICON_EMOJI to randomEmoji1 + Relations.ID to mentionTarget1, + Relations.NAME to mentionTextUpdated1, + Relations.ICON_EMOJI to randomEmoji1 ) - ) val randomEmoji2 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated2 = Block.Fields( + val fieldsUpdated2 = mapOf( - Block.Fields.NAME_KEY to mentionTextUpdated2, - DetailsKeys.ICON_EMOJI to randomEmoji2 + Relations.ID to mentionTarget2, + Relations.NAME to mentionTextUpdated2, + Relations.ICON_EMOJI to randomEmoji2 ) - ) val detailsAmend = mapOf( mentionTarget1 to fieldsUpdated1, @@ -1687,7 +1669,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -1837,22 +1819,22 @@ class DefaultBlockViewRendererTest { ) val randomEmoji1 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( + Relations.ID to mentionTarget1, "name" to "XmN34", "snippet" to mentionTextUpdated1, "layout" to 9.0 ) - ) val randomEmoji2 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated2 = Block.Fields( + val fieldsUpdated2 = mapOf( + Relations.ID to mentionTarget2, "name" to mentionTextUpdated2, "iconEmoji" to randomEmoji2, "layout" to 0.0 ) - ) val detailsAmend = mapOf( mentionTarget1 to fieldsUpdated1, @@ -1874,7 +1856,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -2019,18 +2001,18 @@ class DefaultBlockViewRendererTest { ) val randomEmoji1 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( - DetailsKeys.ICON_EMOJI to randomEmoji1 + Relations.ID to mentionTarget1, + Relations.ICON_EMOJI to randomEmoji1 ) - ) val randomEmoji2 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated2 = Block.Fields( + val fieldsUpdated2 = mapOf( - DetailsKeys.ICON_EMOJI to randomEmoji2 + Relations.ID to mentionTarget2, + Relations.ICON_EMOJI to randomEmoji2 ) - ) val detailsAmend = mapOf( mentionTarget1 to fieldsUpdated1, @@ -2052,7 +2034,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -2188,18 +2170,16 @@ class DefaultBlockViewRendererTest { ) val randomEmoji1 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( - DetailsKeys.ICON_EMOJI to randomEmoji1 + Relations.ICON_EMOJI to randomEmoji1 ) - ) val randomEmoji2 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated2 = Block.Fields( + val fieldsUpdated2 = mapOf( - DetailsKeys.ICON_EMOJI to randomEmoji2 + Relations.ICON_EMOJI to randomEmoji2 ) - ) val detailsAmend = mapOf( mentionTarget1 to fieldsUpdated1, @@ -2221,7 +2201,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -2320,7 +2300,10 @@ class DefaultBlockViewRendererTest { content = Block.Content.Smart ) - val fieldsUpdated1 = Block.Fields(mapOf(Relations.NAME to mentionText2)) + val fieldsUpdated1 = mapOf( + Relations.ID to mentionTarget1, + Relations.NAME to mentionText2 + ) val detailsAmend = mapOf(mentionTarget1 to fieldsUpdated1) @@ -2339,7 +2322,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -2462,21 +2445,21 @@ class DefaultBlockViewRendererTest { ) val randomEmoji1 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( - Block.Fields.NAME_KEY to mentionTextUpdated1, + Relations.ID to mentionTarget1, + Relations.NAME to mentionTextUpdated1, Relations.IS_DELETED to true, - DetailsKeys.ICON_EMOJI to randomEmoji1 + Relations.ICON_EMOJI to randomEmoji1 ) - ) val randomEmoji2 = DefaultDocumentEmojiIconProvider.DOCUMENT_SET.random() - val fieldsUpdated2 = Block.Fields( + val fieldsUpdated2 = mapOf( - Block.Fields.NAME_KEY to mentionTextUpdated2, - DetailsKeys.ICON_EMOJI to randomEmoji2 + Relations.ID to mentionTarget2, + Relations.NAME to mentionTextUpdated2, + Relations.ICON_EMOJI to randomEmoji2 ) - ) val detailsAmend = mapOf( mentionTarget1 to fieldsUpdated1, @@ -2498,7 +2481,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -2598,10 +2581,11 @@ class DefaultBlockViewRendererTest { val snippet = MockDataFactory.randomString() val name = MockDataFactory.randomString() - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - target to Block.Fields( + target to mapOf( + Relations.ID to page.id, "name" to name, "description" to "", "snippet" to snippet, @@ -2609,7 +2593,6 @@ class DefaultBlockViewRendererTest { ) ) ) - ) wrapper = BlockViewRenderWrapper( blocks = map, @@ -2729,12 +2712,12 @@ class DefaultBlockViewRendererTest { fields = Block.Fields.empty() ) - val fields = Block.Fields.empty() + val fields = mapOf() val page = Block( id = MockDataFactory.randomUuid(), children = listOf(header.id, a.id), - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -2755,7 +2738,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails(details) ) } @@ -2960,8 +2943,6 @@ class DefaultBlockViewRendererTest { content = Block.Content.Smart ) - val details = mapOf(page.id to Block.Fields.empty()) - val blocks = listOf(page, header, title, a1, a2, a3, a4, b1, b2, b3) val map = blocks.asMap() @@ -2977,7 +2958,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -3214,7 +3195,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -3348,7 +3329,7 @@ class DefaultBlockViewRendererTest { ) } - val fields = Block.Fields.empty() + val fields = mapOf() val div1 = Block( @@ -3390,7 +3371,7 @@ class DefaultBlockViewRendererTest { val page = Block( id = "root", children = listOf(header.id) + listOf(div1.id, div2.id, div3.id, div4.id), - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -3411,7 +3392,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -3478,7 +3459,7 @@ class DefaultBlockViewRendererTest { ) } - val fields = Block.Fields.empty() + val fields = mapOf() val div1 = Block( @@ -3525,7 +3506,7 @@ class DefaultBlockViewRendererTest { div3.id, div4.id ) + numbered.subList(20, 25).map { it.id }, - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -3546,7 +3527,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -3662,7 +3643,7 @@ class DefaultBlockViewRendererTest { fields = Block.Fields.empty() ) - val fields = Block.Fields.empty() + val fields = mapOf() val div1 = Block( @@ -3711,7 +3692,7 @@ class DefaultBlockViewRendererTest { div1.id, div2.id ) + listOf(afterDiv2Num1.id, afterDiv2Num2.id), - fields = fields, + fields = Block.Fields.empty(), content = Block.Content.Smart ) @@ -3744,7 +3725,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -4010,7 +3991,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -4246,7 +4227,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -4345,7 +4326,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -4460,7 +4441,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -4610,7 +4591,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -4782,7 +4763,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -4908,15 +4889,15 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details( + details = ObjectViewDetails( mapOf( - bookmarkObjectId to Block.Fields( - mapOf( - Relations.NAME to bookmarkTitle, - Relations.DESCRIPTION to bookmarkDescription, - Relations.SOURCE to bookmarkUrl - ) - ) + bookmarkObjectId to + mapOf( + Relations.ID to page.id, + Relations.NAME to bookmarkTitle, + Relations.DESCRIPTION to bookmarkDescription, + Relations.SOURCE to bookmarkUrl + ) ) ) ) @@ -4987,7 +4968,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details() + details = ObjectViewDetails.EMPTY ) } @@ -5051,7 +5032,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details() + details = ObjectViewDetails.EMPTY ) } @@ -5112,7 +5093,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -5171,7 +5152,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -5249,7 +5230,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -5348,7 +5329,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -5426,7 +5407,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -5539,14 +5520,13 @@ class DefaultBlockViewRendererTest { content = Block.Content.Smart ) - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( Relations.ID to mentionTarget1, Relations.NAME to mentionTextUpdated1, Relations.TIMESTAMP to 1733775232, Relations.LAYOUT to Layout.DATE.code.toDouble() ) - ) val detailsAmend = mapOf( mentionTarget1 to fieldsUpdated1, @@ -5567,7 +5547,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -5680,14 +5660,13 @@ class DefaultBlockViewRendererTest { content = Block.Content.Smart ) - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( Relations.ID to mentionTarget1, Relations.NAME to mentionTextUpdated1, Relations.TIMESTAMP to 1733775232, Relations.LAYOUT to Layout.DATE.code.toDouble() ) - ) val detailsAmend = mapOf( mentionTarget1 to fieldsUpdated1, @@ -5708,7 +5687,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.id(a.id), indent = 0, - details = Block.Details(detailsAmend) + details = ObjectViewDetails(detailsAmend) ) } @@ -5778,14 +5757,13 @@ class DefaultBlockViewRendererTest { val page = StubSmartBlock(id = currentObjectId, children = listOf(paragraph.id, file.id)) val details = mapOf( - page.id to Block.Fields( + page.id to mapOf( Relations.ID to currentObjectId, Relations.NAME to "file-name", Relations.LAYOUT to layout.code.toDouble() ) ) - ) val blocks = listOf(page, paragraph, file) @@ -5802,7 +5780,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails(details) ) } @@ -5846,14 +5824,13 @@ class DefaultBlockViewRendererTest { val page = StubSmartBlock(id = currentObjectId, children = listOf(paragraph.id, file.id)) val details = mapOf( - page.id to Block.Fields( + page.id to mapOf( Relations.ID to currentObjectId, Relations.NAME to "image-name", Relations.LAYOUT to ObjectType.Layout.IMAGE.code.toDouble() ) ) - ) val blocks = listOf(page, paragraph, file) @@ -5870,7 +5847,7 @@ class DefaultBlockViewRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails(details) ) } diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/EditorViewModelTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/EditorViewModelTest.kt index 8a228f01b8..da9a82de65 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/EditorViewModelTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/EditorViewModelTest.kt @@ -12,7 +12,6 @@ import com.anytypeio.anytype.core_models.NetworkModeConfig import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Payload import com.anytypeio.anytype.core_models.Position -import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.core_models.StubFile import com.anytypeio.anytype.core_models.StubNumbered import com.anytypeio.anytype.core_models.StubObject @@ -24,7 +23,6 @@ import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions import com.anytypeio.anytype.core_models.primitives.SpaceId import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction import com.anytypeio.anytype.core_utils.common.EventWrapper -import com.anytypeio.anytype.core_utils.ext.Mimetype import com.anytypeio.anytype.domain.auth.interactor.ClearLastOpenedObject import com.anytypeio.anytype.domain.base.Either import com.anytypeio.anytype.domain.base.Result @@ -106,6 +104,7 @@ import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate import com.anytypeio.anytype.presentation.common.Action import com.anytypeio.anytype.presentation.common.Delegator import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.BlockDimensions import com.anytypeio.anytype.presentation.editor.editor.Command import com.anytypeio.anytype.presentation.editor.editor.Interactor @@ -2573,7 +2572,7 @@ open class EditorViewModelTest { fileExt = ".pdf" ) - val objectDetails = Block.Fields(targetObject.map) + val objectDetails = targetObject.map val page = listOf( Block( @@ -2594,9 +2593,7 @@ open class EditorViewModelTest { root = root, blocks = page, context = root, - details = Block.Details(mapOf( - targetObjectId to objectDetails - )) + details = mapOf(targetObjectId to objectDetails) ) ) ) @@ -3591,8 +3588,7 @@ open class EditorViewModelTest { private fun givenOpenDocument( document: List = emptyList(), - details: Block.Details = Block.Details(), - relations: List = emptyList(), + details: ObjectViewDetails = ObjectViewDetails.EMPTY, objectRestrictions: List = emptyList() ) { openPage.stub { @@ -3604,7 +3600,7 @@ open class EditorViewModelTest { Event.Command.ShowObject( context = root, root = root, - details = details, + details = details.details, blocks = document, objectRestrictions = objectRestrictions ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorBackspaceDeleteTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorBackspaceDeleteTest.kt index f1808d6a90..662026c0c3 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorBackspaceDeleteTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorBackspaceDeleteTest.kt @@ -1,6 +1,7 @@ package com.anytypeio.anytype.presentation.editor.editor import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.core_models.Relation @@ -19,13 +20,11 @@ import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.StubTitle import com.anytypeio.anytype.core_models.StubToggle import com.anytypeio.anytype.core_models.ext.content -import com.anytypeio.anytype.core_models.primitives.SpaceId import com.anytypeio.anytype.domain.block.interactor.MergeBlocks import com.anytypeio.anytype.domain.block.interactor.UnlinkBlocks import com.anytypeio.anytype.domain.block.interactor.UpdateText import com.anytypeio.anytype.domain.block.interactor.UpdateTextStyle import com.anytypeio.anytype.domain.event.interactor.InterceptEvents -import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate import com.anytypeio.anytype.presentation.editor.EditorViewModel import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.render.parseThemeBackgroundColor @@ -40,8 +39,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.mockito.MockitoAnnotations -import org.mockito.kotlin.doReturn -import org.mockito.kotlin.stub import org.mockito.kotlin.times import org.mockito.kotlin.verifyBlocking import org.mockito.kotlin.verifyNoInteractions @@ -1333,16 +1330,16 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() { format = Relation.Format.NUMBER ) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( + Relations.ID to root, Relations.FEATURED_RELATIONS to listOf( relation.key, Relations.DESCRIPTION ) ) - ) ) ) @@ -1362,7 +1359,7 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() { stubOpenDocument( document = document, details = details, - relations = emptyList() + ) stubUpdateText() stubGetTemplates() @@ -1418,8 +1415,11 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() { val paragraph = StubParagraph() val relation = StubRelationObject(format = Relation.Format.NUMBER) - val details = Block.Details( - mapOf(root to Block.Fields(mapOf(Relations.FEATURED_RELATIONS to listOf(relation.key)))) + val details = ObjectViewDetails( + mapOf(root to mapOf( + Relations.ID to root, + Relations.FEATURED_RELATIONS to listOf(relation.key) + )) ) val header = StubHeader( @@ -1438,7 +1438,7 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() { stubOpenDocument( document = document, details = details, - relations = emptyList() + ) stubUpdateText() stubGetTemplates() @@ -1559,14 +1559,13 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() { format = RelationFormat.NUMBER ) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - Relations.FEATURED_RELATIONS to listOf( - relationKey, - Relations.DESCRIPTION - ) + root to mapOf( + Relations.ID to root, + Relations.FEATURED_RELATIONS to listOf( + relationKey, + Relations.DESCRIPTION ) ) ) @@ -1588,7 +1587,7 @@ class EditorBackspaceDeleteTest : EditorPresentationTestSetup() { stubOpenDocument( document = document, details = details, - relations = emptyList() + ) stubUpdateText() stubInterceptThreadStatus() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorErrorMessageTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorErrorMessageTest.kt index 480e053843..e95eab0bff 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorErrorMessageTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorErrorMessageTest.kt @@ -1,11 +1,11 @@ package com.anytypeio.anytype.presentation.editor.editor import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.StubFile -import com.anytypeio.anytype.core_models.StubObject import com.anytypeio.anytype.domain.base.Either import com.anytypeio.anytype.presentation.util.DefaultCoroutineTestRule import com.anytypeio.anytype.test_utils.MockDataFactory @@ -50,9 +50,9 @@ class EditorErrorMessageTest : EditorPresentationTestSetup() { targetObjectId = fileObjectId ) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - fileObjectId to Block.Fields( + fileObjectId to mapOf( Relations.ID to fileObjectId, Relations.NAME to "file object", @@ -61,7 +61,6 @@ class EditorErrorMessageTest : EditorPresentationTestSetup() { Relations.LAYOUT to ObjectType.Layout.FILE.code.toDouble() ) ) - ) ) val doc = listOf( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorFeaturedRelationsTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorFeaturedRelationsTest.kt index e28665b45f..0ae5f0a467 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorFeaturedRelationsTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorFeaturedRelationsTest.kt @@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation.editor.editor import android.util.Log import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Relation @@ -92,25 +93,25 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, Relations.TYPE to objectTypeId, Relations.FEATURED_RELATIONS to listOf(Relations.TYPE, r3.key) ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( Relations.ID to objectTypeId, Relations.UNIQUE_KEY to objectTypeKey, Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -124,7 +125,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -218,7 +219,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( r1.key to value1, r2.key to value2, @@ -226,17 +227,17 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { Relations.TYPE to objectTypeId, Relations.FEATURED_RELATIONS to listOf(Relations.TYPE) ) - ) - val objectTypeFields = Block.Fields( + + val objectTypeFields = mapOf( Relations.ID to objectTypeId, Relations.UNIQUE_KEY to objectTypeKey, Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -248,7 +249,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -322,7 +323,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( r1.key to value1, r2.key to value2, @@ -330,17 +331,15 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { Relations.TYPE to objectTypeId, Relations.FEATURED_RELATIONS to emptyList() ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( Relations.ID to objectTypeId, Relations.UNIQUE_KEY to objectTypeKey, Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -352,7 +351,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -427,25 +426,26 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, Relations.TYPE to objectTypeId, Relations.FEATURED_RELATIONS to listOf(Relations.TYPE, r3.key) ) - ) - val objectTypeFields = Block.Fields( + + val objectTypeFields = mapOf( Relations.ID to objectTypeId, Relations.UNIQUE_KEY to objectTypeKey, Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -457,7 +457,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -549,25 +549,25 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, Relations.TYPE to objectTypeId, Relations.FEATURED_RELATIONS to listOf(Relations.TYPE, r1.key, r2.key, r3.key) ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( Relations.ID to objectTypeId, Relations.UNIQUE_KEY to objectTypeKey, Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -580,7 +580,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -694,17 +694,17 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, Relations.TYPE to objectTypeId, Relations.FEATURED_RELATIONS to listOf(Relations.TYPE, r3.key) ) - ) - val customDetails = Block.Details(mapOf(root to objectFields)) + val customDetails = ObjectViewDetails(mapOf(root to objectFields)) stubInterceptEvents() stubInterceptThreadStatus() @@ -712,7 +712,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -809,24 +809,23 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, Relations.TYPE to objectTypeId, Relations.FEATURED_RELATIONS to listOf(Relations.TYPE, r3.key) ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( Relations.IS_DELETED to true ) - ) val customDetails = - Block.Details(mapOf(root to objectFields, objectTypeId to objectTypeFields)) + ObjectViewDetails(mapOf(root to objectFields, objectTypeId to objectTypeFields)) stubInterceptEvents() stubInterceptThreadStatus() @@ -834,7 +833,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -922,7 +921,8 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val doc = listOf(page, header, title, block, featuredBlock) - val backlinksRelation = StubRelationObject(uniqueKey = Relations.BACKLINKS, key = Relations.BACKLINKS) + val backlinksRelation = + StubRelationObject(uniqueKey = Relations.BACKLINKS, key = Relations.BACKLINKS) val linksRelation = StubRelationObject(uniqueKey = Relations.LINKS, key = Relations.LINKS) val objBacklinks1 = StubObject("objBacklinks1") @@ -932,31 +932,33 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val objLinksTo1 = StubObject("objLinksTo1") val objLinksTo2 = StubObject("objLinksTo2") - val objectDetails = Block.Details( + val objectDetails = ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - Relations.TYPE to MockDataFactory.randomString(), - Relations.FEATURED_RELATIONS to listOf(Relations.BACKLINKS, Relations.LINKS), - Relations.BACKLINKS to listOf(objBacklinks1.id, objBacklinks2.id, objBacklinks3.id), - Relations.LINKS to listOf(objLinksTo1.id, objLinksTo2.id) - ) - ), - objBacklinks1.id to Block.Fields( - mapOf(Relations.ID to objBacklinks1.id) - ), - objBacklinks2.id to Block.Fields( - mapOf(Relations.ID to objBacklinks2.id) - ), - objBacklinks3.id to Block.Fields( - mapOf(Relations.ID to objBacklinks3.id) - ), - objLinksTo1.id to Block.Fields( - mapOf(Relations.ID to objLinksTo1.id) - ), - objLinksTo2.id to Block.Fields( - mapOf(Relations.ID to objLinksTo2.id) - ) + root to + mapOf( + Relations.ID to root, + Relations.TYPE to MockDataFactory.randomString(), + Relations.FEATURED_RELATIONS to listOf( + Relations.BACKLINKS, + Relations.LINKS + ), + Relations.BACKLINKS to listOf( + objBacklinks1.id, + objBacklinks2.id, + objBacklinks3.id + ), + Relations.LINKS to listOf(objLinksTo1.id, objLinksTo2.id) + ), + objBacklinks1.id to + mapOf(Relations.ID to objBacklinks1.id), + objBacklinks2.id to + mapOf(Relations.ID to objBacklinks2.id), + objBacklinks3.id to + mapOf(Relations.ID to objBacklinks3.id), + objLinksTo1.id to + mapOf(Relations.ID to objLinksTo1.id), + objLinksTo2.id to + mapOf(Relations.ID to objLinksTo2.id) ) ) @@ -971,7 +973,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = objectDetails, - relations = emptyList() + ) val vm = buildViewModel() @@ -1031,89 +1033,94 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { } @Test - fun `should not render backlinks and links as featured relations, when no sub objects are present`() = runTest { + fun `should not render backlinks and links as featured relations, when no sub objects are present`() = + runTest { - val title = MockTypicalDocumentFactory.title - val header = MockTypicalDocumentFactory.header - val block = MockTypicalDocumentFactory.a - val featuredBlock = Block( - id = MockDataFactory.randomUuid(), - fields = Block.Fields.empty(), - children = emptyList(), - content = Block.Content.FeaturedRelations - ) + val title = MockTypicalDocumentFactory.title + val header = MockTypicalDocumentFactory.header + val block = MockTypicalDocumentFactory.a + val featuredBlock = Block( + id = MockDataFactory.randomUuid(), + fields = Block.Fields.empty(), + children = emptyList(), + content = Block.Content.FeaturedRelations + ) - val page = Block( - id = root, - fields = Block.Fields(emptyMap()), - content = Block.Content.Smart, - children = listOf(header.id, featuredBlock.id, block.id) - ) + val page = Block( + id = root, + fields = Block.Fields(emptyMap()), + content = Block.Content.Smart, + children = listOf(header.id, featuredBlock.id, block.id) + ) - val doc = listOf(page, header, title, block, featuredBlock) + val doc = listOf(page, header, title, block, featuredBlock) - val backlinksRelation = StubRelationObject(uniqueKey = Relations.BACKLINKS, key = Relations.BACKLINKS) - val linksRelation = StubRelationObject(uniqueKey = Relations.LINKS, key = Relations.LINKS) + val backlinksRelation = + StubRelationObject(uniqueKey = Relations.BACKLINKS, key = Relations.BACKLINKS) + val linksRelation = + StubRelationObject(uniqueKey = Relations.LINKS, key = Relations.LINKS) - val objectDetails = Block.Details( - mapOf( - root to Block.Fields( - mapOf( - Relations.TYPE to MockDataFactory.randomString(), - Relations.FEATURED_RELATIONS to listOf(Relations.BACKLINKS, Relations.LINKS) + val objectDetails = ObjectViewDetails( + mapOf( + root to + mapOf( + Relations.TYPE to MockDataFactory.randomString(), + Relations.FEATURED_RELATIONS to listOf( + Relations.BACKLINKS, + Relations.LINKS + ) + ) + ) + ) + + storeOfRelations.merge( + listOf(backlinksRelation, linksRelation) + ) + + stubGetNetworkMode() + stubInterceptEvents() + stubInterceptThreadStatus() + stubSearchObjects() + stubOpenDocument( + document = doc, + details = objectDetails, + + ) + + val vm = buildViewModel() + + vm.onStart(id = root, space = defaultSpace) + + advanceUntilIdle() + + val expected = listOf( + BlockView.Title.Basic( + id = title.id, + isFocused = false, + text = title.content().text, + emoji = null + ), + BlockView.Text.Numbered( + isFocused = false, + id = block.id, + marks = emptyList(), + background = block.parseThemeBackgroundColor(), + text = block.content().text, + alignment = block.content().align?.toView(), + number = 1, + decorations = listOf( + BlockView.Decoration( + background = block.parseThemeBackgroundColor() + ) ) ) ) - ) - storeOfRelations.merge( - listOf(backlinksRelation, linksRelation) - ) - - stubGetNetworkMode() - stubInterceptEvents() - stubInterceptThreadStatus() - stubSearchObjects() - stubOpenDocument( - document = doc, - details = objectDetails, - relations = emptyList() - ) - - val vm = buildViewModel() - - vm.onStart(id = root, space = defaultSpace) - - advanceUntilIdle() - - val expected = listOf( - BlockView.Title.Basic( - id = title.id, - isFocused = false, - text = title.content().text, - emoji = null - ), - BlockView.Text.Numbered( - isFocused = false, - id = block.id, - marks = emptyList(), - background = block.parseThemeBackgroundColor(), - text = block.content().text, - alignment = block.content().align?.toView(), - number = 1, - decorations = listOf( - BlockView.Decoration( - background = block.parseThemeBackgroundColor() - ) - ) + assertEquals( + expected = ViewState.Success(expected), + actual = vm.state.value ) - ) - - assertEquals( - expected = ViewState.Success(expected), - actual = vm.state.value - ) - } + } @Test fun `should render globalName relation with proper value from global name`() = runTest { @@ -1141,21 +1148,22 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { key = Relations.IDENTITY, isHidden = true ) - val globalNameRelation = StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) + val globalNameRelation = + StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) val identityValue = MockDataFactory.randomString() val globalNameValue = "name123.any" - val objectDetails = Block.Details( + val objectDetails = ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - Relations.TYPE to MockDataFactory.randomString(), - Relations.FEATURED_RELATIONS to emptyList(), - Relations.IDENTITY to identityValue, - Relations.GLOBAL_NAME to globalNameValue, - Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() - ) - ) + root to + mapOf( + Relations.ID to root, + Relations.TYPE to MockDataFactory.randomString(), + Relations.FEATURED_RELATIONS to emptyList(), + Relations.IDENTITY to identityValue, + Relations.GLOBAL_NAME to globalNameValue, + Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() + ) ) ) @@ -1170,7 +1178,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = objectDetails, - relations = emptyList() + ) val vm = buildViewModel() @@ -1234,21 +1242,22 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { key = Relations.IDENTITY, isHidden = true ) - val globalNameRelation = StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) + val globalNameRelation = + StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) val identityValue = MockDataFactory.randomString() val globalNameValue = "" - val objectDetails = Block.Details( + val objectDetails = ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - Relations.TYPE to MockDataFactory.randomString(), - Relations.FEATURED_RELATIONS to listOf(Relations.IDENTITY), - Relations.IDENTITY to identityValue, - Relations.GLOBAL_NAME to globalNameValue, - Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() - ) - ) + root to + mapOf( + Relations.ID to root, + Relations.TYPE to MockDataFactory.randomString(), + Relations.FEATURED_RELATIONS to listOf(Relations.IDENTITY), + Relations.IDENTITY to identityValue, + Relations.GLOBAL_NAME to globalNameValue, + Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() + ) ) ) @@ -1263,7 +1272,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = objectDetails, - relations = emptyList() + ) val vm = buildViewModel() @@ -1322,23 +1331,24 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val doc = listOf(page, header, title, featuredBlock) - val globalNameRelation = StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) + val globalNameRelation = + StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) val globalNameValue = "name123.any" val someRelationKey = MockDataFactory.randomString() val someRelation = StubRelationObject(uniqueKey = someRelationKey, key = someRelationKey) val someRelationValue = "Some relation Value" - val objectDetails = Block.Details( + val objectDetails = ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - Relations.TYPE to MockDataFactory.randomString(), - Relations.FEATURED_RELATIONS to listOf(someRelationKey), - Relations.GLOBAL_NAME to globalNameValue, - someRelationKey to someRelationValue, - Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() - ) - ) + root to + mapOf( + Relations.ID to root, + Relations.TYPE to MockDataFactory.randomString(), + Relations.FEATURED_RELATIONS to listOf(someRelationKey), + Relations.GLOBAL_NAME to globalNameValue, + someRelationKey to someRelationValue, + Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() + ) ) ) @@ -1353,7 +1363,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = objectDetails, - relations = emptyList() + ) val vm = buildViewModel() @@ -1422,25 +1432,27 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { val doc = listOf(page, header, title, featuredBlock) - val globalNameRelation = StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) + val globalNameRelation = + StubRelationObject(uniqueKey = Relations.GLOBAL_NAME, key = Relations.GLOBAL_NAME) val globalNameValue = "name123.any" - val identityRelation = StubRelationObject(uniqueKey = Relations.IDENTITY, key = Relations.IDENTITY) + val identityRelation = + StubRelationObject(uniqueKey = Relations.IDENTITY, key = Relations.IDENTITY) val identityValue = MockDataFactory.randomString() val someRelationKey = MockDataFactory.randomString() val someRelation = StubRelationObject(uniqueKey = someRelationKey, key = someRelationKey) val someRelationValue = "Some relation Value" - val objectDetails = Block.Details( + val objectDetails = ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - Relations.TYPE to MockDataFactory.randomString(), - Relations.FEATURED_RELATIONS to listOf(someRelationKey), - Relations.IDENTITY to identityValue, - someRelationKey to someRelationValue, - Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() - ) - ) + root to + mapOf( + Relations.ID to root, + Relations.TYPE to MockDataFactory.randomString(), + Relations.FEATURED_RELATIONS to listOf(someRelationKey), + Relations.IDENTITY to identityValue, + someRelationKey to someRelationValue, + Relations.LAYOUT to ObjectType.Layout.PARTICIPANT.code.toDouble() + ) ) ) @@ -1455,7 +1467,7 @@ class EditorFeaturedRelationsTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = objectDetails, - relations = emptyList() + ) val vm = buildViewModel() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorInternalFlagsTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorInternalFlagsTest.kt index 53c4e82632..91aea86582 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorInternalFlagsTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorInternalFlagsTest.kt @@ -2,20 +2,19 @@ package com.anytypeio.anytype.presentation.editor.editor import androidx.arch.core.executor.testing.InstantTaskExecutorRule import app.cash.turbine.test -import com.anytypeio.anytype.core_models.Block +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.InternalFlags import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds -import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.StubHeader import com.anytypeio.anytype.core_models.StubObjectType import com.anytypeio.anytype.core_models.StubSmartBlock import com.anytypeio.anytype.core_models.StubTitle +import com.anytypeio.anytype.core_models.ext.toObject import com.anytypeio.anytype.presentation.editor.EditorViewModel import com.anytypeio.anytype.presentation.util.DefaultCoroutineTestRule import kotlin.test.assertEquals -import kotlin.test.assertIs import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest @@ -50,16 +49,16 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { stubInterceptEvents() stubGetObjectTypes(emptyList()) - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( + Relations.ID to root, Relations.TYPE to ObjectTypeIds.NOTE, Relations.LAYOUT to ObjectType.Layout.NOTE.code.toDouble(), Relations.INTERNAL_FLAGS to listOf(2.0, 0.0, 1.0) ) ) - ) ) stubOpenDocument(document = document, details = detailsList) @@ -71,39 +70,14 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { val storedDetails = orchestrator.stores.details.current() - val objectDetails = ObjectWrapper.Basic(storedDetails.details[root]?.map.orEmpty()) + val objectDetails = storedDetails.details[root].toObject() val expectedFlags = listOf( InternalFlags.ShouldSelectTemplate, InternalFlags.ShouldEmptyDelete, InternalFlags.ShouldSelectType ) - val actualFlags = objectDetails.internalFlags - - assertEquals(expected = expectedFlags, actual = actualFlags) - } - - @Test - fun `should hasn't internal flags on object open`() = runTest { - val title = StubTitle() - val header = StubHeader(children = listOf(title.id)) - val page = StubSmartBlock(id = root, children = listOf(header.id)) - val document = listOf(page, header, title) - stubInterceptEvents() - stubOpenDocument(document = document) - - val vm = buildViewModel() - - vm.onStart(id = root, space = defaultSpace) - - advanceUntilIdle() - - val storedDetails = orchestrator.stores.details.current() - - val objectDetails = ObjectWrapper.Basic(storedDetails.details[root]?.map.orEmpty()) - - val expectedFlags = emptyList() - val actualFlags = objectDetails.internalFlags + val actualFlags = objectDetails?.internalFlags assertEquals(expected = expectedFlags, actual = actualFlags) } @@ -116,9 +90,9 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { val document = listOf(page, header, title) stubInterceptEvents() - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.TYPE to ObjectTypeIds.PAGE, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), @@ -128,7 +102,7 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { InternalFlags.ShouldSelectType.code.toDouble(), ) ) - ) + ) ) stubOpenDocument(document = document, details = detailsList) @@ -160,9 +134,9 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { stubInterceptEvents() stubInterceptThreadStatus() - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.TYPE to ObjectTypeIds.PAGE, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), @@ -171,7 +145,7 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { InternalFlags.ShouldEmptyDelete.code.toDouble() ) ) - ) + ) ) stubOpenDocument(document = document, details = detailsList) @@ -200,9 +174,9 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { val document = listOf(page, header, title) stubInterceptEvents() - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.TYPE to ObjectTypeIds.PAGE, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), @@ -211,7 +185,7 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { InternalFlags.ShouldEmptyDelete.code.toDouble(), ) ) - ) + ) ) stubOpenDocument(document = document, details = detailsList) @@ -244,9 +218,9 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { val document = listOf(page, header, title) stubInterceptEvents() - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( Relations.TYPE to ObjectTypeIds.PAGE, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), @@ -254,7 +228,7 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { InternalFlags.ShouldSelectType.code.toDouble(), ) ) - ) + ) ) stubOpenDocument(document = document, details = detailsList) @@ -287,17 +261,18 @@ class EditorInternalFlagsTest : EditorPresentationTestSetup() { val document = listOf(page, header, title) stubInterceptEvents() - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - root to Block.Fields( + root to mapOf( + Relations.ID to root, Relations.TYPE to ObjectTypeIds.PAGE, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), Relations.INTERNAL_FLAGS to listOf( InternalFlags.ShouldSelectType.code.toDouble(), ) ) - ) + ) ) stubOpenDocument(document = document, details = detailsList) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorLockPageTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorLockPageTest.kt index 8ab5b75044..31431c7d9f 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorLockPageTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorLockPageTest.kt @@ -1,6 +1,7 @@ package com.anytypeio.anytype.presentation.editor.editor import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.Relations @@ -279,16 +280,15 @@ class EditorLockPageTest : EditorPresentationTestSetup() { stubOpenDocument( document = page, - details = Block.Details( + details = ObjectViewDetails( mapOf( - target to Block.Fields( + target to mapOf( Relations.ID to target, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), Relations.SPACE_ID to defaultSpace ) ) - ) ) ) @@ -392,16 +392,16 @@ class EditorLockPageTest : EditorPresentationTestSetup() { stubClosePage() stubOpenDocument( document = page, - details = Block.Details( + details = ObjectViewDetails( mapOf( - target to Block.Fields( + target to mapOf( Relations.ID to target, Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble(), Relations.SPACE_ID to defaultSpace ) ) - ) + ) ) @@ -505,16 +505,16 @@ class EditorLockPageTest : EditorPresentationTestSetup() { stubClosePage() stubOpenDocument( document = page, - details = Block.Details( + details = ObjectViewDetails( mapOf( - bookmarkObjectId to Block.Fields( + bookmarkObjectId to mapOf( + Relations.ID to root, Relations.NAME to bookmarkTitle, Relations.DESCRIPTION to bookmarkDescription, Relations.SOURCE to bookmarkUrl ) ) - ) ) ) @@ -613,9 +613,9 @@ class EditorLockPageTest : EditorPresentationTestSetup() { stubInterceptThreadStatus() stubOpenDocument( document = page, - details = Block.Details( + details = ObjectViewDetails( mapOf( - targetObjectId to Block.Fields( + targetObjectId to mapOf( Relations.ID to targetObjectId, Relations.FILE_MIME_TYPE to mimeType, @@ -623,7 +623,6 @@ class EditorLockPageTest : EditorPresentationTestSetup() { Relations.SIZE_IN_BYTES to fileSize ) ) - ) ) ) @@ -715,9 +714,9 @@ class EditorLockPageTest : EditorPresentationTestSetup() { stubInterceptThreadStatus() stubOpenDocument( document = page, - details = Block.Details( + details = ObjectViewDetails( mapOf( - targetObjectId to Block.Fields( + targetObjectId to mapOf( Relations.ID to targetObjectId, Relations.FILE_MIME_TYPE to mimeType, @@ -725,7 +724,6 @@ class EditorLockPageTest : EditorPresentationTestSetup() { Relations.SIZE_IN_BYTES to fileSize ) ) - ) ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMarkupObjectTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMarkupObjectTest.kt index d89bb0bc0c..901c28fc81 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMarkupObjectTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMarkupObjectTest.kt @@ -80,9 +80,7 @@ class EditorMarkupObjectTest : EditorPresentationTestSetup() { stubInterceptThreadStatus() stubSearchObjects() stubOpenDocument( - document = doc, - details = Block.Details(), - relations = listOf() + document = doc ) stubUpdateText() @@ -228,11 +226,7 @@ class EditorMarkupObjectTest : EditorPresentationTestSetup() { stubInterceptEvents() stubInterceptThreadStatus() stubSearchObjects() - stubOpenDocument( - document = doc, - details = Block.Details(), - relations = listOf() - ) + stubOpenDocument(document = doc) stubUpdateText() val vm = buildViewModel() @@ -396,9 +390,7 @@ class EditorMarkupObjectTest : EditorPresentationTestSetup() { stubInterceptThreadStatus() stubSearchObjects() stubOpenDocument( - document = doc, - details = Block.Details(), - relations = listOf() + document = doc ) stubUpdateText() val vm = buildViewModel() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt index 8edcde6da3..246fe2c653 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMentionTest.kt @@ -3,6 +3,7 @@ package com.anytypeio.anytype.presentation.editor.editor import android.util.Log import androidx.arch.core.executor.testing.InstantTaskExecutorRule import app.cash.turbine.test +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.core_models.ObjectType.Layout @@ -15,7 +16,6 @@ import com.anytypeio.anytype.domain.base.Result import com.anytypeio.anytype.domain.base.Resultat import com.anytypeio.anytype.domain.event.interactor.InterceptEvents import com.anytypeio.anytype.domain.icon.DocumentEmojiIconProvider -import com.anytypeio.anytype.domain.primitives.FieldParserImpl import com.anytypeio.anytype.presentation.editor.EditorViewModel import com.anytypeio.anytype.presentation.editor.editor.control.ControlPanelState import com.anytypeio.anytype.presentation.editor.editor.mention.MentionConst.MENTION_TITLE_EMPTY @@ -163,7 +163,18 @@ class EditorMentionTest : EditorPresentationTestSetup() { val document = listOf(page, header, title, a) - stubOpenDocument(document) + stubOpenDocument( + document, + details = ObjectViewDetails( + details = mapOf( + mentionHash to mapOf( + Relations.ID to mentionHash, + Relations.LAYOUT to Layout.BASIC.code.toDouble(), + Relations.NAME to mentionText + ) + ) + ) + ) stubInterceptEvents() updateText.stub { @@ -203,8 +214,8 @@ class EditorMentionTest : EditorPresentationTestSetup() { coroutineTestRule.advanceUntilIdle() vm.state.test().apply { - assertValue( - ViewState.Success( + assertEquals( + expected = ViewState.Success( blocks = listOf( BlockView.Title.Basic( id = title.id, @@ -226,14 +237,15 @@ class EditorMentionTest : EditorPresentationTestSetup() { from = 5, to = 9 ), + Markup.Mark.Mention.Base( + from = from, + to = from + mentionText.length, + param = mentionHash, + isArchived = false + ), Markup.Mark.Strikethrough( from = 29, to = 33 - ), - Markup.Mark.Mention.Loading( - from = from, - to = from + mentionText.length, - param = mentionHash ) ), indent = 0, @@ -246,7 +258,8 @@ class EditorMentionTest : EditorPresentationTestSetup() { ) ) ) - ) + ), + actual = this.value() ) } @@ -844,14 +857,21 @@ class EditorMentionTest : EditorPresentationTestSetup() { Event.Command.ShowObject( context = root, root = root, - details = Block.Details(), blocks = document, + details = mapOf( + mentionTarget to mapOf( + Relations.ID to mentionTarget, + Relations.NAME to "" + ) + ), objectRestrictions = emptyList() ), Event.Command.Details.Amend( context = root, target = mentionTarget, - details = mapOf(Block.Fields.NAME_KEY to "Foob") + details = mapOf( + Relations.NAME to "Foob" + ) ) ) ) @@ -973,12 +993,11 @@ class EditorMentionTest : EditorPresentationTestSetup() { children = listOf(header.id, a.id) ) - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( Relations.ID to mentionTarget, Relations.NAME to "" ) - ) val detailsAmend = mapOf( mentionTarget to fieldsUpdated1, @@ -1002,7 +1021,7 @@ class EditorMentionTest : EditorPresentationTestSetup() { Event.Command.ShowObject( context = root, root = root, - details = Block.Details(detailsAmend), + details = detailsAmend, blocks = document, objectRestrictions = emptyList() ), @@ -1259,12 +1278,11 @@ class EditorMentionTest : EditorPresentationTestSetup() { children = listOf(header.id, a.id) ) - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( Relations.ID to mentionTarget, Relations.NAME to " " ) - ) val detailsAmend = mapOf( mentionTarget to fieldsUpdated1, @@ -1288,7 +1306,7 @@ class EditorMentionTest : EditorPresentationTestSetup() { Event.Command.ShowObject( context = root, root = root, - details = Block.Details(detailsAmend), + details = detailsAmend, blocks = document, objectRestrictions = emptyList() ), @@ -1418,11 +1436,10 @@ class EditorMentionTest : EditorPresentationTestSetup() { children = listOf(header.id, a.id) ) - val fieldsUpdated1 = Block.Fields( + val fieldsUpdated1 = mapOf( Relations.ID to mentionTarget ) - ) val detailsAmend = mapOf( mentionTarget to fieldsUpdated1, @@ -1446,7 +1463,7 @@ class EditorMentionTest : EditorPresentationTestSetup() { Event.Command.ShowObject( context = root, root = root, - details = Block.Details(detailsAmend), + details = detailsAmend, blocks = document, objectRestrictions = emptyList() ), diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMenuTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMenuTest.kt index 9656de90fd..8af89acfc9 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMenuTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorMenuTest.kt @@ -1,7 +1,7 @@ package com.anytypeio.anytype.presentation.editor.editor import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import com.anytypeio.anytype.core_models.Block +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.primitives.SpaceId @@ -63,15 +63,14 @@ class EditorMenuTest : EditorPresentationTestSetup() { val doc = page(root) - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( Relations.ID to root, Relations.SPACE_ID to defaultSpace ) ) - ) ) stubInterceptEvents() @@ -114,16 +113,15 @@ class EditorMenuTest : EditorPresentationTestSetup() { val space = defaultSpace - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( Relations.SPACE_ID to defaultSpace, Relations.ID to root, Relations.SPACE_ID to space ) ) - ) ) val doc = page(root) @@ -199,18 +197,16 @@ class EditorMenuTest : EditorPresentationTestSetup() { val typeId = MockDataFactory.randomString() - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - Relations.ID to root, - Relations.SPACE_ID to space, - Relations.TYPE to typeId - ) - ), - typeId to Block.Fields( - mapOf(Relations.ID to typeId, Relations.UNIQUE_KEY to ObjectTypeIds.PROFILE) - ) + root to + mapOf( + Relations.ID to root, + Relations.SPACE_ID to space, + Relations.TYPE to typeId + ), + typeId to + mapOf(Relations.ID to typeId, Relations.UNIQUE_KEY to ObjectTypeIds.PROFILE) ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorNoteLayoutTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorNoteLayoutTest.kt index c7329ee5ce..5f0229a8ce 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorNoteLayoutTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorNoteLayoutTest.kt @@ -3,9 +3,9 @@ package com.anytypeio.anytype.presentation.editor.editor import android.util.Log import androidx.arch.core.executor.testing.InstantTaskExecutorRule import app.cash.turbine.test +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType -import com.anytypeio.anytype.core_models.RelationLink import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.StubObjectType import com.anytypeio.anytype.core_models.StubRelationObject @@ -104,8 +104,9 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, @@ -113,17 +114,15 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() { Relations.FEATURED_RELATIONS to listOf(Relations.TYPE), Relations.LAYOUT to ObjectType.Layout.NOTE.code.toDouble() ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( Relations.ID to objectTypeId, Relations.UNIQUE_KEY to objectType.uniqueKey, Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -136,10 +135,7 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() { stubGetDefaultObjectType() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -224,8 +220,9 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, @@ -233,17 +230,15 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() { Relations.FEATURED_RELATIONS to listOf(Relations.TYPE), Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble() ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( Relations.ID to objectTypeId, Relations.UNIQUE_KEY to MockDataFactory.randomString(), Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -256,10 +251,7 @@ class EditorNoteLayoutTest : EditorPresentationTestSetup() { stubGetDefaultObjectType() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorObjectTypeChangeWidgetTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorObjectTypeChangeWidgetTest.kt index db0a64c492..862dedf114 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorObjectTypeChangeWidgetTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorObjectTypeChangeWidgetTest.kt @@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation.editor.editor import android.util.Log import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds @@ -99,16 +100,15 @@ class EditorObjectTypeChangeWidgetTest : EditorPresentationTestSetup() { val doc = listOf(page, header, title, paragraph, featuredBlock) - val objectDetails = Block.Fields( + val objectDetails = mapOf( Relations.SPACE_ID to defaultSpace, Relations.TYPE to ObjectTypeIds.NOTE, Relations.LAYOUT to ObjectType.Layout.NOTE.code.toDouble(), Relations.INTERNAL_FLAGS to listOf(1.0) ) - ) - val detailsList = Block.Details(details = mapOf(root to objectDetails)) + val detailsList = ObjectViewDetails(details = mapOf(root to objectDetails)) stubInterceptEvents() stubInterceptThreadStatus() @@ -169,14 +169,13 @@ class EditorObjectTypeChangeWidgetTest : EditorPresentationTestSetup() { val doc = listOf(page, header, paragraph, featuredBlock) - val objectDetails = Block.Fields( + val objectDetails = mapOf( "type" to ObjectTypeIds.NOTE, "layout" to ObjectType.Layout.NOTE.code.toDouble() ) - ) - val detailsList = Block.Details(details = mapOf(root to objectDetails)) + val detailsList = ObjectViewDetails(details = mapOf(root to objectDetails)) stubInterceptEvents() stubInterceptThreadStatus() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt index ce80493a66..0a7b17f2a1 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorPresentationTestSetup.kt @@ -1,14 +1,13 @@ package com.anytypeio.anytype.presentation.editor.editor import com.anytypeio.anytype.analytics.base.Analytics +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Event import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.NetworkModeConfig 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.RelationLink import com.anytypeio.anytype.core_models.Response import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions import com.anytypeio.anytype.core_models.primitives.SpaceId @@ -26,7 +25,6 @@ import com.anytypeio.anytype.domain.block.interactor.CreateBlock import com.anytypeio.anytype.domain.block.interactor.DuplicateBlock import com.anytypeio.anytype.domain.block.interactor.MergeBlocks import com.anytypeio.anytype.domain.block.interactor.Move -import com.anytypeio.anytype.domain.block.interactor.MoveOld import com.anytypeio.anytype.domain.block.interactor.RemoveLinkMark import com.anytypeio.anytype.domain.block.interactor.ReplaceBlock import com.anytypeio.anytype.domain.block.interactor.SetObjectType @@ -537,10 +535,8 @@ open class EditorPresentationTestSetup { fun stubOpenDocument( document: List = emptyList(), - details: Block.Details = Block.Details(), - relations: List = emptyList(), + details: ObjectViewDetails = ObjectViewDetails.EMPTY, objectRestrictions: List = emptyList(), - relationLinks: List = emptyList(), spaceId: SpaceId = SpaceId(defaultSpace) ) { openPage.stub { @@ -560,7 +556,7 @@ open class EditorPresentationTestSetup { Event.Command.ShowObject( context = root, root = root, - details = details, + details = details.details, blocks = document, objectRestrictions = objectRestrictions ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorRelationBlockTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorRelationBlockTest.kt index 65dcb6fc54..37db21d423 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorRelationBlockTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorRelationBlockTest.kt @@ -1,6 +1,7 @@ package com.anytypeio.anytype.presentation.editor.editor import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Relation import com.anytypeio.anytype.core_models.Relations @@ -62,7 +63,9 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() { val value = "Safe as milk" - val customDetails = Block.Details(mapOf(root to Block.Fields(mapOf(relation.key to value)))) + val customDetails = ObjectViewDetails(mapOf(root to mapOf( + Relations.ID to root, + relation.key to value))) val a = Block( id = MockDataFactory.randomUuid(), @@ -95,7 +98,7 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() { stubOpenDocument( document = document, details = customDetails, - relations = emptyList() + ) val vm = buildViewModel() @@ -190,22 +193,21 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( r1.key to value1, r2.key to value2, r3.key to value3, relationObjectType.key to objectTypeId ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( Relations.NAME to objectTypeName, Relations.DESCRIPTION to objectTypeDescription ) - ) - val customDetails = Block.Details( + + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -217,7 +219,7 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( @@ -311,22 +313,23 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() { val objectTypeName = MockDataFactory.randomString() val objectTypeDescription = MockDataFactory.randomString() - val objectFields = Block.Fields( + val objectFields = mapOf( + Relations.ID to root, r1.key to value1, r2.key to value2, r3.key to value3, relationObjectType.key to objectTypeId ) - ) - val objectTypeFields = Block.Fields( + val objectTypeFields = mapOf( + Relations.ID to objectTypeId, Relations.NAME to objectTypeName, - Relations.DESCRIPTION to objectTypeDescription + Relations.DESCRIPTION to objectTypeDescription, + Relations.UNIQUE_KEY to objectTypeId ) - ) - val customDetails = Block.Details( + val customDetails = ObjectViewDetails( mapOf( root to objectFields, objectTypeId to objectTypeFields @@ -339,7 +342,7 @@ class EditorRelationBlockTest : EditorPresentationTestSetup() { stubOpenDocument( document = doc, details = customDetails, - relations = emptyList() + ) storeOfRelations.merge( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetClicksTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetClicksTest.kt index 9a533f3410..4f55af249e 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetClicksTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetClicksTest.kt @@ -1,9 +1,10 @@ package com.anytypeio.anytype.presentation.editor.editor import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Relation -import com.anytypeio.anytype.core_models.RelationLink +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.presentation.MockObjectTypes import com.anytypeio.anytype.presentation.MockTypicalDocumentFactory @@ -440,16 +441,16 @@ class EditorSlashWidgetClicksTest: EditorPresentationTestSetup() { val value3 = "Captain Beefheart and his Magic Band" val customDetails = - Block.Details( + ObjectViewDetails( mapOf( - root to Block.Fields( + root to mapOf( + Relations.ID to root, relation1.key to value1, relation2.key to value2, relation3.key to value3 ) ) - ) ) val a = Block( @@ -483,13 +484,7 @@ class EditorSlashWidgetClicksTest: EditorPresentationTestSetup() { stubInterceptThreadStatus() stubOpenDocument( document = document, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink( - key = it.key, - format = it.relationFormat - ) - } + details = customDetails ) val vm = buildViewModel() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetFilterTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetFilterTest.kt index bb79911724..e8b3700579 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetFilterTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetFilterTest.kt @@ -2,10 +2,10 @@ package com.anytypeio.anytype.presentation.editor.editor import android.os.Build import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import com.anytypeio.anytype.core_models.Block +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.Relation -import com.anytypeio.anytype.core_models.RelationLink +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.StubObjectType import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.ThemeColor @@ -240,16 +240,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -300,16 +297,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -350,16 +344,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -404,19 +395,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink( - key = it.key, - format = it.relationFormat - ) - } + details = customDetails ) storeOfRelations.merge(objectRelations) @@ -449,8 +434,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type1 = MockObjectTypes.objectTypePage val type2 = MockObjectTypes.objectTypeNote val type3 = MockObjectTypes.objectTypeTask - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubGetObjectTypes(listOf(type1, type2, type3)) @@ -517,16 +502,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -562,16 +544,16 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf( + Relations.ID to root, + r1.key to value1, r2.key to value2, r3.key to value3 + ) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) stubGetObjectTypes(listOf()) @@ -633,16 +615,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -683,16 +662,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -737,16 +713,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -787,16 +760,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -841,16 +811,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -891,16 +858,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -945,16 +909,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -995,16 +956,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1063,16 +1021,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1113,16 +1068,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1181,16 +1133,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1233,16 +1182,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1288,16 +1234,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1340,16 +1283,13 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1393,8 +1333,7 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubOpenDocument( @@ -1440,8 +1379,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubOpenDocument( @@ -1487,8 +1426,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubOpenDocument( @@ -1532,8 +1471,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type1 = MockObjectTypes.objectTypePage val type2 = MockObjectTypes.objectTypeNote val type3 = MockObjectTypes.objectTypeCustom - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubSearchObjects( @@ -1612,16 +1551,20 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf( + Relations.ID to root, + r1.key to value1, r2.key to value2, r3.key to value3 + ) + val customDetails = ObjectViewDetails( + details = mapOf( + root to fields + ) + ) stubInterceptEvents() stubOpenDocument( document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + details = customDetails ) val vm = buildViewModel() @@ -1687,8 +1630,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubOpenDocument( @@ -1740,8 +1683,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubOpenDocument( @@ -1798,8 +1741,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubOpenDocument( @@ -1840,8 +1783,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { val type2 = StubObjectType(name = "Df") val type3 = StubObjectType(name = "LK") val objectTypes = listOf(type1, type2, type3) - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubOpenDocument( @@ -1879,8 +1822,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { // SETUP val doc = MockTypicalDocumentFactory.page(root) val a = MockTypicalDocumentFactory.a - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubSearchObjects() @@ -1917,8 +1860,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { // SETUP val doc = MockTypicalDocumentFactory.page(root) val a = MockTypicalDocumentFactory.a - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubSearchObjects() @@ -1955,8 +1898,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { // SETUP val doc = MockTypicalDocumentFactory.page(root) val a = MockTypicalDocumentFactory.a - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubSearchObjects() @@ -1993,8 +1936,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { // SETUP val doc = MockTypicalDocumentFactory.page(root) val a = MockTypicalDocumentFactory.a - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubSearchObjects() @@ -2031,8 +1974,8 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { // SETUP val doc = MockTypicalDocumentFactory.page(root) val a = MockTypicalDocumentFactory.a - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubSearchObjects() @@ -2069,8 +2012,7 @@ class EditorSlashWidgetFilterTest : EditorPresentationTestSetup() { // SETUP val doc = MockTypicalDocumentFactory.page(root) val a = MockTypicalDocumentFactory.a - val fields = Block.Fields.empty() - val customDetails = Block.Details(mapOf(root to fields)) + val customDetails = ObjectViewDetails.EMPTY stubInterceptEvents() stubSearchObjects() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetRelationsTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetRelationsTest.kt index 4f26dc274d..86a51ff995 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetRelationsTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSlashWidgetRelationsTest.kt @@ -2,10 +2,10 @@ package com.anytypeio.anytype.presentation.editor.editor import android.util.Log import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Position import com.anytypeio.anytype.core_models.Relation -import com.anytypeio.anytype.core_models.RelationLink import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.domain.block.interactor.CreateBlock @@ -76,8 +76,8 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubUpdateText() @@ -188,8 +188,8 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubUpdateText() @@ -311,8 +311,8 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(details = mapOf(root to fields)) stubInterceptEvents() stubInterceptThreadStatus() @@ -410,8 +410,8 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubUpdateText() @@ -503,18 +503,16 @@ class EditorSlashWidgetRelationsTest: EditorPresentationTestSetup() { val value1 = MockDataFactory.randomString() val value2 = MockDataFactory.randomString() val value3 = MockDataFactory.randomString() - val fields = Block.Fields(mapOf(r1.key to value1, r2.key to value2, r3.key to value3)) - val customDetails = Block.Details(mapOf(root to fields)) + val fields = mapOf(r1.key to value1, r2.key to value2, r3.key to value3) + val customDetails = ObjectViewDetails(mapOf(root to fields)) stubInterceptEvents() stubUpdateText() stubCreateBlock(root = root) stubSearchObjects() - stubOpenDocument(document = doc, - details = customDetails, - relationLinks = objectRelations.map { - RelationLink(key = it.key, format = it.relationFormat) - } + stubOpenDocument( + document = doc, + details = customDetails ) val vm = buildViewModel() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSplitTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSplitTest.kt index 02b85b40eb..420b43beeb 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSplitTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorSplitTest.kt @@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation.editor.editor import android.util.Log import androidx.arch.core.executor.testing.InstantTaskExecutorRule +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Position @@ -112,13 +113,11 @@ class EditorSplitTest : EditorPresentationTestSetup() { private fun setupInteractions( doc: List, - details: Block.Details = Block.Details(), - relations: List = listOf() + details: ObjectViewDetails = ObjectViewDetails.EMPTY, ) { stubInterceptEvents() stubOpenDocument( document = doc, - relations = relations, details = details ) stubSplitBlock() @@ -196,15 +195,14 @@ class EditorSplitTest : EditorPresentationTestSetup() { ) fun createDetailsWithFeaturedRelations(root: Id, relation1: String, relation2: String) = - Block.Details( + ObjectViewDetails( mapOf( - root to Block.Fields( - mapOf( - "featuredRelations" to listOf( - relation1, relation2 + root to + mapOf( + "featuredRelations" to listOf( + relation1, relation2 + ) ) - ) - ) ) ) } @@ -613,7 +611,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -954,7 +952,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1018,7 +1016,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1197,7 +1195,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1378,7 +1376,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1452,7 +1450,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1526,7 +1524,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1602,7 +1600,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1675,7 +1673,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) @@ -1748,7 +1746,7 @@ class EditorSplitTest : EditorPresentationTestSetup() { setupInteractions( doc = doc, details = createDetailsWithFeaturedRelations(root, description.id, relation2.key), - relations = listOf() + ) val vm = buildViewModel() vm.onStart(id = root, space = defaultSpace) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTableOfContentsBlockTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTableOfContentsBlockTest.kt index 7c0a19be99..74a8d03f6b 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTableOfContentsBlockTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTableOfContentsBlockTest.kt @@ -225,8 +225,6 @@ class EditorTableOfContentsBlockTest : EditorPresentationTestSetup() { stubSearchObjects() stubOpenDocument( document = doc, - details = Block.Details(), - relations = listOf() ) stubUpdateText() @@ -507,8 +505,6 @@ class EditorTableOfContentsBlockTest : EditorPresentationTestSetup() { stubSearchObjects() stubOpenDocument( document = doc, - details = Block.Details(), - relations = listOf() ) stubUpdateText() @@ -819,9 +815,7 @@ class EditorTableOfContentsBlockTest : EditorPresentationTestSetup() { stubInterceptThreadStatus() stubSearchObjects() stubOpenDocument( - document = doc, - details = Block.Details(), - relations = listOf() + document = doc ) stubUpdateText() @@ -1045,9 +1039,7 @@ class EditorTableOfContentsBlockTest : EditorPresentationTestSetup() { stubInterceptThreadStatus() stubSearchObjects() stubOpenDocument( - document = doc, - details = Block.Details(), - relations = listOf() + document = doc ) stubUpdateText() diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTitleTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTitleTest.kt index 67b1ebbff3..999428f6e0 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTitleTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/EditorTitleTest.kt @@ -313,7 +313,10 @@ class EditorTitleTest : EditorPresentationTestSetup() { listOf(Event.Command.Details.Amend( context = root, target = root, - details = mapOf(Relations.ICON_EMOJI to emoji) + details = mapOf( + Relations.ID to root, + Relations.ICON_EMOJI to emoji + ) )) ) } @@ -430,7 +433,10 @@ class EditorTitleTest : EditorPresentationTestSetup() { listOf(Event.Command.Details.Amend( context = root, target = root, - details = mapOf(Relations.ICON_EMOJI to emoji) + details = mapOf( + Relations.ID to root, + Relations.ICON_EMOJI to emoji + ) )) ) } diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/file_layout/FileLayoutTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/file_layout/FileLayoutTest.kt index 3c1ba7ebfd..b3c222a6e1 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/file_layout/FileLayoutTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/file_layout/FileLayoutTest.kt @@ -11,9 +11,9 @@ import com.anytypeio.anytype.core_models.StubHeader import com.anytypeio.anytype.core_models.StubObject import com.anytypeio.anytype.core_models.StubSmartBlock import com.anytypeio.anytype.core_models.StubTitle -import com.anytypeio.anytype.core_models.ext.content import com.anytypeio.anytype.core_utils.common.EventWrapper import com.anytypeio.anytype.domain.base.Resultat +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.Command import com.anytypeio.anytype.presentation.editor.editor.EditorPresentationTestSetup import com.anytypeio.anytype.presentation.editor.editor.ViewState @@ -21,7 +21,6 @@ import com.anytypeio.anytype.presentation.editor.editor.listener.ListenerType import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.objects.ObjectIcon import com.anytypeio.anytype.presentation.util.DefaultCoroutineTestRule -import com.anytypeio.anytype.presentation.util.TXT import com.anytypeio.anytype.presentation.util.downloader.MiddlewareShareDownloader import com.anytypeio.anytype.test_utils.MockDataFactory import com.jraska.livedata.test @@ -95,9 +94,9 @@ class FileLayoutTest : EditorPresentationTestSetup() { fileExt = fileExt ) - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - fileObject.id to Block.Fields(fileObject.map) + fileObject.id to fileObject.map ) ) @@ -163,9 +162,9 @@ class FileLayoutTest : EditorPresentationTestSetup() { fileExt = fileExt ) - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - fileObject.id to Block.Fields(fileObject.map) + fileObject.id to fileObject.map ) ) @@ -226,9 +225,9 @@ class FileLayoutTest : EditorPresentationTestSetup() { fileExt = "pdf" ) - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - fileObject.id to Block.Fields(fileObject.map) + fileObject.id to fileObject.map ) ) @@ -294,9 +293,9 @@ class FileLayoutTest : EditorPresentationTestSetup() { fileExt = "jpg" ) - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - fileObject.id to Block.Fields(fileObject.map) + fileObject.id to fileObject.map ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/table/TableBlockRendererTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/table/TableBlockRendererTest.kt index f0059acaa5..48dd1647a9 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/table/TableBlockRendererTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/table/TableBlockRendererTest.kt @@ -24,6 +24,7 @@ import com.anytypeio.anytype.domain.objects.DefaultStoreOfObjectTypes import com.anytypeio.anytype.domain.objects.DefaultStoreOfRelations import com.anytypeio.anytype.domain.primitives.FieldParser import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.render.BlockViewRenderer import com.anytypeio.anytype.presentation.editor.render.DefaultBlockViewRenderer @@ -53,7 +54,7 @@ class TableBlockRendererTest { anchor: Id, focus: Editor.Focus, indent: Int, - details: Block.Details + details: ObjectViewDetails ): List = blocks.render( context = root.id, root = root, @@ -181,8 +182,6 @@ class TableBlockRendererTest { */ assertEquals(50, blocks.size) - val details = mapOf(page.id to Block.Fields.empty()) - val map = blocks.asMap() wrapper = BlockViewRenderWrapper( @@ -196,7 +195,7 @@ class TableBlockRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -349,8 +348,6 @@ class TableBlockRendererTest { */ assertEquals(26, blocks.size) - val details = mapOf(page.id to Block.Fields.empty()) - val map = blocks.asMap() wrapper = BlockViewRenderWrapper( @@ -364,7 +361,7 @@ class TableBlockRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } @@ -530,8 +527,6 @@ class TableBlockRendererTest { assertEquals(28, blocks.size) - val details = mapOf(page.id to Block.Fields.empty()) - val map = blocks.asMap() wrapper = BlockViewRenderWrapper( @@ -546,7 +541,7 @@ class TableBlockRendererTest { anchor = page.id, focus = Editor.Focus.empty(), indent = 0, - details = Block.Details(details) + details = ObjectViewDetails.EMPTY ) } diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/template/EditorTemplateTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/template/EditorTemplateTest.kt index 6e8d019fa8..c46166ebb5 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/template/EditorTemplateTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/editor/editor/template/EditorTemplateTest.kt @@ -1,13 +1,13 @@ package com.anytypeio.anytype.presentation.editor.editor.template import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.core_models.StubHeader import com.anytypeio.anytype.core_models.StubSmartBlock import com.anytypeio.anytype.core_models.StubTitle +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.EditorPresentationTestSetup import com.anytypeio.anytype.presentation.util.DefaultCoroutineTestRule import kotlin.test.assertFalse @@ -50,22 +50,21 @@ class EditorTemplateTest: EditorPresentationTestSetup() { val typeObjectId = RandomString.make() - val detailsList = Block.Details( + val detailsList = ObjectViewDetails( details = mapOf( - root to Block.Fields( - mapOf( - Relations.SPACE_ID to defaultSpace, - Relations.TYPE to listOf(typeObjectId), - Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble() - ) - ), - typeObjectId to Block.Fields( - mapOf( - Relations.ID to typeObjectId, - Relations.SPACE_ID to defaultSpace, - Relations.UNIQUE_KEY to ObjectTypeIds.TEMPLATE - ) - ) + root to + mapOf( + Relations.ID to root, + Relations.SPACE_ID to defaultSpace, + Relations.TYPE to listOf(typeObjectId), + Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble() + ), + typeObjectId to + mapOf( + Relations.ID to typeObjectId, + Relations.SPACE_ID to defaultSpace, + Relations.UNIQUE_KEY to ObjectTypeIds.TEMPLATE + ) ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModelTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModelTest.kt index 452465d588..9d2fe316d5 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModelTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModelTest.kt @@ -2272,7 +2272,7 @@ class HomeScreenViewModelTest { Event.Command.Details.Set( context = WIDGET_OBJECT_ID, target = newSourceObject.id, - details = Block.Fields(newSourceObject.map) + details = newSourceObject.map ), Event.Command.LinkGranularChange( context = WIDGET_OBJECT_ID, diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/linking/LinkToObjectOrWebViewModelTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/linking/LinkToObjectOrWebViewModelTest.kt index 542b9f36a5..d0b9facdc2 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/linking/LinkToObjectOrWebViewModelTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/linking/LinkToObjectOrWebViewModelTest.kt @@ -59,8 +59,8 @@ open class LinkToObjectOrWebViewModelTest { @Mock lateinit var gateway: Gateway - var store: Editor.Storage = Editor.Storage() var ctx = "" + var store: Editor.Storage = Editor.Storage() val spaceId = MockDataFactory.randomString() protected val builder: UrlBuilder get() = UrlBuilder(gateway) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/MapperExtensionKtTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/MapperExtensionKtTest.kt index 8531eb33a3..4a89574b38 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/MapperExtensionKtTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/mapper/MapperExtensionKtTest.kt @@ -16,6 +16,7 @@ import com.anytypeio.anytype.domain.objects.GetDateObjectByTimestamp import com.anytypeio.anytype.domain.primitives.FieldParser import com.anytypeio.anytype.domain.primitives.FieldParserImpl import com.anytypeio.anytype.domain.resources.StringResourceProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.test_utils.MockDataFactory import org.junit.Before @@ -67,22 +68,21 @@ class MapperExtensionKtTest { val type = Block.Content.File.Type.FILE val mode = BlockView.Mode.EDIT - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - objectId to Block.Fields( - StubObject( - layout = ObjectType.Layout.BASIC.code.toDouble() - ).map - ), - targetObjectId to Block.Fields( - mapOf( - Relations.ID to targetObjectId, - Relations.NAME to name, - Relations.SIZE_IN_BYTES to 10000.0, - Relations.FILE_MIME_TYPE to mime, - Relations.LAYOUT to ObjectType.Layout.FILE.code.toDouble() - ) - ) + objectId to + StubObject( + id = objectId, + layout = ObjectType.Layout.BASIC.code.toDouble() + ).map, + targetObjectId to + mapOf( + Relations.ID to targetObjectId, + Relations.NAME to name, + Relations.SIZE_IN_BYTES to 10000.0, + Relations.FILE_MIME_TYPE to mime, + Relations.LAYOUT to ObjectType.Layout.FILE.code.toDouble() + ) ) ) @@ -127,7 +127,8 @@ class MapperExtensionKtTest { val expected = BlockView.MediaPlaceholder.File(id = id, indent = indent, isPreviousBlockMedia = false) - val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), + ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -152,7 +153,7 @@ class MapperExtensionKtTest { ).content as Block.Content.File val expected = BlockView.Error.File(id = id, indent = indent, decorations = emptyList(), name = block.name) - val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -175,7 +176,7 @@ class MapperExtensionKtTest { ).content as Block.Content.File val expected = BlockView.Upload.File(id = id, indent = indent) - val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -201,9 +202,9 @@ class MapperExtensionKtTest { targetObjectId = targetObjectId ).content as Block.Content.File - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - targetObjectId to Block.Fields( + targetObjectId to mapOf( Relations.ID to targetObjectId, Relations.NAME to name, @@ -211,7 +212,6 @@ class MapperExtensionKtTest { Relations.FILE_MIME_TYPE to mime, ) ) - ) ) val expected = BlockView.Media.Picture( @@ -252,7 +252,7 @@ class MapperExtensionKtTest { indent = indent, isPreviousBlockMedia = false ) - val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -281,7 +281,7 @@ class MapperExtensionKtTest { name = block.name ) - val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -304,7 +304,7 @@ class MapperExtensionKtTest { ).content as Block.Content.File val expected = BlockView.Upload.Picture(id = id, indent = indent) - val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -330,16 +330,15 @@ class MapperExtensionKtTest { targetObjectId = targetObjectId ).content as Block.Content.File - val details = Block.Details( + val details = ObjectViewDetails( mapOf( - targetObjectId to Block.Fields( - mapOf( - Relations.ID to targetObjectId, - Relations.NAME to name, - Relations.SIZE_IN_BYTES to 10000.0, - Relations.FILE_MIME_TYPE to mime, - ) - ) + targetObjectId to + mapOf( + Relations.ID to targetObjectId, + Relations.NAME to name, + Relations.SIZE_IN_BYTES to 10000.0, + Relations.FILE_MIME_TYPE to mime, + ) ) ) @@ -382,7 +381,7 @@ class MapperExtensionKtTest { decorations = emptyList() ) - val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -410,7 +409,7 @@ class MapperExtensionKtTest { decorations = emptyList() ) - val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toPictureView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -438,7 +437,7 @@ class MapperExtensionKtTest { decorations = emptyList() ) - val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -466,7 +465,7 @@ class MapperExtensionKtTest { decorations = emptyList() ) - val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toFileView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -494,7 +493,7 @@ class MapperExtensionKtTest { isPreviousBlockMedia = false ) - val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -521,7 +520,7 @@ class MapperExtensionKtTest { indent = indent ) - val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -550,7 +549,7 @@ class MapperExtensionKtTest { name = block.name ) - val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), Block.Details(), fieldParser) + val actual = block.toVideoView(objectId, id, urlBuilder, indent, mode, false, ThemeColor.DEFAULT, false, emptyList(), ObjectViewDetails.EMPTY, fieldParser) assertEquals(expected, actual) } @@ -821,7 +820,7 @@ class MapperExtensionKtTest { val result = content.marks( urlBuilder = urlBuilder, - details = Block.Details(mapOf()) + details = ObjectViewDetails.EMPTY ) assertEquals( @@ -860,7 +859,7 @@ class MapperExtensionKtTest { val result = content.marks( urlBuilder = urlBuilder, - details = Block.Details(mapOf()) + details = ObjectViewDetails.EMPTY ) assertEquals( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChoosePreviewLayoutViewModelTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChoosePreviewLayoutViewModelTest.kt index 2b75801f8c..78fc04366d 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChoosePreviewLayoutViewModelTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChoosePreviewLayoutViewModelTest.kt @@ -36,6 +36,8 @@ class ObjectAppearanceChoosePreviewLayoutViewModelTest { private lateinit var viewModel: ObjectAppearanceChoosePreviewLayoutViewModel + val root = MockDataFactory.randomUuid() + private var storage = Editor.Storage() @Before @@ -51,7 +53,6 @@ class ObjectAppearanceChoosePreviewLayoutViewModelTest { @Test fun `should fallback to icon size small when changing from card preview to text`() { - val root = MockDataFactory.randomUuid() val target = MockDataFactory.randomUuid() val block = Block( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImplTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImplTest.kt index a0d06d3f1c..63bd9d349b 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImplTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/menu/ObjectMenuOptionsProviderImplTest.kt @@ -1,30 +1,33 @@ package com.anytypeio.anytype.presentation.objects.menu import app.cash.turbine.test -import com.anytypeio.anytype.core_models.Block.Fields -import com.anytypeio.anytype.core_models.Id 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.core_models.ObjectViewDetails +import kotlin.test.assertEquals import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.runTest import org.junit.Test -import org.mockito.kotlin.mock -import kotlin.test.assertEquals @ExperimentalCoroutinesApi class ObjectMenuOptionsProviderImplTest { private val objectId: String = "objectId" - private val details = MutableStateFlow>(mapOf()) + private val details = MutableStateFlow(ObjectViewDetails.EMPTY) private val restrictions = MutableStateFlow>(emptyList()) - private val provider = ObjectMenuOptionsProviderImpl(details, restrictions, mock()) + private val provider = ObjectMenuOptionsProviderImpl(details, restrictions) @Test fun `when layout note - options are layout, relations, history`() { - details.value = mapOf( - objectId to Fields(map = mapOf(Relations.LAYOUT to ObjectType.Layout.NOTE.code.toDouble())) + details.value = ObjectViewDetails( + mapOf( + objectId to mapOf( + Relations.ID to objectId, + Relations.LAYOUT to ObjectType.Layout.NOTE.code.toDouble() + ) + ) ) val expected = ObjectMenuOptionsProvider.Options( hasIcon = false, @@ -42,8 +45,13 @@ class ObjectMenuOptionsProviderImplTest { @Test fun `when layout task - options are layout, relations, history`() { - details.value = mapOf( - objectId to Fields(map = mapOf(Relations.LAYOUT to ObjectType.Layout.TODO.code.toDouble())) + details.value = ObjectViewDetails( + mapOf( + objectId to mapOf( + Relations.ID to objectId, + Relations.LAYOUT to ObjectType.Layout.TODO.code.toDouble() + ) + ) ) val expected = ObjectMenuOptionsProvider.Options( hasIcon = false, @@ -61,8 +69,13 @@ class ObjectMenuOptionsProviderImplTest { @Test fun `when layout basic - all options are visible`() { - details.value = mapOf( - objectId to Fields(map = mapOf(Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble())) + details.value = ObjectViewDetails( + mapOf( + objectId to mapOf( + Relations.ID to objectId, + Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble() + ) + ) ) assertOptions( @@ -73,8 +86,12 @@ class ObjectMenuOptionsProviderImplTest { @Test fun `when layout null - all options are not visible`() { - details.value = mapOf( - objectId to Fields(map = mapOf(Relations.LAYOUT to null)) + details.value = ObjectViewDetails( + mapOf( + objectId to mapOf( + Relations.ID to objectId + ) + ) ) assertOptions( @@ -84,8 +101,13 @@ class ObjectMenuOptionsProviderImplTest { @Test fun `when restricts layout_change - layout options is invisible`() { - details.value = mapOf( - objectId to Fields(map = mapOf(Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble())) + details.value = ObjectViewDetails( + mapOf( + objectId to mapOf( + Relations.ID to objectId, + Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble() + ) + ) ) restrictions.value = listOf(ObjectRestriction.LAYOUT_CHANGE) @@ -99,8 +121,13 @@ class ObjectMenuOptionsProviderImplTest { @Test fun `when object is Locked - show only relations`() { - details.value = mapOf( - objectId to Fields(map = mapOf(Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble())) + details.value = ObjectViewDetails( + mapOf( + objectId to mapOf( + Relations.ID to objectId, + Relations.LAYOUT to ObjectType.Layout.BASIC.code.toDouble() + ) + ) ) assertOptions( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/MockObjectSetFactory.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/MockObjectSetFactory.kt index ccb77e675c..b8ed4255df 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/MockObjectSetFactory.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/MockObjectSetFactory.kt @@ -1,5 +1,6 @@ package com.anytypeio.anytype.presentation.sets +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.RelationLink @@ -85,6 +86,10 @@ object MockObjectSetFactory { val blocks = listOf(title, dataView) - return ObjectState.DataView.Set(root = root, blocks = blocks) + return ObjectState.DataView.Set( + root = root, + blocks = blocks, + details = ObjectViewDetails.EMPTY + ) } } \ No newline at end of file diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/ObjectSetReducerTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/ObjectSetReducerTest.kt index 573771bf92..0b6ef05552 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/ObjectSetReducerTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/ObjectSetReducerTest.kt @@ -13,6 +13,7 @@ import com.anytypeio.anytype.core_models.StubFilter import com.anytypeio.anytype.core_models.StubRelationLink import com.anytypeio.anytype.core_models.StubSort import com.anytypeio.anytype.core_models.StubTitle +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.state.DefaultObjectStateReducer import com.anytypeio.anytype.presentation.sets.state.ObjectState import com.anytypeio.anytype.presentation.sets.state.ObjectStateReducer @@ -120,7 +121,7 @@ class ObjectSetReducerTest { context = context, root = context, blocks = blocks, - details = details + details = details.details ) val event = Event.Command.DataView.SetView( @@ -188,7 +189,7 @@ class ObjectSetReducerTest { val expected = ObjectState.DataView.Set( root = context, blocks = listOf(title, expectedDataView), - details = details.details + details = details ) assertEquals(expected, stateSetView) @@ -261,7 +262,7 @@ class ObjectSetReducerTest { context = context, root = context, blocks = blocks, - details = details + details = details.details ) val event = Event.Command.DataView.SetView( @@ -327,368 +328,376 @@ class ObjectSetReducerTest { val expected = ObjectState.DataView.Set( root = context, blocks = listOf(title, expectedDataView), - details = details.details + details = details ) assertEquals(expected, stateSetView) } @Test - fun `when getting add, move, update, remove sorts events, should proper update viewer`() = runTest { + fun `when getting add, move, update, remove sorts events, should proper update viewer`() = + runTest { - val title = StubTitle() + val title = StubTitle() - val relationKey1 = MockDataFactory.randomUuid() - val relationKey2 = MockDataFactory.randomUuid() - val relationKey3 = MockDataFactory.randomUuid() - val relationKey4 = MockDataFactory.randomUuid() - val relationKey5 = MockDataFactory.randomUuid() - val sortId1 = MockDataFactory.randomUuid() - val sortId2 = MockDataFactory.randomUuid() - val sortId3 = MockDataFactory.randomUuid() - val sortId4 = MockDataFactory.randomUuid() - val sortId5 = MockDataFactory.randomUuid() - val sort1 = StubSort(relationKey = relationKey1, id = sortId1) - val sort2 = StubSort(relationKey = relationKey2, id = sortId2) - val sort3 = StubSort(relationKey = relationKey3, id = sortId3) - val sort4 = StubSort(relationKey = relationKey4, id = sortId4) - val sort5 = StubSort(relationKey = relationKey5, id = sortId5) + val relationKey1 = MockDataFactory.randomUuid() + val relationKey2 = MockDataFactory.randomUuid() + val relationKey3 = MockDataFactory.randomUuid() + val relationKey4 = MockDataFactory.randomUuid() + val relationKey5 = MockDataFactory.randomUuid() + val sortId1 = MockDataFactory.randomUuid() + val sortId2 = MockDataFactory.randomUuid() + val sortId3 = MockDataFactory.randomUuid() + val sortId4 = MockDataFactory.randomUuid() + val sortId5 = MockDataFactory.randomUuid() + val sort1 = StubSort(relationKey = relationKey1, id = sortId1) + val sort2 = StubSort(relationKey = relationKey2, id = sortId2) + val sort3 = StubSort(relationKey = relationKey3, id = sortId3) + val sort4 = StubSort(relationKey = relationKey4, id = sortId4) + val sort5 = StubSort(relationKey = relationKey5, id = sortId5) - val viewer1 = StubDataViewView( - type = Block.Content.DataView.Viewer.Type.BOARD, - sorts = listOf(sort1, sort2, sort3, sort4) - ) - val viewer2 = StubDataViewView( - type = Block.Content.DataView.Viewer.Type.GRID, - sorts = listOf(sort1) - ) - val dataView = StubDataView( - id = MockDataFactory.randomUuid(), - views = listOf(viewer1, viewer2) - ) - - val blocks = listOf(title, dataView) - - // TESTING - - val event = Event.Command.DataView.UpdateView( - context = context, - block = dataView.id, - viewerId = viewer1.id, - sortUpdates = listOf( - Event.Command.DataView.UpdateView.DVSortUpdate.Move( - afterId = sortId3, - ids = listOf(sortId1, sortId2) - ), - Event.Command.DataView.UpdateView.DVSortUpdate.Add( - afterId = sortId3, - sorts = listOf(sort5) - ), - Event.Command.DataView.UpdateView.DVSortUpdate.Update( - id = sortId2, - sort = DVSort(sort2.id, relationKey2, Block.Content.DataView.Sort.Type.DESC, relationFormat = RelationFormat.LONG_TEXT) - ), - Event.Command.DataView.UpdateView.DVSortUpdate.Remove( - ids = listOf(sortId1) - ) - ), - filterUpdates = listOf(), - relationUpdates = listOf(), - fields = null - ) - - val eventOpen = Event.Command.ShowObject( - context = context, root = context, blocks = blocks, details = details - ) - - val stateOpen = reducer.reduce( - state = ObjectState.Init, events = listOf(eventOpen) - ).state - - val stateUpdateView = reducer.reduce( - state = stateOpen, events = listOf(event) - ).state - - val expectedSorts = listOf( - DVSort( - id = sortId3, - relationKey = relationKey3, - type = Block.Content.DataView.Sort.Type.ASC, - relationFormat = RelationFormat.LONG_TEXT - ), - DVSort( - id = sortId5, - relationKey = relationKey5, - type = Block.Content.DataView.Sort.Type.ASC, - relationFormat = RelationFormat.LONG_TEXT - ), - DVSort( - id = sortId2, - relationKey = relationKey2, - type = Block.Content.DataView.Sort.Type.DESC, - relationFormat = RelationFormat.LONG_TEXT - ), - DVSort( - id = sortId4, - relationKey = relationKey4, - type = Block.Content.DataView.Sort.Type.ASC, - relationFormat = RelationFormat.LONG_TEXT + val viewer1 = StubDataViewView( + type = Block.Content.DataView.Viewer.Type.BOARD, + sorts = listOf(sort1, sort2, sort3, sort4) ) - ) - val expectedDataView = Block( - id = dataView.id, - content = Block.Content.DataView( - viewers = listOf( - Block.Content.DataView.Viewer( - id = viewer1.id, - name = viewer1.name, - type = viewer1.type, - viewerRelations = viewer1.viewerRelations, - sorts = expectedSorts, - filters = viewer1.filters + val viewer2 = StubDataViewView( + type = Block.Content.DataView.Viewer.Type.GRID, + sorts = listOf(sort1) + ) + val dataView = StubDataView( + id = MockDataFactory.randomUuid(), + views = listOf(viewer1, viewer2) + ) + + val blocks = listOf(title, dataView) + + // TESTING + + val event = Event.Command.DataView.UpdateView( + context = context, + block = dataView.id, + viewerId = viewer1.id, + sortUpdates = listOf( + Event.Command.DataView.UpdateView.DVSortUpdate.Move( + afterId = sortId3, + ids = listOf(sortId1, sortId2) ), - Block.Content.DataView.Viewer( - id = viewer2.id, - name = viewer2.name, - type = Block.Content.DataView.Viewer.Type.GRID, - viewerRelations = viewer2.viewerRelations, - sorts = listOf(sort1), - filters = listOf() + Event.Command.DataView.UpdateView.DVSortUpdate.Add( + afterId = sortId3, + sorts = listOf(sort5) + ), + Event.Command.DataView.UpdateView.DVSortUpdate.Update( + id = sortId2, + sort = DVSort( + sort2.id, + relationKey2, + Block.Content.DataView.Sort.Type.DESC, + relationFormat = RelationFormat.LONG_TEXT + ) + ), + Event.Command.DataView.UpdateView.DVSortUpdate.Remove( + ids = listOf(sortId1) ) ), - targetObjectId = (dataView.content as Block.Content.DataView).targetObjectId - ), - fields = Block.Fields.empty(), - children = listOf() - ) + filterUpdates = listOf(), + relationUpdates = listOf(), + fields = null + ) - val expected = ObjectState.DataView.Set( - root = context, - blocks = listOf(title, expectedDataView), - details = details.details - ) + val eventOpen = Event.Command.ShowObject( + context = context, root = context, blocks = blocks, details = details.details + ) - assertEquals(expected, stateUpdateView) - } + val stateOpen = reducer.reduce( + state = ObjectState.Init, events = listOf(eventOpen) + ).state + + val stateUpdateView = reducer.reduce( + state = stateOpen, events = listOf(event) + ).state + + val expectedSorts = listOf( + DVSort( + id = sortId3, + relationKey = relationKey3, + type = Block.Content.DataView.Sort.Type.ASC, + relationFormat = RelationFormat.LONG_TEXT + ), + DVSort( + id = sortId5, + relationKey = relationKey5, + type = Block.Content.DataView.Sort.Type.ASC, + relationFormat = RelationFormat.LONG_TEXT + ), + DVSort( + id = sortId2, + relationKey = relationKey2, + type = Block.Content.DataView.Sort.Type.DESC, + relationFormat = RelationFormat.LONG_TEXT + ), + DVSort( + id = sortId4, + relationKey = relationKey4, + type = Block.Content.DataView.Sort.Type.ASC, + relationFormat = RelationFormat.LONG_TEXT + ) + ) + val expectedDataView = Block( + id = dataView.id, + content = Block.Content.DataView( + viewers = listOf( + Block.Content.DataView.Viewer( + id = viewer1.id, + name = viewer1.name, + type = viewer1.type, + viewerRelations = viewer1.viewerRelations, + sorts = expectedSorts, + filters = viewer1.filters + ), + Block.Content.DataView.Viewer( + id = viewer2.id, + name = viewer2.name, + type = Block.Content.DataView.Viewer.Type.GRID, + viewerRelations = viewer2.viewerRelations, + sorts = listOf(sort1), + filters = listOf() + ) + ), + targetObjectId = (dataView.content as Block.Content.DataView).targetObjectId + ), + fields = Block.Fields.empty(), + children = listOf() + ) + + val expected = ObjectState.DataView.Set( + root = context, + blocks = listOf(title, expectedDataView), + details = details + ) + + assertEquals(expected, stateUpdateView) + } @Test - fun `when getting add, move, update, remove filters events, should proper update viewer`() = runTest { + fun `when getting add, move, update, remove filters events, should proper update viewer`() = + runTest { - val title = StubTitle() + val title = StubTitle() - val filterId1 = MockDataFactory.randomUuid() - val filterId2 = MockDataFactory.randomUuid() - val filterId3 = MockDataFactory.randomUuid() - val filterId4 = MockDataFactory.randomUuid() - val filterId5 = MockDataFactory.randomUuid() - val relationKey1 = MockDataFactory.randomUuid() - val relationKey2 = MockDataFactory.randomUuid() - val relationKey3 = MockDataFactory.randomUuid() - val relationKey4 = MockDataFactory.randomUuid() - val relationKey5 = MockDataFactory.randomUuid() - val filter1 = StubFilter(relationKey = relationKey1, id = filterId1) - val filter2 = StubFilter(relationKey = relationKey2, id = filterId2) - val filter3 = StubFilter(relationKey = relationKey3, id = filterId3) - val filter4 = StubFilter(relationKey = relationKey4, id = filterId4) - val filter5 = StubFilter(relationKey = relationKey5, id = filterId5) + val filterId1 = MockDataFactory.randomUuid() + val filterId2 = MockDataFactory.randomUuid() + val filterId3 = MockDataFactory.randomUuid() + val filterId4 = MockDataFactory.randomUuid() + val filterId5 = MockDataFactory.randomUuid() + val relationKey1 = MockDataFactory.randomUuid() + val relationKey2 = MockDataFactory.randomUuid() + val relationKey3 = MockDataFactory.randomUuid() + val relationKey4 = MockDataFactory.randomUuid() + val relationKey5 = MockDataFactory.randomUuid() + val filter1 = StubFilter(relationKey = relationKey1, id = filterId1) + val filter2 = StubFilter(relationKey = relationKey2, id = filterId2) + val filter3 = StubFilter(relationKey = relationKey3, id = filterId3) + val filter4 = StubFilter(relationKey = relationKey4, id = filterId4) + val filter5 = StubFilter(relationKey = relationKey5, id = filterId5) - val viewer1 = StubDataViewView( - type = Block.Content.DataView.Viewer.Type.BOARD, - filters = listOf(filter1, filter2, filter3, filter4) - ) - val dataView = StubDataView( - id = MockDataFactory.randomUuid(), - views = listOf(viewer1) - ) + val viewer1 = StubDataViewView( + type = Block.Content.DataView.Viewer.Type.BOARD, + filters = listOf(filter1, filter2, filter3, filter4) + ) + val dataView = StubDataView( + id = MockDataFactory.randomUuid(), + views = listOf(viewer1) + ) - val blocks = listOf(title, dataView) + val blocks = listOf(title, dataView) - // TESTING + // TESTING - val filter2Value = MockDataFactory.randomString() - val event = Event.Command.DataView.UpdateView( - context = context, - block = dataView.id, - viewerId = viewer1.id, - sortUpdates = listOf(), - filterUpdates = listOf( - Event.Command.DataView.UpdateView.DVFilterUpdate.Move( - afterId = filterId3, - ids = listOf(filterId1, filterId2) - ), - Event.Command.DataView.UpdateView.DVFilterUpdate.Add( - afterId = filterId3, - filters = listOf(filter5) - ), - Event.Command.DataView.UpdateView.DVFilterUpdate.Update( - id = filterId2, - filter = filter2.copy( - value = filter2Value + val filter2Value = MockDataFactory.randomString() + val event = Event.Command.DataView.UpdateView( + context = context, + block = dataView.id, + viewerId = viewer1.id, + sortUpdates = listOf(), + filterUpdates = listOf( + Event.Command.DataView.UpdateView.DVFilterUpdate.Move( + afterId = filterId3, + ids = listOf(filterId1, filterId2) + ), + Event.Command.DataView.UpdateView.DVFilterUpdate.Add( + afterId = filterId3, + filters = listOf(filter5) + ), + Event.Command.DataView.UpdateView.DVFilterUpdate.Update( + id = filterId2, + filter = filter2.copy( + value = filter2Value + ) + ), + Event.Command.DataView.UpdateView.DVFilterUpdate.Remove( + ids = listOf(filterId1) ) ), - Event.Command.DataView.UpdateView.DVFilterUpdate.Remove( - ids = listOf(filterId1) - ) - ), - relationUpdates = listOf(), - fields = null - ) + relationUpdates = listOf(), + fields = null + ) - val eventOpen = Event.Command.ShowObject( - context = context, root = context, blocks = blocks, details = details - ) + val eventOpen = Event.Command.ShowObject( + context = context, root = context, blocks = blocks, details = details.details + ) - val stateOpen = reducer.reduce( - state = ObjectState.Init, events = listOf(eventOpen) - ).state + val stateOpen = reducer.reduce( + state = ObjectState.Init, events = listOf(eventOpen) + ).state - val stateUpdateView = reducer.reduce( - state = stateOpen, events = listOf(event) - ).state + val stateUpdateView = reducer.reduce( + state = stateOpen, events = listOf(event) + ).state - val expectedFilters = listOf( - filter3, - filter5, - filter2.copy( - value = filter2Value - ), - filter4 - ) - - val expectedDataView = Block( - id = dataView.id, - content = Block.Content.DataView( - viewers = listOf( - Block.Content.DataView.Viewer( - id = viewer1.id, - name = viewer1.name, - type = viewer1.type, - viewerRelations = viewer1.viewerRelations, - sorts = viewer1.sorts, - filters = expectedFilters - ) + val expectedFilters = listOf( + filter3, + filter5, + filter2.copy( + value = filter2Value ), - targetObjectId = (dataView.content as Block.Content.DataView).targetObjectId - ), - fields = Block.Fields.empty(), - children = listOf() - ) + filter4 + ) - val expected = ObjectState.DataView.Set( - root = context, - blocks = listOf(title, expectedDataView), - details = details.details - ) + val expectedDataView = Block( + id = dataView.id, + content = Block.Content.DataView( + viewers = listOf( + Block.Content.DataView.Viewer( + id = viewer1.id, + name = viewer1.name, + type = viewer1.type, + viewerRelations = viewer1.viewerRelations, + sorts = viewer1.sorts, + filters = expectedFilters + ) + ), + targetObjectId = (dataView.content as Block.Content.DataView).targetObjectId + ), + fields = Block.Fields.empty(), + children = listOf() + ) - assertEquals(expected, stateUpdateView) - } + val expected = ObjectState.DataView.Set( + root = context, + blocks = listOf(title, expectedDataView), + details = details + ) + + assertEquals(expected, stateUpdateView) + } @Test - fun `when getting add, move, update, remove relations events, should proper update viewer`() = runTest { + fun `when getting add, move, update, remove relations events, should proper update viewer`() = + runTest { - val title = StubTitle() + val title = StubTitle() - val relationKey1 = MockDataFactory.randomUuid() - val relationKey2 = MockDataFactory.randomUuid() - val relationKey3 = MockDataFactory.randomUuid() - val relationKey4 = MockDataFactory.randomUuid() - val relationKey5 = MockDataFactory.randomUuid() - val relation1 = StubDataViewViewRelation(key = relationKey1) - val relation2 = StubDataViewViewRelation(key = relationKey2) - val relation3 = StubDataViewViewRelation(key = relationKey3) - val relation4 = StubDataViewViewRelation(key = relationKey4) - val relation5 = StubDataViewViewRelation(key = relationKey5) + val relationKey1 = MockDataFactory.randomUuid() + val relationKey2 = MockDataFactory.randomUuid() + val relationKey3 = MockDataFactory.randomUuid() + val relationKey4 = MockDataFactory.randomUuid() + val relationKey5 = MockDataFactory.randomUuid() + val relation1 = StubDataViewViewRelation(key = relationKey1) + val relation2 = StubDataViewViewRelation(key = relationKey2) + val relation3 = StubDataViewViewRelation(key = relationKey3) + val relation4 = StubDataViewViewRelation(key = relationKey4) + val relation5 = StubDataViewViewRelation(key = relationKey5) - val viewer1 = StubDataViewView( - type = Block.Content.DataView.Viewer.Type.BOARD, - viewerRelations = listOf(relation1, relation2, relation3, relation4) - ) - val dataView = StubDataView( - id = MockDataFactory.randomUuid(), - views = listOf(viewer1) - ) + val viewer1 = StubDataViewView( + type = Block.Content.DataView.Viewer.Type.BOARD, + viewerRelations = listOf(relation1, relation2, relation3, relation4) + ) + val dataView = StubDataView( + id = MockDataFactory.randomUuid(), + views = listOf(viewer1) + ) - val blocks = listOf(title, dataView) + val blocks = listOf(title, dataView) - // TESTING + // TESTING - val relation2IsVisible = !relation2.isVisible - val event = Event.Command.DataView.UpdateView( - context = context, - block = dataView.id, - viewerId = viewer1.id, - sortUpdates = listOf(), - filterUpdates = listOf(), - relationUpdates = listOf( - Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Move( - afterId = relationKey3, - ids = listOf(relationKey1, relationKey2) - ), - Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Add( - afterId = relationKey3, - relations = listOf(relation5) - ), - Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Update( - id = relationKey2, - relation = relation2.copy( - isVisible = relation2IsVisible + val relation2IsVisible = !relation2.isVisible + val event = Event.Command.DataView.UpdateView( + context = context, + block = dataView.id, + viewerId = viewer1.id, + sortUpdates = listOf(), + filterUpdates = listOf(), + relationUpdates = listOf( + Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Move( + afterId = relationKey3, + ids = listOf(relationKey1, relationKey2) + ), + Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Add( + afterId = relationKey3, + relations = listOf(relation5) + ), + Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Update( + id = relationKey2, + relation = relation2.copy( + isVisible = relation2IsVisible + ) + ), + Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Remove( + ids = listOf(relationKey1) ) ), - Event.Command.DataView.UpdateView.DVViewerRelationUpdate.Remove( - ids = listOf(relationKey1) - ) - ), - fields = null - ) + fields = null + ) - val eventOpen = Event.Command.ShowObject( - context = context, root = context, blocks = blocks, details = details - ) + val eventOpen = Event.Command.ShowObject( + context = context, root = context, blocks = blocks, details = details.details + ) - val stateOpen = reducer.reduce( - state = ObjectState.Init, events = listOf(eventOpen) - ).state + val stateOpen = reducer.reduce( + state = ObjectState.Init, events = listOf(eventOpen) + ).state - val stateUpdateView = reducer.reduce( - state = stateOpen, events = listOf(event) - ).state + val stateUpdateView = reducer.reduce( + state = stateOpen, events = listOf(event) + ).state - val expectedRelations = listOf( - relation3, - relation5, - relation2.copy( - isVisible = relation2IsVisible - ), - relation4 - ) - - val expectedDataView = Block( - id = dataView.id, - content = Block.Content.DataView( - viewers = listOf( - Block.Content.DataView.Viewer( - id = viewer1.id, - name = viewer1.name, - type = viewer1.type, - viewerRelations = expectedRelations, - sorts = viewer1.sorts, - filters = viewer1.filters - ) + val expectedRelations = listOf( + relation3, + relation5, + relation2.copy( + isVisible = relation2IsVisible ), - targetObjectId = (dataView.content as Block.Content.DataView).targetObjectId - ), - fields = Block.Fields.empty(), - children = listOf() - ) + relation4 + ) - val expected = ObjectState.DataView.Set( - root = context, - blocks = listOf(title, expectedDataView), - details = details.details - ) + val expectedDataView = Block( + id = dataView.id, + content = Block.Content.DataView( + viewers = listOf( + Block.Content.DataView.Viewer( + id = viewer1.id, + name = viewer1.name, + type = viewer1.type, + viewerRelations = expectedRelations, + sorts = viewer1.sorts, + filters = viewer1.filters + ) + ), + targetObjectId = (dataView.content as Block.Content.DataView).targetObjectId + ), + fields = Block.Fields.empty(), + children = listOf() + ) - assertEquals(expected, stateUpdateView) - } + val expected = ObjectState.DataView.Set( + root = context, + blocks = listOf(title, expectedDataView), + details = details + ) + + assertEquals(expected, stateUpdateView) + } @Test fun `should update fields for viewer, with new fields`() = runTest { @@ -748,7 +757,7 @@ class ObjectSetReducerTest { ) val eventOpen = Event.Command.ShowObject( - context = context, root = context, blocks = blocks, details = details + context = context, root = context, blocks = blocks, details = details.details ) val stateOpen = reducer.reduce( @@ -784,7 +793,7 @@ class ObjectSetReducerTest { val expected = ObjectState.DataView.Set( root = context, blocks = listOf(title, expectedDataView), - details = details.details + details = details ) assertEquals(expected, stateUpdateView) @@ -828,7 +837,7 @@ class ObjectSetReducerTest { ) val eventOpen = Event.Command.ShowObject( - context = context, root = context, blocks = blocks, details = details + context = context, root = context, blocks = blocks, details = details.details ) val stateOpen = reducer.reduce( @@ -863,17 +872,15 @@ class ObjectSetReducerTest { val expected = ObjectState.DataView.Set( root = context, blocks = listOf(title, expectedDataView), - details = details.details + details = details ) assertEquals(expected, stateDeleteRelation) } - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - context to Block.Fields( - mapOf(Relations.ID to context, Relations.LAYOUT to 3.0) - ) + context to mapOf(Relations.ID to context, Relations.LAYOUT to 3.0) ) ) } \ No newline at end of file diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetDataViewObjectCreateTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetDataViewObjectCreateTest.kt index d5ea187859..ef64a7aeac 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetDataViewObjectCreateTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetDataViewObjectCreateTest.kt @@ -1,7 +1,6 @@ package com.anytypeio.anytype.presentation.sets.main import app.cash.turbine.test -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.Relations @@ -13,7 +12,7 @@ import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewObject import com.anytypeio.anytype.presentation.collections.MockCollection import com.anytypeio.anytype.presentation.collections.MockSet import com.anytypeio.anytype.core_models.SupportedLayouts -import com.anytypeio.anytype.domain.primitives.FieldParserImpl +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.DataViewViewState import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel import kotlin.test.assertFalse @@ -165,24 +164,22 @@ class ObjectSetDataViewObjectCreateTest : ObjectSetViewModelTestSetup() { val skipLayouts = SupportedLayouts.fileLayouts + SupportedLayouts.systemLayouts val recommendedLayout = skipLayouts.random() - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields( - mapOf( - Relations.ID to root, - Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), - Relations.SET_OF to listOf(mockObjectSet.setOf) - ) - ), - mockObjectSet.setOf to Block.Fields( - map = mapOf( - Relations.ID to mockObjectSet.setOf, - Relations.UNIQUE_KEY to setOfKey, - Relations.TYPE to ObjectTypeIds.OBJECT_TYPE, - Relations.RECOMMENDED_LAYOUT to recommendedLayout.code.toDouble(), - Relations.LAYOUT to ObjectType.Layout.OBJECT_TYPE.code.toDouble(), - ) - ) + root to + mapOf( + Relations.ID to root, + Relations.LAYOUT to ObjectType.Layout.SET.code.toDouble(), + Relations.SET_OF to listOf(mockObjectSet.setOf) + ), + mockObjectSet.setOf to + mapOf( + Relations.ID to mockObjectSet.setOf, + Relations.UNIQUE_KEY to setOfKey, + Relations.TYPE to ObjectTypeIds.OBJECT_TYPE, + Relations.RECOMMENDED_LAYOUT to recommendedLayout.code.toDouble(), + Relations.LAYOUT to ObjectType.Layout.OBJECT_TYPE.code.toDouble(), + ) ) ) stubOpenObject( diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetViewModelTestSetup.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetViewModelTestSetup.kt index 46d3bfb2d9..d3f7de185b 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetViewModelTestSetup.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetViewModelTestSetup.kt @@ -10,7 +10,6 @@ import com.anytypeio.anytype.core_models.Key import com.anytypeio.anytype.core_models.NetworkModeConfig 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.RelationLink import com.anytypeio.anytype.core_models.SearchResult import com.anytypeio.anytype.core_models.StubConfig @@ -19,7 +18,6 @@ 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.DataViewRestrictions -import com.anytypeio.anytype.domain.auth.interactor.ClearLastOpenedObject import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers import com.anytypeio.anytype.domain.base.Either import com.anytypeio.anytype.domain.base.Result @@ -35,7 +33,6 @@ import com.anytypeio.anytype.domain.debugging.Logger import com.anytypeio.anytype.domain.event.interactor.InterceptEvents import com.anytypeio.anytype.domain.event.interactor.SpaceSyncAndP2PStatusProvider import com.anytypeio.anytype.domain.launch.GetDefaultObjectType -import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer import com.anytypeio.anytype.domain.misc.DateProvider import com.anytypeio.anytype.domain.misc.LocaleProvider import com.anytypeio.anytype.domain.misc.UrlBuilder @@ -70,6 +67,7 @@ import com.anytypeio.anytype.presentation.collections.MockSet import com.anytypeio.anytype.presentation.common.Action import com.anytypeio.anytype.presentation.common.Delegator import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.home.UserPermissionProviderStub import com.anytypeio.anytype.presentation.relations.ObjectSetConfig import com.anytypeio.anytype.presentation.search.ObjectSearchConstants @@ -92,7 +90,6 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest import net.bytebuddy.utility.RandomString import org.junit.Rule @@ -340,8 +337,7 @@ open class ObjectSetViewModelTestSetup { fun stubOpenObject( doc: List = emptyList(), - details: Block.Details = Block.Details(), - relations: List = emptyList(), + details: ObjectViewDetails = ObjectViewDetails.EMPTY, additionalEvents: List = emptyList(), dataViewRestrictions: List = emptyList() ) { @@ -357,7 +353,7 @@ open class ObjectSetViewModelTestSetup { context = root, root = root, blocks = doc, - details = details, + details = details.details, dataViewRestrictions = dataViewRestrictions ) ) + additionalEvents diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetZeroViewTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetZeroViewTest.kt index a6c70a2707..5080f3db11 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetZeroViewTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/sets/main/ObjectSetZeroViewTest.kt @@ -3,7 +3,7 @@ package com.anytypeio.anytype.presentation.sets.main import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.DV import com.anytypeio.anytype.core_models.Relations -import com.anytypeio.anytype.domain.primitives.FieldParserImpl +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel import com.anytypeio.anytype.test_utils.MockDataFactory import org.junit.Before @@ -32,12 +32,11 @@ class ObjectSetZeroViewTest : ObjectSetViewModelTestSetup() { children = listOf(title.id) ) - private val objectSetDetails = Block.Details( - mapOf( - root to Block.Fields( - mapOf( - Relations.SET_OF to listOf(MockDataFactory.randomUuid()) - ) + private val objectSetDetails = ObjectViewDetails( + details = mapOf( + root to mapOf( + Relations.ID to root, + Relations.SET_OF to listOf(MockDataFactory.randomUuid()) ) ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/CollectionViewerTypeAndTemplateTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/CollectionViewerTypeAndTemplateTest.kt index ae08c822f2..2eb0a0527b 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/CollectionViewerTypeAndTemplateTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/CollectionViewerTypeAndTemplateTest.kt @@ -1,6 +1,5 @@ package com.anytypeio.anytype.presentation.templates -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.Relations @@ -13,7 +12,7 @@ import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.primitives.TypeId import com.anytypeio.anytype.core_models.primitives.TypeKey import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewObject -import com.anytypeio.anytype.domain.primitives.FieldParserImpl +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.DataViewViewState import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel import com.anytypeio.anytype.presentation.sets.main.ObjectSetViewModelTestSetup @@ -122,10 +121,10 @@ class CollectionViewerTypeAndTemplateTest: ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to null ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = collectionObjDetails), - pageTypeId.id to Block.Fields(map = pageTypeMap) + root to collectionObjDetails, + pageTypeId.id to pageTypeMap ) ) @@ -214,10 +213,10 @@ class CollectionViewerTypeAndTemplateTest: ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to null ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = collectionObjDetails), - pageTypeId.id to Block.Fields(map = pageTypeMap) + root to collectionObjDetails, + pageTypeId.id to pageTypeMap ) ) @@ -306,10 +305,10 @@ class CollectionViewerTypeAndTemplateTest: ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to pageTemplate2.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = collectionObjDetails), - pageTypeId.id to Block.Fields(map = pageTypeMap) + root to collectionObjDetails, + pageTypeId.id to pageTypeMap ) ) @@ -398,10 +397,10 @@ class CollectionViewerTypeAndTemplateTest: ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to template1.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = collectionObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to collectionObjDetails, + customType1Id to customType1Map ) ) @@ -490,10 +489,10 @@ class CollectionViewerTypeAndTemplateTest: ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to template1.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = collectionObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to collectionObjDetails, + customType1Id to customType1Map ) ) @@ -582,10 +581,10 @@ class CollectionViewerTypeAndTemplateTest: ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to template1.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = collectionObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to collectionObjDetails, + customType1Id to customType1Map ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByRelationViewerTypeAndTemplateTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByRelationViewerTypeAndTemplateTest.kt index 301334b3d2..7bff2cc8c7 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByRelationViewerTypeAndTemplateTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByRelationViewerTypeAndTemplateTest.kt @@ -1,6 +1,5 @@ package com.anytypeio.anytype.presentation.templates -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.ObjectWrapper @@ -12,7 +11,7 @@ import com.anytypeio.anytype.core_models.StubObject import com.anytypeio.anytype.core_models.StubRelationLink import com.anytypeio.anytype.core_models.primitives.TypeKey import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewObject -import com.anytypeio.anytype.domain.primitives.FieldParserImpl +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.DataViewViewState import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel import com.anytypeio.anytype.presentation.sets.main.ObjectSetViewModelTestSetup @@ -125,11 +124,11 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to null ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap ) ) @@ -215,11 +214,11 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to DEFAULT_TEMPLATE_ID_BLANK ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap ) ) @@ -305,11 +304,11 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to pageTemplate2.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap ) ) @@ -404,12 +403,12 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to template1.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap, + customType1Id to customType1Map ) ) @@ -505,12 +504,12 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to null ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap, + customType1Id to customType1Map ) ) @@ -606,12 +605,12 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to DEFAULT_TEMPLATE_ID_BLANK ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap, + customType1Id to customType1Map ) ) @@ -707,12 +706,12 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to template1.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap, + customType1Id to customType1Map ) ) @@ -808,12 +807,12 @@ class SetByRelationViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.DEFAULT_TEMPLATE_ID to template1.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - setByRelationId to Block.Fields(map = setByRelationMap), - pageTypeId to Block.Fields(map = pageTypeMap), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + setByRelationId to setByRelationMap, + pageTypeId to pageTypeMap, + customType1Id to customType1Map ) ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByTypeViewerTypeAndTemplateTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByTypeViewerTypeAndTemplateTest.kt index 7dac47de2e..f2c6328e2b 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByTypeViewerTypeAndTemplateTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/templates/SetByTypeViewerTypeAndTemplateTest.kt @@ -1,6 +1,5 @@ package com.anytypeio.anytype.presentation.templates -import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.NetworkModeConfig import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds @@ -13,7 +12,7 @@ import com.anytypeio.anytype.core_models.StubRelationLink import com.anytypeio.anytype.core_models.StubRelationObject import com.anytypeio.anytype.core_models.primitives.TypeKey import com.anytypeio.anytype.domain.dataview.interactor.CreateDataViewObject -import com.anytypeio.anytype.domain.primitives.FieldParserImpl +import com.anytypeio.anytype.core_models.ObjectViewDetails import com.anytypeio.anytype.presentation.sets.DataViewViewState import com.anytypeio.anytype.presentation.sets.ObjectSetViewModel import com.anytypeio.anytype.presentation.sets.main.ObjectSetViewModelTestSetup @@ -109,10 +108,10 @@ class SetByTypeViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.NAME to "name-$customType1Id", Relations.DEFAULT_TEMPLATE_ID to null ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + customType1Id to customType1Map ) ) @@ -198,10 +197,10 @@ class SetByTypeViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.NAME to "name-$customType1Id", Relations.DEFAULT_TEMPLATE_ID to DEFAULT_TEMPLATE_ID_BLANK ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + customType1Id to customType1Map ) ) @@ -287,10 +286,10 @@ class SetByTypeViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.NAME to "name-$customType1Id", Relations.DEFAULT_TEMPLATE_ID to template2.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + customType1Id to customType1Map ) ) @@ -389,11 +388,11 @@ class SetByTypeViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { defaultTemplateId = template1.id ) val dv = StubDataView(views = listOf(viewer), relationLinks = listOf(relationLink1)) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - customType1Id to Block.Fields(map = customType1Map), - customType2Id to Block.Fields(map = customType2Map) + root to setObjDetails, + customType1Id to customType1Map, + customType2Id to customType2Map ) ) @@ -479,10 +478,10 @@ class SetByTypeViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.NAME to "name-$customType1Id", Relations.DEFAULT_TEMPLATE_ID to template2.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + customType1Id to customType1Map ) ) @@ -568,10 +567,10 @@ class SetByTypeViewerTypeAndTemplateTest : ObjectSetViewModelTestSetup() { Relations.NAME to "name-$customType1Id", Relations.DEFAULT_TEMPLATE_ID to template2.id ) - val details = Block.Details( + val details = ObjectViewDetails( details = mapOf( - root to Block.Fields(map = setObjDetails), - customType1Id to Block.Fields(map = customType1Map) + root to setObjDetails, + customType1Id to customType1Map ) )