mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3240 Tech | Remove object relation links (#2000)
This commit is contained in:
parent
b3fdf89cbd
commit
c4968c3e4f
56 changed files with 304 additions and 1253 deletions
|
@ -413,7 +413,7 @@ class BlockMiddleware(
|
|||
|
||||
override suspend fun addRelationToObject(
|
||||
ctx: Id, relation: Key
|
||||
): Payload = middleware.objectRelationAdd(ctx, relation)
|
||||
): Payload? = middleware.objectRelationAdd(ctx, relation)
|
||||
|
||||
override suspend fun deleteRelationFromObject(
|
||||
ctx: Id,
|
||||
|
|
|
@ -1122,7 +1122,7 @@ class Middleware @Inject constructor(
|
|||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun objectRelationAdd(ctx: Id, relation: Key): Payload {
|
||||
fun objectRelationAdd(ctx: Id, relation: Key): Payload? {
|
||||
val request = Rpc.ObjectRelation.Add.Request(
|
||||
contextId = ctx,
|
||||
relationKeys = listOf(relation)
|
||||
|
@ -1130,7 +1130,7 @@ class Middleware @Inject constructor(
|
|||
logRequestIfDebug(request)
|
||||
val (response, time) = measureTimedValue { service.objectRelationAdd(request) }
|
||||
logResponseIfDebug(response, time)
|
||||
return response.event.toPayload()
|
||||
return response.event?.toPayload()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
|
|
|
@ -237,19 +237,10 @@ fun anytype.Event.Message.toCoreModels(
|
|||
key = event.key?.value_
|
||||
)
|
||||
}
|
||||
objectRelationsAmend != null -> {
|
||||
val event = objectRelationsAmend
|
||||
checkNotNull(event)
|
||||
Event.Command.ObjectRelationLinks.Amend(
|
||||
context = context,
|
||||
id = event.id,
|
||||
relationLinks = event.relationLinks.map { it.toCoreModels() }
|
||||
)
|
||||
}
|
||||
objectRelationsRemove != null -> {
|
||||
val event = objectRelationsRemove
|
||||
checkNotNull(event)
|
||||
Event.Command.ObjectRelationLinks.Remove(
|
||||
Event.Command.ObjectRelation.Remove(
|
||||
context = context,
|
||||
id = event.id,
|
||||
keys = event.relationKeys
|
||||
|
|
|
@ -46,7 +46,6 @@ import com.anytypeio.anytype.core_models.RelationLink
|
|||
import com.anytypeio.anytype.core_models.RelationListWithValueItem
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.SpaceUsage
|
||||
import com.anytypeio.anytype.core_models.TimeInSeconds
|
||||
import com.anytypeio.anytype.core_models.chats.Chat
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
|
@ -95,7 +94,6 @@ fun MObjectView.toPayload(): Payload {
|
|||
details.id to details.details.toCoreModel()
|
||||
}
|
||||
),
|
||||
relationLinks = relationLinks.map { it.toCoreModels() },
|
||||
objectRestrictions = restrictions?.object_?.map { it.toCoreModel() }.orEmpty(),
|
||||
dataViewRestrictions = restrictions?.dataview?.map { it.toCoreModel() }.orEmpty()
|
||||
)
|
||||
|
@ -108,7 +106,6 @@ fun MObjectView.toCore(): ObjectView {
|
|||
root = rootId,
|
||||
blocks = blocks.toCoreModels(),
|
||||
details = details.associate { d -> d.id to d.details.orEmpty() },
|
||||
relations = relationLinks.map { it.toCoreModels() },
|
||||
objectRestrictions = restrictions?.object_?.map { it.toCoreModel() }.orEmpty(),
|
||||
dataViewRestrictions = restrictions?.dataview?.map { it.toCoreModel() }.orEmpty(),
|
||||
)
|
||||
|
|
|
@ -2,13 +2,10 @@ package com.anytypeio.anytype
|
|||
|
||||
import anytype.model.Block
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.RelationFormat
|
||||
import com.anytypeio.anytype.core_models.RelationLink
|
||||
import com.anytypeio.anytype.core_models.ThemeColor
|
||||
import com.anytypeio.anytype.core_utils.tools.FeatureToggles
|
||||
import com.anytypeio.anytype.middleware.EventProxy
|
||||
import com.anytypeio.anytype.middleware.interactor.MiddlewareEventChannel
|
||||
import com.anytypeio.anytype.middleware.mappers.MRelationLink
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
@ -315,63 +312,6 @@ class MiddlewareEventChannelTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return amend relation links event`() {
|
||||
|
||||
val context = MockDataFactory.randomUuid()
|
||||
|
||||
val id = MockDataFactory.randomUuid()
|
||||
|
||||
val relationLink1 = MRelationLink(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
format = anytype.model.RelationFormat.longtext
|
||||
)
|
||||
|
||||
val relationLink2 = MRelationLink(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
format = anytype.model.RelationFormat.longtext
|
||||
)
|
||||
|
||||
val relationLink3 = MRelationLink(
|
||||
key = MockDataFactory.randomUuid(),
|
||||
format = anytype.model.RelationFormat.longtext
|
||||
)
|
||||
|
||||
val msg = anytype.Event.Object.Relations.Amend(
|
||||
id = id,
|
||||
relationLinks = listOf(relationLink1, relationLink2, relationLink3)
|
||||
)
|
||||
|
||||
val message = anytype.Event.Message(objectRelationsAmend = msg)
|
||||
|
||||
val event = anytype.Event(contextId = context, messages = listOf(message))
|
||||
|
||||
proxy.stub {
|
||||
on { flow() } doReturn flowOf(event)
|
||||
}
|
||||
|
||||
val expected = listOf(
|
||||
Event.Command.ObjectRelationLinks.Amend(
|
||||
context = context,
|
||||
id = id,
|
||||
relationLinks = listOf(
|
||||
RelationLink(key = relationLink1.key, format = RelationFormat.LONG_TEXT),
|
||||
RelationLink(key = relationLink2.key, format = RelationFormat.LONG_TEXT),
|
||||
RelationLink(key = relationLink3.key, format = RelationFormat.LONG_TEXT)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
channel.observeEvents(context = context).collect { events ->
|
||||
assertEquals(
|
||||
expected = expected,
|
||||
actual = events
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return remove relation links event`() {
|
||||
|
||||
|
@ -397,7 +337,7 @@ class MiddlewareEventChannelTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
Event.Command.ObjectRelationLinks.Remove(
|
||||
Event.Command.ObjectRelation.Remove(
|
||||
context = context,
|
||||
id = id,
|
||||
keys = listOf(id1, id2, id3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue