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 3b8fb99c51..68403379b1 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 @@ -192,29 +192,18 @@ data class Block( val iconSize: IconSize, val cardStyle: CardStyle, val description: Description, - @Deprecated("To be removed") - val relations: Set = emptySet(), + val relations: Set = emptySet(), ) : Content() { - sealed interface Relation { - object COVER : Relation - object NAME : Relation - object TYPE : Relation - data class UNKNOWN(val value: String) : Relation - } - enum class Type { PAGE, DATA_VIEW, DASHBOARD, ARCHIVE } enum class IconSize { NONE, SMALL, MEDIUM } enum class CardStyle { TEXT, CARD, INLINE } enum class Description { NONE, ADDED, CONTENT } - val hasName: Boolean - get() = relations.contains(Relation.NAME) - val hasCover: Boolean - get() = relations.contains(Relation.COVER) + get() = relations.contains(Relations.COVER) val hasType: Boolean - get() = relations.contains(Relation.TYPE) + get() = relations.contains(Relations.TYPE) } /** 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 5d837a7854..2eb0cceefd 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 @@ -80,7 +80,6 @@ sealed class Event { * @property context update's context * @property id id of the link * @property target id of the linked block - * @property fields link's fields (considered updated if not null) */ data class LinkGranularChange( override val context: String, @@ -89,7 +88,7 @@ sealed class Event { val iconSize: Block.Content.Link.IconSize?, val cardStyle: Block.Content.Link.CardStyle?, val description: Block.Content.Link.Description?, - val relations: Set?, + val relations: Set?, ) : Command() /** diff --git a/core-models/src/main/java/com/anytypeio/anytype/core_models/Relations.kt b/core-models/src/main/java/com/anytypeio/anytype/core_models/Relations.kt index 7dde725fa0..2898b341b9 100644 --- a/core-models/src/main/java/com/anytypeio/anytype/core_models/Relations.kt +++ b/core-models/src/main/java/com/anytypeio/anytype/core_models/Relations.kt @@ -6,6 +6,7 @@ package com.anytypeio.anytype.core_models object Relations { const val ID = "id" + const val COVER = "cover" const val COVER_TYPE = "coverType" const val COVER_ID = "coverId" const val DESCRIPTION = "description" diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt index 9c72fa5123..90e25bb3d7 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/interactor/Middleware.kt @@ -696,7 +696,7 @@ class Middleware( iconSize = content.iconSize.toMiddlewareModel(), cardStyle = content.cardStyle.toMiddlewareModel(), description = content.description.toMiddlewareModel(), - relations = content.relations.map { it.toMiddlewareModel() } + relations = content.relations.toList() ) if (BuildConfig.DEBUG) logRequest(request) val response = service.blockLinkListSetAppearance( 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 f08c486619..fc5de24e9b 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 @@ -1,7 +1,6 @@ package com.anytypeio.anytype.middleware.interactor import com.anytypeio.anytype.core_models.Event -import com.anytypeio.anytype.middleware.mappers.toCoreLinkRelationModel import com.anytypeio.anytype.middleware.mappers.toCoreModel import com.anytypeio.anytype.middleware.mappers.toCoreModels import com.anytypeio.anytype.middleware.mappers.toCoreModelsAlign @@ -96,7 +95,7 @@ fun anytype.Event.Message.toCoreModels( iconSize = event.iconSize?.value_?.toCoreModel(), cardStyle = event.cardStyle?.value_?.toCoreModel(), description = event.description?.value_?.toCoreModel(), - relations = event.relations?.value_?.map { it.toCoreLinkRelationModel() }?.toSet() + relations = event.relations?.value_?.toSet() ) } blockSetAlign != 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 d7fdc432d0..45b354dd52 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 @@ -263,19 +263,10 @@ fun MBlock.toCoreModelsLink(): Block.Content.Link { iconSize = content.iconSize.toCoreModel(), cardStyle = content.cardStyle.toCoreModel(), description = content.description.toCoreModel(), - relations = content.relations.map { it.toCoreLinkRelationModel() }.toSet(), + relations = content.relations.toSet(), ) } -internal fun String.toCoreLinkRelationModel(): Block.Content.Link.Relation { - return when (this) { - "cover" -> Block.Content.Link.Relation.COVER - "name" -> Block.Content.Link.Relation.NAME - "type" -> Block.Content.Link.Relation.TYPE - else -> Block.Content.Link.Relation.UNKNOWN(this) - } -} - fun MBLinkIconSize.toCoreModel(): Block.Content.Link.IconSize { return when (this) { MBLinkIconSize.SizeNone -> Block.Content.Link.IconSize.NONE diff --git a/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToMiddlewareModelMappers.kt b/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToMiddlewareModelMappers.kt index fdf26a82ca..0f515419c5 100644 --- a/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToMiddlewareModelMappers.kt +++ b/middleware/src/main/java/com/anytypeio/anytype/middleware/mappers/ToMiddlewareModelMappers.kt @@ -118,19 +118,10 @@ internal fun Block.Content.Link.toMiddlewareModel(): MBLink { iconSize = iconSize.toMiddlewareModel(), cardStyle = cardStyle.toMiddlewareModel(), description = description.toMiddlewareModel(), - relations = relations.map { it.toMiddlewareModel() } + relations = relations.toList() ) } -internal fun Block.Content.Link.Relation.toMiddlewareModel(): String { - return when (this) { - Block.Content.Link.Relation.COVER -> "cover" - Block.Content.Link.Relation.NAME -> "name" - Block.Content.Link.Relation.TYPE -> "type" - is Block.Content.Link.Relation.UNKNOWN -> this.value - } -} - internal fun Block.Content.Link.Description.toMiddlewareModel(): MBLinkDescription { return when (this) { Block.Content.Link.Description.NONE -> MBLinkDescription.None diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/ObjectAppearanceSettingViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/ObjectAppearanceSettingViewModel.kt index 74a27ffc45..70c49bbd76 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/ObjectAppearanceSettingViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/ObjectAppearanceSettingViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope import com.anytypeio.anytype.core_models.Block.Content.Link import com.anytypeio.anytype.core_models.Id import com.anytypeio.anytype.core_models.Payload +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.domain.block.interactor.SetLinkAppearance import com.anytypeio.anytype.presentation.editor.Editor import com.anytypeio.anytype.presentation.editor.editor.ext.getLinkAppearanceMenu @@ -104,9 +105,9 @@ class ObjectAppearanceSettingViewModel( val newContent = when (toggle) { is Relation.ObjectType -> content.copy( relations = if (isChecked) { - content.relations + Link.Relation.TYPE + content.relations + Relations.TYPE } else { - content.relations - Link.Relation.TYPE + content.relations - Relations.TYPE } ) } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChooseCoverViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChooseCoverViewModel.kt index 9e3bc48d97..08b42dce92 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChooseCoverViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/objects/appearance/choose/ObjectAppearanceChooseCoverViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Payload +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.domain.block.interactor.SetLinkAppearance import com.anytypeio.anytype.presentation.editor.Editor import com.anytypeio.anytype.presentation.editor.editor.model.BlockView @@ -37,12 +38,12 @@ class ObjectAppearanceChooseCoverViewModel( return when (item) { is Cover.None -> { oldContent.copy( - relations = relations - Block.Content.Link.Relation.COVER + relations = relations - Relations.COVER ) } is Cover.Visible -> { oldContent.copy( - relations = relations + Block.Content.Link.Relation.COVER + relations = relations + Relations.COVER ) } } 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 8c93e8ff9d..aa1b5ed281 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 @@ -2645,7 +2645,7 @@ class DefaultBlockViewRendererTest { cardStyle = Link.CardStyle.CARD, iconSize = Link.IconSize.NONE, description = Link.Description.ADDED, - relations = setOf(Link.Relation.NAME) + relations = setOf(Relations.NAME) ), backgroundColor = "red" ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceInEditorTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceInEditorTest.kt index 282a2a3c00..c78b0fc483 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceInEditorTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceInEditorTest.kt @@ -2,11 +2,12 @@ package com.anytypeio.anytype.presentation.objects.appearance import com.anytypeio.anytype.core_models.Block.Content.Link import com.anytypeio.anytype.core_models.ObjectType +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubLinkContent import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.editor.model.BlockView.Appearance.InEditor.Description -import org.junit.Test import kotlin.test.assertEquals +import org.junit.Test class LinkAppearanceInEditorTest { @@ -61,7 +62,7 @@ class LinkAppearanceInEditorTest { fun `should create appearance params without cover`() { val factory = LinkAppearanceFactory( content = defaultLinkAppearance.copy( - relations = defaultLinkAppearance.relations + Link.Relation.COVER + relations = defaultLinkAppearance.relations + Relations.COVER ), layout = ObjectType.Layout.BASIC ) diff --git a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceMenuTest.kt b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceMenuTest.kt index 9ef2aa155d..f8ad609c08 100644 --- a/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceMenuTest.kt +++ b/presentation/src/test/java/com/anytypeio/anytype/presentation/objects/appearance/LinkAppearanceMenuTest.kt @@ -2,13 +2,13 @@ package com.anytypeio.anytype.presentation.objects.appearance import com.anytypeio.anytype.core_models.Block.Content.Link import com.anytypeio.anytype.core_models.ObjectType +import com.anytypeio.anytype.core_models.Relations import com.anytypeio.anytype.presentation.MockBlockContentFactory.StubLinkContent import com.anytypeio.anytype.presentation.editor.editor.model.BlockView import com.anytypeio.anytype.presentation.editor.editor.model.BlockView.Appearance.MenuItem -import com.anytypeio.anytype.presentation.objects.appearance.choose.ObjectAppearanceChooseIconViewModel import com.anytypeio.anytype.presentation.objects.appearance.choose.ObjectAppearanceChooseSettingsView -import org.junit.Test import kotlin.test.assertEquals +import org.junit.Test class LinkAppearanceMenuTest { @@ -16,7 +16,7 @@ class LinkAppearanceMenuTest { iconSize = Link.IconSize.SMALL, cardStyle = Link.CardStyle.TEXT, description = Link.Description.NONE, - relations = setOf(Link.Relation.NAME) + relations = setOf(Relations.NAME) ) @Test @@ -67,7 +67,7 @@ class LinkAppearanceMenuTest { iconSize = Link.IconSize.SMALL, cardStyle = Link.CardStyle.CARD, description = Link.Description.NONE, - relations = setOf(Link.Relation.NAME) + relations = setOf(Relations.NAME) ), layout = ObjectType.Layout.TODO ) @@ -91,7 +91,7 @@ class LinkAppearanceMenuTest { iconSize = Link.IconSize.SMALL, cardStyle = Link.CardStyle.CARD, description = Link.Description.NONE, - relations = setOf(Link.Relation.NAME, Link.Relation.COVER) + relations = setOf(Relations.NAME, Relations.COVER) ), layout = ObjectType.Layout.TODO ) diff --git a/test/core-models-stub/src/main/java/com/anytypeio/anytype/presentation/MockBlockContentFactory.kt b/test/core-models-stub/src/main/java/com/anytypeio/anytype/presentation/MockBlockContentFactory.kt index 7116cf29df..b2ffec2e1b 100644 --- a/test/core-models-stub/src/main/java/com/anytypeio/anytype/presentation/MockBlockContentFactory.kt +++ b/test/core-models-stub/src/main/java/com/anytypeio/anytype/presentation/MockBlockContentFactory.kt @@ -2,6 +2,7 @@ package com.anytypeio.anytype.presentation import com.anytypeio.anytype.core_models.Block import com.anytypeio.anytype.core_models.Block.Content.Link +import com.anytypeio.anytype.core_models.Key import com.anytypeio.anytype.test_utils.MockDataFactory object MockBlockContentFactory { @@ -12,7 +13,7 @@ object MockBlockContentFactory { iconSize: Link.IconSize = Link.IconSize.SMALL, cardStyle: Link.CardStyle = Link.CardStyle.TEXT, description: Link.Description = Link.Description.NONE, - relations: Set = emptySet(), + relations: Set = emptySet(), ): Link = Link( target = target, type = type,