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

DROID-2578 Tech | Implement BlockDataViewSetActiveView (#1766)

This commit is contained in:
Konstantin Ivanov 2024-11-05 09:12:50 +01:00 committed by GitHub
parent 50d0d293ec
commit 3536f4535b
Signed by: github
GPG key ID: B5690EEEBB952194
9 changed files with 76 additions and 0 deletions

View file

@ -607,4 +607,14 @@ sealed class Command {
val emoji: String
): ChatCommand()
}
/**
* id of dataview block
* id of active vi1ew
*/
data class DataViewSetActiveView(
val ctx: Id,
val dataViewId: Id,
val viewerId: Id
)
}

View file

@ -872,6 +872,10 @@ class BlockDataRepository(
return remote.setQueryToSet(command)
}
override suspend fun dataViewSetActiveView(command: Command.DataViewSetActiveView): Payload {
return remote.dataViewSetActiveView(command)
}
override suspend fun nodeUsage(): NodeUsageInfo {
return remote.nodeUsage()
}

View file

@ -382,6 +382,7 @@ interface BlockRemote {
suspend fun addObjectToCollection(command: Command.AddObjectToCollection): Payload
suspend fun setQueryToSet(command: Command.SetQueryToSet): Payload
suspend fun nodeUsage(): NodeUsageInfo
suspend fun dataViewSetActiveView(command: Command.DataViewSetActiveView): Payload
suspend fun setInternalFlags(command: Command.SetInternalFlags): Payload

View file

@ -431,6 +431,7 @@ interface BlockRepository {
suspend fun sortDataViewViewRelation(command: Command.SortRelations): Payload
suspend fun addObjectToCollection(command: Command.AddObjectToCollection): Payload
suspend fun setQueryToSet(command: Command.SetQueryToSet): Payload
suspend fun dataViewSetActiveView(command: Command.DataViewSetActiveView): Payload
suspend fun nodeUsage(): NodeUsageInfo
suspend fun setInternalFlags(command: Command.SetInternalFlags): Payload
suspend fun duplicateObjectsList(ids: List<Id>): List<Id>

View file

@ -0,0 +1,27 @@
package com.anytypeio.anytype.domain.dataview.interactor
import com.anytypeio.anytype.core_models.Command
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.ResultInteractor
import com.anytypeio.anytype.domain.block.repo.BlockRepository
class SetActiveViewer(private val repo: BlockRepository, dispatchers: AppCoroutineDispatchers) :
ResultInteractor<SetActiveViewer.Params, Payload>(dispatchers.io) {
override suspend fun doWork(params: Params): Payload {
val command = Command.DataViewSetActiveView(
ctx = params.ctx,
viewerId = params.viewer,
dataViewId = params.dv
)
return repo.dataViewSetActiveView(command)
}
data class Params(
val ctx: Id,
val viewer: Id,
val dv: Id
)
}

View file

@ -1040,4 +1040,8 @@ class BlockMiddleware(
override suspend fun unsubscribeChat(chat: Id) {
return middleware.chatUnsubscribe(chat = chat)
}
override suspend fun dataViewSetActiveView(command: Command.DataViewSetActiveView): Payload {
return middleware.dataViewSetActiveView(command)
}
}

View file

@ -2782,6 +2782,19 @@ class Middleware @Inject constructor(
logResponseIfDebug(response, time)
}
@Throws
fun dataViewSetActiveView(command: Command.DataViewSetActiveView): Payload {
val request = Rpc.BlockDataview.View.SetActive.Request(
contextId = command.ctx,
blockId = command.dataViewId,
viewId = command.viewerId
)
logRequestIfDebug(request)
val (response, time) = measureTimedValue { service.blockDataViewSetActiveView(request) }
logResponseIfDebug(response, time)
return response.event.toPayload()
}
@Throws
fun chatUnsubscribe(chat: Id) {
val request = Rpc.Chat.Unsubscribe.Request(chatObjectId = chat)

View file

@ -354,6 +354,9 @@ interface MiddlewareService {
@Throws(Exception::class)
fun blockDataViewSortViewRelation(request: Rpc.BlockDataview.ViewRelation.Sort.Request): Rpc.BlockDataview.ViewRelation.Sort.Response
@Throws(Exception::class)
fun blockDataViewSetActiveView(request: Rpc.BlockDataview.View.SetActive.Request): Rpc.BlockDataview.View.SetActive.Response
//endregion
//region TEXT BLOCK commands

View file

@ -1653,6 +1653,19 @@ class MiddlewareServiceImplementation @Inject constructor(
}
}
override fun blockDataViewSetActiveView(request: Rpc.BlockDataview.View.SetActive.Request): Rpc.BlockDataview.View.SetActive.Response {
val encoded = Service.blockDataviewViewSetActive(
Rpc.BlockDataview.View.SetActive.Request.ADAPTER.encode(request)
)
val response = Rpc.BlockDataview.View.SetActive.Response.ADAPTER.decode(encoded)
val error = response.error
if (error != null && error.code != Rpc.BlockDataview.View.SetActive.Response.Error.Code.NULL) {
throw Exception(error.description)
} else {
return response
}
}
override fun createTemplateFromObject(request: Rpc.Template.CreateFromObject.Request): Rpc.Template.CreateFromObject.Response {
val encoded = Service.templateCreateFromObject(
Rpc.Template.CreateFromObject.Request.ADAPTER.encode(request)