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

DROID-366 Tech | Enhancement | Support object view result + New Interactor (#2790)

This commit is contained in:
Evgenii Kozlov 2022-12-28 21:11:35 +03:00 committed by GitHub
parent f0b7ef5618
commit ca535bbd46
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 94 additions and 20 deletions

View file

@ -0,0 +1,14 @@
package com.anytypeio.anytype.core_models
import com.anytypeio.anytype.core_models.restrictions.DataViewRestrictions
import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction
data class ObjectView(
val root: Id,
val blocks: List<Block>,
val details: Map<Id, Struct>,
val type: SmartBlockType,
val relations: List<RelationLink>,
val objectRestrictions: List<ObjectRestriction>,
val dataViewRestrictions: List<DataViewRestrictions>
)

View file

@ -11,10 +11,10 @@ import com.anytypeio.anytype.core_models.DVViewerType
import com.anytypeio.anytype.core_models.DocumentInfo
import com.anytypeio.anytype.core_models.Hash
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.InternalFlags
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectInfoWithLinks
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectView
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Position
@ -37,6 +37,8 @@ class BlockDataRepository(
private val remote: BlockDataStore
) : BlockRepository {
override suspend fun openObject(id: Id): ObjectView = remote.openObject(id = id)
override suspend fun openDashboard(
contextId: String,
id: String

View file

@ -13,10 +13,10 @@ import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectInfoWithLinks
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectView
import com.anytypeio.anytype.core_models.ObjectWrapper
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.Response
import com.anytypeio.anytype.core_models.SearchResult
@ -49,6 +49,7 @@ interface BlockDataStore {
suspend fun move(command: Command.Move): Payload
suspend fun unlink(command: Command.Unlink): Payload
suspend fun openObject(id: Id) : ObjectView
suspend fun openPage(id: String): Payload
suspend fun openObjectSet(id: String): Payload
suspend fun openProfile(id: String): Payload

View file

@ -13,10 +13,10 @@ import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectInfoWithLinks
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectView
import com.anytypeio.anytype.core_models.ObjectWrapper
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.Response
import com.anytypeio.anytype.core_models.SearchResult
@ -49,6 +49,7 @@ interface BlockRemote {
command: Command.CreateBlockLinkWithObject
): CreateBlockLinkWithObjectResult
suspend fun openObject(id: Id) : ObjectView
suspend fun openPage(id: String): Payload
suspend fun openProfile(id: String): Payload
suspend fun openObjectSet(id: String): Payload

View file

@ -10,14 +10,13 @@ import com.anytypeio.anytype.core_models.DVViewer
import com.anytypeio.anytype.core_models.DVViewerType
import com.anytypeio.anytype.core_models.DocumentInfo
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.InternalFlags
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectInfoWithLinks
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectView
import com.anytypeio.anytype.core_models.ObjectWrapper
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.Response
import com.anytypeio.anytype.core_models.SearchResult
@ -39,6 +38,7 @@ class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore {
command: Command.CreateBlockLinkWithObject
): CreateBlockLinkWithObjectResult = remote.createBlockLinkWithObject(command)
override suspend fun openObject(id: Id): ObjectView = remote.openObject(id = id)
override suspend fun openPage(id: String): Payload = remote.openPage(id)
override suspend fun openProfile(id: String): Payload = remote.openProfile(id)
override suspend fun openObjectSet(id: String): Payload = remote.openObjectSet(id)

View file

@ -4,11 +4,9 @@ import com.anytypeio.anytype.domain.base.Interactor.Status
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flatMapConcat
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext
import kotlin.coroutines.CoroutineContext
@ -55,6 +53,19 @@ abstract class Interactor<in P>(
}
}
abstract class ResultatInteractor<in P, out R>() {
operator fun invoke(params: P): Flow<Resultat<R>> {
return flow {
emit(Resultat.Loading())
val r = execute(params)
emit(Resultat.Success(r))
}.catch { t ->
emit(Resultat.Failure(t))
}
}
protected abstract suspend fun execute(params: P) : R
}
abstract class ResultInteractor<in P, R>(
private val context: CoroutineContext = Dispatchers.IO
) {

View file

@ -11,14 +11,13 @@ import com.anytypeio.anytype.core_models.DVViewerType
import com.anytypeio.anytype.core_models.DocumentInfo
import com.anytypeio.anytype.core_models.Hash
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.InternalFlags
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectInfoWithLinks
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectView
import com.anytypeio.anytype.core_models.ObjectWrapper
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.Response
import com.anytypeio.anytype.core_models.SearchResult
@ -90,12 +89,14 @@ interface BlockRepository {
suspend fun setRelationKey(command: Command.SetRelationKey): Payload
suspend fun openObject(id: Id) : ObjectView
@Deprecated("To be deleted")
suspend fun openObjectPreview(id: Id): Result<Payload>
@Deprecated("To be deleted")
suspend fun openPage(id: String): Result<Payload>
@Deprecated("To be deleted")
suspend fun openProfile(id: String): Payload
@Deprecated("To be deleted")
suspend fun openObjectSet(id: String): Result<Payload>
suspend fun closePage(id: String)

View file

@ -0,0 +1,21 @@
package com.anytypeio.anytype.domain.`object`
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectView
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.ResultatInteractor
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import kotlinx.coroutines.withContext
class OpenObject(
private val repo: BlockRepository,
private val auth: AuthRepository,
private val dispatchers: AppCoroutineDispatchers
) : ResultatInteractor<Id, ObjectView>() {
override suspend fun execute(params: Id): ObjectView = withContext(dispatchers.io) {
repo.openObject(params).also {
auth.saveLastOpenedObjectId(params)
}
}
}

View file

@ -14,10 +14,10 @@ import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Key
import com.anytypeio.anytype.core_models.ObjectInfoWithLinks
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectView
import com.anytypeio.anytype.core_models.ObjectWrapper
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.Response
import com.anytypeio.anytype.core_models.SearchResult
@ -26,7 +26,6 @@ import com.anytypeio.anytype.core_models.Url
import com.anytypeio.anytype.data.auth.repo.block.BlockRemote
import com.anytypeio.anytype.middleware.interactor.Middleware
import com.anytypeio.anytype.middleware.mappers.toCoreModel
import com.anytypeio.anytype.middleware.mappers.toCoreModels
import com.anytypeio.anytype.middleware.mappers.toMiddlewareModel
class BlockMiddleware(
@ -42,9 +41,10 @@ class BlockMiddleware(
middleware.objectClose(id)
}
override suspend fun openPage(id: String): Payload = middleware.objectOpen(id)
override suspend fun openProfile(id: String): Payload = middleware.objectOpen(id)
override suspend fun openObjectSet(id: String): Payload = middleware.objectOpen(id)
override suspend fun openObject(id: Id): ObjectView = middleware.objectOpen(id = id)
override suspend fun openPage(id: String): Payload = middleware.objectOpenOld(id)
override suspend fun openProfile(id: String): Payload = middleware.objectOpenOld(id)
override suspend fun openObjectSet(id: String): Payload = middleware.objectOpenOld(id)
override suspend fun openObjectPreview(id: Id): Payload = middleware.objectShow(id)
override suspend fun closePage(id: String) {

View file

@ -18,6 +18,7 @@ import com.anytypeio.anytype.core_models.DVViewerType
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.ObjectView
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Position
@ -30,10 +31,10 @@ import com.anytypeio.anytype.core_models.Url
import com.anytypeio.anytype.middleware.BuildConfig
import com.anytypeio.anytype.middleware.auth.toAccountSetup
import com.anytypeio.anytype.middleware.const.Constants
import com.anytypeio.anytype.middleware.mappers.MRelation
import com.anytypeio.anytype.middleware.mappers.MRelationFormat
import com.anytypeio.anytype.middleware.mappers.core
import com.anytypeio.anytype.middleware.mappers.parse
import com.anytypeio.anytype.middleware.mappers.toCore
import com.anytypeio.anytype.middleware.mappers.toCoreModel
import com.anytypeio.anytype.middleware.mappers.toCoreModels
import com.anytypeio.anytype.middleware.mappers.toMiddlewareModel
@ -1039,7 +1040,7 @@ class Middleware(
}
@Throws(Exception::class)
fun objectOpen(id: String): Payload {
fun objectOpenOld(id: String): Payload {
val request = Rpc.Object.Open.Request(objectId = id)
if (BuildConfig.DEBUG) logRequest(request)
val response = service.objectOpen(request)
@ -1049,6 +1050,15 @@ class Middleware(
?: throw IllegalStateException("Object view was null")
}
@Throws(Exception::class)
fun objectOpen(id: String): ObjectView {
val request = Rpc.Object.Open.Request(objectId = id)
if (BuildConfig.DEBUG) logRequest(request)
val response = service.objectOpen(request)
if (BuildConfig.DEBUG) logResponse(response)
return response.objectView?.toCore() ?: throw IllegalStateException("Object view was null")
}
@Throws(Exception::class)
fun objectRedo(command: Command.Redo): Payload {
val request = Rpc.Object.Redo.Request(contextId = command.context)

View file

@ -41,13 +41,26 @@ fun MObjectView.toPayload() : Payload {
),
type = type,
relationLinks = relationLinks.map { it.toCoreModels() },
objectRestrictions = restrictions?.object_?.mapNotNull { it.toCoreModel() }.orEmpty(),
objectRestrictions = restrictions?.object_?.map { it.toCoreModel() }.orEmpty(),
dataViewRestrictions = restrictions?.dataview?.map { it.toCoreModel() }.orEmpty()
)
)
)
}
fun MObjectView.toCore() : ObjectView {
val type = type.toCoreModel()
return ObjectView(
root = rootId,
blocks = blocks.toCoreModels(types = mapOf(rootId to type)),
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(),
type = type
)
}
// ---------------------- BLOCKS ------------------------
fun List<MBlock>.toCoreModels(