mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2688 Version history | Api (#1428)
This commit is contained in:
parent
eef83e033b
commit
a103fdab44
14 changed files with 373 additions and 0 deletions
|
@ -545,4 +545,30 @@ sealed class Command {
|
|||
data class ProcessCancel(
|
||||
val processId: Id
|
||||
) : Command()
|
||||
|
||||
sealed class VersionHistory {
|
||||
data class GetVersions(
|
||||
val objectId: Id,
|
||||
val lastVersion: Id,
|
||||
val limit: Int
|
||||
) : VersionHistory()
|
||||
|
||||
data class ShowVersion(
|
||||
val objectId: Id,
|
||||
val versionId: Id,
|
||||
val traceId: Id
|
||||
) : VersionHistory()
|
||||
|
||||
data class SetVersion(
|
||||
val objectId: Id,
|
||||
val versionId: Id
|
||||
) : VersionHistory()
|
||||
|
||||
data class DiffVersions(
|
||||
val objectId: Id,
|
||||
val spaceId: Id,
|
||||
val currentVersion: Id,
|
||||
val previousVersion: Id
|
||||
) : VersionHistory()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.anytypeio.anytype.core_models.history
|
||||
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectView
|
||||
|
||||
data class Version(
|
||||
val id: Id,
|
||||
val previousIds: List<Id>,
|
||||
val authorId: Id,
|
||||
val authorName: String,
|
||||
val timestamp: Long,
|
||||
val groupId: Long
|
||||
)
|
||||
|
||||
data class ShowVersionResponse(
|
||||
val objectView: ObjectView?,
|
||||
val version: Version?,
|
||||
val traceId: Id
|
||||
)
|
||||
|
||||
data class DiffVersionResponse(
|
||||
val historyEvents: List<Event.Command>,
|
||||
val objectView: ObjectView?
|
||||
)
|
|
@ -24,6 +24,9 @@ import com.anytypeio.anytype.core_models.SearchResult
|
|||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.core_models.WidgetLayout
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.Version
|
||||
import com.anytypeio.anytype.core_models.membership.EmailVerificationStatus
|
||||
import com.anytypeio.anytype.core_models.membership.GetPaymentUrlResponse
|
||||
import com.anytypeio.anytype.core_models.membership.Membership
|
||||
|
@ -1031,4 +1034,20 @@ class BlockDataRepository(
|
|||
override suspend fun processCancel(command: Command.ProcessCancel) {
|
||||
remote.processCancel(command)
|
||||
}
|
||||
|
||||
override suspend fun getVersions(command: Command.VersionHistory.GetVersions): List<Version> {
|
||||
return remote.getVersions(command)
|
||||
}
|
||||
|
||||
override suspend fun showVersion(command: Command.VersionHistory.ShowVersion): ShowVersionResponse {
|
||||
return remote.showVersion(command)
|
||||
}
|
||||
|
||||
override suspend fun setVersion(command: Command.VersionHistory.SetVersion) {
|
||||
remote.setVersion(command)
|
||||
}
|
||||
|
||||
override suspend fun diffVersions(command: Command.VersionHistory.DiffVersions): DiffVersionResponse {
|
||||
return remote.diffVersions(command)
|
||||
}
|
||||
}
|
|
@ -24,6 +24,9 @@ import com.anytypeio.anytype.core_models.SearchResult
|
|||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.core_models.WidgetLayout
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.Version
|
||||
import com.anytypeio.anytype.core_models.membership.EmailVerificationStatus
|
||||
import com.anytypeio.anytype.core_models.membership.GetPaymentUrlResponse
|
||||
import com.anytypeio.anytype.core_models.membership.Membership
|
||||
|
@ -436,4 +439,9 @@ interface BlockRemote {
|
|||
suspend fun membershipGetTiers(command: Command.Membership.GetTiers): List<MembershipTierData>
|
||||
|
||||
suspend fun processCancel(command: Command.ProcessCancel)
|
||||
|
||||
suspend fun getVersions(command: Command.VersionHistory.GetVersions): List<Version>
|
||||
suspend fun showVersion(command: Command.VersionHistory.ShowVersion): ShowVersionResponse
|
||||
suspend fun setVersion(command: Command.VersionHistory.SetVersion)
|
||||
suspend fun diffVersions(command: Command.VersionHistory.DiffVersions): DiffVersionResponse
|
||||
}
|
|
@ -24,6 +24,9 @@ import com.anytypeio.anytype.core_models.SearchResult
|
|||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.core_models.WidgetLayout
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.Version
|
||||
import com.anytypeio.anytype.core_models.membership.EmailVerificationStatus
|
||||
import com.anytypeio.anytype.core_models.membership.GetPaymentUrlResponse
|
||||
import com.anytypeio.anytype.core_models.membership.Membership
|
||||
|
@ -477,4 +480,9 @@ interface BlockRepository {
|
|||
suspend fun membershipGetTiers(command: Command.Membership.GetTiers): List<MembershipTierData>
|
||||
|
||||
suspend fun processCancel(command: Command.ProcessCancel)
|
||||
|
||||
suspend fun getVersions(command: Command.VersionHistory.GetVersions): List<Version>
|
||||
suspend fun showVersion(command: Command.VersionHistory.ShowVersion): ShowVersionResponse
|
||||
suspend fun setVersion(command: Command.VersionHistory.SetVersion)
|
||||
suspend fun diffVersions(command: Command.VersionHistory.DiffVersions): DiffVersionResponse
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.anytypeio.anytype.domain.history
|
||||
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.base.ResultInteractor
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DiffVersions @Inject constructor(
|
||||
dispatchers: AppCoroutineDispatchers,
|
||||
private val repo: BlockRepository
|
||||
) : ResultInteractor<DiffVersions.Params, DiffVersionResponse>(dispatchers.io) {
|
||||
|
||||
override suspend fun doWork(params: Params): DiffVersionResponse {
|
||||
val command = Command.VersionHistory.DiffVersions(
|
||||
objectId = params.objectId,
|
||||
spaceId = params.spaceId,
|
||||
currentVersion = params.currentVersion,
|
||||
previousVersion = params.previousVersion
|
||||
)
|
||||
return repo.diffVersions(command)
|
||||
}
|
||||
|
||||
data class Params(
|
||||
val objectId: Id,
|
||||
val spaceId: Id,
|
||||
val currentVersion: Id,
|
||||
val previousVersion: Id
|
||||
)
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.anytypeio.anytype.domain.history
|
||||
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.history.Version
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.base.ResultInteractor
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetVersions @Inject constructor(
|
||||
dispatchers: AppCoroutineDispatchers,
|
||||
private val repo: BlockRepository
|
||||
) : ResultInteractor<GetVersions.Params, List<Version>>(dispatchers.io) {
|
||||
|
||||
override suspend fun doWork(params: Params): List<Version> {
|
||||
val command = Command.VersionHistory.GetVersions(
|
||||
objectId = params.objectId,
|
||||
lastVersion = params.lastVersion,
|
||||
limit = params.limit
|
||||
)
|
||||
return repo.getVersions(command)
|
||||
}
|
||||
|
||||
data class Params(
|
||||
val objectId: Id,
|
||||
val lastVersion: Id,
|
||||
val limit: Int
|
||||
)
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.anytypeio.anytype.domain.history
|
||||
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.base.ResultInteractor
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class SetVersion @Inject constructor(
|
||||
dispatchers: AppCoroutineDispatchers,
|
||||
private val repo: BlockRepository
|
||||
) : ResultInteractor<SetVersion.Params, Unit>(dispatchers.io) {
|
||||
|
||||
override suspend fun doWork(params: Params) {
|
||||
val command = Command.VersionHistory.SetVersion(
|
||||
objectId = params.objectId,
|
||||
versionId = params.versionId
|
||||
)
|
||||
repo.setVersion(command)
|
||||
}
|
||||
|
||||
data class Params(
|
||||
val objectId: Id,
|
||||
val versionId: Id
|
||||
)
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.anytypeio.anytype.domain.history
|
||||
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.base.ResultInteractor
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class ShowVersion @Inject constructor(
|
||||
dispatchers: AppCoroutineDispatchers,
|
||||
private val repo: BlockRepository
|
||||
) : ResultInteractor<ShowVersion.Params, ShowVersionResponse>(dispatchers.io) {
|
||||
|
||||
override suspend fun doWork(params: Params): ShowVersionResponse {
|
||||
val command = Command.VersionHistory.ShowVersion(
|
||||
objectId = params.objectId,
|
||||
versionId = params.versionId,
|
||||
traceId = params.traceId
|
||||
)
|
||||
return repo.showVersion(command)
|
||||
}
|
||||
|
||||
data class Params(
|
||||
val objectId: Id,
|
||||
val versionId: Id,
|
||||
val traceId: Id
|
||||
)
|
||||
}
|
|
@ -25,6 +25,9 @@ import com.anytypeio.anytype.core_models.SearchResult
|
|||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.core_models.WidgetLayout
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.Version
|
||||
import com.anytypeio.anytype.core_models.membership.EmailVerificationStatus
|
||||
import com.anytypeio.anytype.core_models.membership.GetPaymentUrlResponse
|
||||
import com.anytypeio.anytype.core_models.membership.Membership
|
||||
|
@ -994,4 +997,20 @@ class BlockMiddleware(
|
|||
override suspend fun processCancel(command: Command.ProcessCancel) {
|
||||
middleware.processCancel(command)
|
||||
}
|
||||
|
||||
override suspend fun getVersions(command: Command.VersionHistory.GetVersions): List<Version> {
|
||||
return middleware.getVersions(command)
|
||||
}
|
||||
|
||||
override suspend fun showVersion(command: Command.VersionHistory.ShowVersion): ShowVersionResponse {
|
||||
return middleware.showVersion(command)
|
||||
}
|
||||
|
||||
override suspend fun setVersion(command: Command.VersionHistory.SetVersion) {
|
||||
middleware.setVersion(command)
|
||||
}
|
||||
|
||||
override suspend fun diffVersions(command: Command.VersionHistory.DiffVersions): DiffVersionResponse {
|
||||
return middleware.diffVersions(command)
|
||||
}
|
||||
}
|
|
@ -31,6 +31,9 @@ import com.anytypeio.anytype.core_models.SearchResult
|
|||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.core_models.WidgetLayout
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.Version
|
||||
import com.anytypeio.anytype.core_models.membership.EmailVerificationStatus
|
||||
import com.anytypeio.anytype.core_models.membership.GetPaymentUrlResponse
|
||||
import com.anytypeio.anytype.core_models.membership.Membership
|
||||
|
@ -2701,6 +2704,55 @@ class Middleware @Inject constructor(
|
|||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
}
|
||||
|
||||
@Throws
|
||||
fun getVersions(command: Command.VersionHistory.GetVersions): List<Version> {
|
||||
val request = Rpc.History.GetVersions.Request(
|
||||
lastVersionId = command.lastVersion,
|
||||
objectId = command.objectId,
|
||||
limit = command.limit
|
||||
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.getVersions(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
return response.versions.map { it.toCoreModel() }
|
||||
}
|
||||
|
||||
@Throws
|
||||
fun showVersion(command: Command.VersionHistory.ShowVersion): ShowVersionResponse {
|
||||
val request = Rpc.History.ShowVersion.Request(
|
||||
versionId = command.versionId
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.showVersion(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
return response.toCoreModel()
|
||||
}
|
||||
|
||||
@Throws
|
||||
fun setVersion(command: Command.VersionHistory.SetVersion) {
|
||||
val request = Rpc.History.SetVersion.Request(
|
||||
versionId = command.versionId
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.setVersion(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
}
|
||||
|
||||
@Throws
|
||||
fun diffVersions(command: Command.VersionHistory.DiffVersions): DiffVersionResponse {
|
||||
val request = Rpc.History.DiffVersions.Request(
|
||||
objectId = command.objectId,
|
||||
spaceId = command.spaceId,
|
||||
currentVersion = command.currentVersion,
|
||||
previousVersion = command.previousVersion
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.diffVersions(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
return response.toCoreModel(context = command.objectId)
|
||||
}
|
||||
|
||||
private fun logRequest(any: Any) {
|
||||
logger.logRequest(any).also {
|
||||
if (BuildConfig.DEBUG && threadInfo.isOnMainThread()) {
|
||||
|
|
|
@ -44,6 +44,9 @@ 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.SpaceUsage
|
||||
import com.anytypeio.anytype.core_models.history.DiffVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.ShowVersionResponse
|
||||
import com.anytypeio.anytype.core_models.history.Version
|
||||
import com.anytypeio.anytype.core_models.membership.EmailVerificationStatus
|
||||
import com.anytypeio.anytype.core_models.membership.Membership
|
||||
import com.anytypeio.anytype.core_models.membership.MembershipPaymentMethod
|
||||
|
@ -1097,3 +1100,31 @@ fun MP2PStatus.toCoreModel(): P2PStatus = when (this) {
|
|||
MP2PStatus.NotPossible -> P2PStatus.NOT_POSSIBLE
|
||||
MP2PStatus.Connected -> P2PStatus.CONNECTED
|
||||
}
|
||||
|
||||
fun Rpc.History.Version.toCoreModel(): Version {
|
||||
return Version(
|
||||
id = id,
|
||||
previousIds = previousIds,
|
||||
authorId = authorId,
|
||||
authorName = authorName,
|
||||
timestamp = time,
|
||||
groupId = groupId
|
||||
)
|
||||
}
|
||||
|
||||
fun Rpc.History.ShowVersion.Response.toCoreModel(): ShowVersionResponse {
|
||||
return ShowVersionResponse(
|
||||
objectView = objectView?.toCore(),
|
||||
version = version?.toCoreModel(),
|
||||
traceId = traceId
|
||||
)
|
||||
}
|
||||
|
||||
fun Rpc.History.DiffVersions.Response.toCoreModel(
|
||||
context: Id
|
||||
): DiffVersionResponse {
|
||||
return DiffVersionResponse(
|
||||
historyEvents = historyEvents.mapNotNull { it.toCoreModels(context) },
|
||||
objectView = objectView?.toCore()
|
||||
)
|
||||
}
|
|
@ -576,4 +576,18 @@ interface MiddlewareService {
|
|||
@Throws(Exception::class)
|
||||
fun membershipGetTiers(request: Rpc.Membership.GetTiers.Request): Rpc.Membership.GetTiers.Response
|
||||
//endregion
|
||||
|
||||
//region VERSION HISTORY
|
||||
@Throws(Exception::class)
|
||||
fun getVersions(request: Rpc.History.GetVersions.Request): Rpc.History.GetVersions.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun showVersion(request: Rpc.History.ShowVersion.Request): Rpc.History.ShowVersion.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun setVersion(request: Rpc.History.SetVersion.Request): Rpc.History.SetVersion.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun diffVersions(request: Rpc.History.DiffVersions.Request): Rpc.History.DiffVersions.Response
|
||||
//endregion
|
||||
}
|
|
@ -2130,4 +2130,56 @@ class MiddlewareServiceImplementation @Inject constructor(
|
|||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun getVersions(request: Rpc.History.GetVersions.Request): Rpc.History.GetVersions.Response {
|
||||
val encoded = Service.historyGetVersions(
|
||||
Rpc.History.GetVersions.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.History.GetVersions.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.History.GetVersions.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun showVersion(request: Rpc.History.ShowVersion.Request): Rpc.History.ShowVersion.Response {
|
||||
val encoded = Service.historyShowVersion(
|
||||
Rpc.History.ShowVersion.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.History.ShowVersion.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.History.ShowVersion.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun setVersion(request: Rpc.History.SetVersion.Request): Rpc.History.SetVersion.Response {
|
||||
val encoded = Service.historySetVersion(
|
||||
Rpc.History.SetVersion.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.History.SetVersion.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.History.SetVersion.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun diffVersions(request: Rpc.History.DiffVersions.Request): Rpc.History.DiffVersions.Response {
|
||||
val encoded = Service.historyDiffVersions(
|
||||
Rpc.History.DiffVersions.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.History.DiffVersions.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.History.DiffVersions.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue