Objects & sets | Refact | Archive / restore (#1790)
This commit is contained in:
parent
6b38195a91
commit
7e6bea9833
|
@ -27,6 +27,7 @@ import com.anytypeio.anytype.domain.download.DownloadFile
|
|||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.icon.DocumentEmojiIconProvider
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.*
|
||||
import com.anytypeio.anytype.domain.page.bookmark.SetupBookmark
|
||||
import com.anytypeio.anytype.domain.page.navigation.GetListPages
|
||||
|
@ -58,7 +59,7 @@ import org.mockito.kotlin.stub
|
|||
open class EditorTestSetup {
|
||||
|
||||
lateinit var createObject: CreateObject
|
||||
lateinit var archiveDocument: ArchiveDocument
|
||||
lateinit var setObjectIsArchived: SetObjectIsArchived
|
||||
lateinit var createDocument: CreateDocument
|
||||
lateinit var downloadFile: DownloadFile
|
||||
lateinit var undo: Undo
|
||||
|
@ -186,7 +187,7 @@ open class EditorTestSetup {
|
|||
|
||||
splitBlock = SplitBlock(repo)
|
||||
createPage = CreatePage(repo, documentEmojiIconProvider)
|
||||
archiveDocument = ArchiveDocument(repo)
|
||||
setObjectIsArchived = SetObjectIsArchived(repo)
|
||||
createDocument = CreateDocument(repo, documentEmojiIconProvider)
|
||||
undo = Undo(repo)
|
||||
redo = Redo(repo)
|
||||
|
@ -236,7 +237,7 @@ open class EditorTestSetup {
|
|||
createPage = createPage,
|
||||
createObject = createObject,
|
||||
documentEventReducer = DocumentExternalEventReducer(),
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
createDocument = createDocument,
|
||||
urlBuilder = urlBuilder,
|
||||
renderer = DefaultBlockViewRenderer(
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.anytypeio.anytype.di.feature
|
|||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.page.ArchiveDocument
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.CloseBlock
|
||||
import com.anytypeio.anytype.domain.page.OpenPage
|
||||
import com.anytypeio.anytype.presentation.editor.DocumentExternalEventReducer
|
||||
|
@ -43,7 +43,7 @@ object ArchiveModule {
|
|||
fun provideArchiveViewModelFactory(
|
||||
openPage: OpenPage,
|
||||
closePage: CloseBlock,
|
||||
archiveDocument: ArchiveDocument,
|
||||
setObjectIsArchived: SetObjectIsArchived,
|
||||
interceptEvents: InterceptEvents,
|
||||
renderer: DefaultBlockViewRenderer,
|
||||
selectionStateHolder: SelectionStateHolder,
|
||||
|
@ -53,7 +53,7 @@ object ArchiveModule {
|
|||
): ArchiveViewModelFactory = ArchiveViewModelFactory(
|
||||
openPage = openPage,
|
||||
closePage = closePage,
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
interceptEvents = interceptEvents,
|
||||
renderer = renderer,
|
||||
selectionStateHolder = selectionStateHolder,
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.anytypeio.anytype.domain.event.interactor.EventChannel
|
|||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.icon.DocumentEmojiIconProvider
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.*
|
||||
import com.anytypeio.anytype.domain.page.bookmark.SetupBookmark
|
||||
import com.anytypeio.anytype.domain.page.navigation.GetListPages
|
||||
|
@ -137,7 +138,7 @@ object EditorSessionModule {
|
|||
removeDocCover: RemoveDocCover,
|
||||
urlBuilder: UrlBuilder,
|
||||
renderer: DefaultBlockViewRenderer,
|
||||
archiveDocument: ArchiveDocument,
|
||||
setObjectIsArchived: SetObjectIsArchived,
|
||||
orchestrator: Orchestrator,
|
||||
getListPages: GetListPages,
|
||||
analytics: Analytics,
|
||||
|
@ -162,7 +163,7 @@ object EditorSessionModule {
|
|||
removeDocCover = removeDocCover,
|
||||
urlBuilder = urlBuilder,
|
||||
renderer = renderer,
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
orchestrator = orchestrator,
|
||||
getListPages = getListPages,
|
||||
analytics = analytics,
|
||||
|
@ -553,7 +554,7 @@ object EditorUseCaseModule {
|
|||
@PerScreen
|
||||
fun provideArchiveDocumentUseCase(
|
||||
repo: BlockRepository
|
||||
): ArchiveDocument = ArchiveDocument(
|
||||
): SetObjectIsArchived = SetObjectIsArchived(
|
||||
repo = repo
|
||||
)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.anytypeio.anytype.core_utils.di.scope.PerDialog
|
|||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.dashboard.interactor.AddToFavorite
|
||||
import com.anytypeio.anytype.domain.dashboard.interactor.RemoveFromFavorite
|
||||
import com.anytypeio.anytype.domain.page.ArchiveDocument
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.presentation.editor.Editor
|
||||
import com.anytypeio.anytype.presentation.objects.ObjectMenuViewModel
|
||||
import com.anytypeio.anytype.presentation.objects.ObjectSetMenuViewModel
|
||||
|
@ -69,14 +69,14 @@ object ObjectMenuModule {
|
|||
@Provides
|
||||
@PerDialog
|
||||
fun provideViewModelFactory(
|
||||
archiveDocument: ArchiveDocument,
|
||||
setObjectIsArchived: SetObjectIsArchived,
|
||||
addToFavorite: AddToFavorite,
|
||||
removeFromFavorite: RemoveFromFavorite,
|
||||
storage: Editor.Storage,
|
||||
analytics: Analytics,
|
||||
dispatcher: Dispatcher<Payload>
|
||||
): ObjectMenuViewModel.Factory = ObjectMenuViewModel.Factory(
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
addToFavorite = addToFavorite,
|
||||
removeFromFavorite = removeFromFavorite,
|
||||
storage = storage,
|
||||
|
@ -91,14 +91,14 @@ object ObjectSetMenuModule {
|
|||
@Provides
|
||||
@PerDialog
|
||||
fun provideViewModelFactory(
|
||||
archiveDocument: ArchiveDocument,
|
||||
setObjectIsArchived: SetObjectIsArchived,
|
||||
addToFavorite: AddToFavorite,
|
||||
removeFromFavorite: RemoveFromFavorite,
|
||||
analytics: Analytics,
|
||||
state: StateFlow<ObjectSet>,
|
||||
dispatcher: Dispatcher<Payload>
|
||||
): ObjectSetMenuViewModel.Factory = ObjectSetMenuViewModel.Factory(
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
addToFavorite = addToFavorite,
|
||||
removeFromFavorite = removeFromFavorite,
|
||||
analytics = analytics,
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.anytypeio.anytype.domain.dataview.interactor.*
|
|||
import com.anytypeio.anytype.domain.event.interactor.EventChannel
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.page.ArchiveDocument
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.CloseBlock
|
||||
import com.anytypeio.anytype.domain.relations.AddFileToRecord
|
||||
import com.anytypeio.anytype.domain.sets.OpenObjectSet
|
||||
|
@ -265,7 +265,7 @@ object ObjectSetModule {
|
|||
@PerScreen
|
||||
fun provideArchiveDocumentUseCase(
|
||||
repo: BlockRepository
|
||||
): ArchiveDocument = ArchiveDocument(
|
||||
): SetObjectIsArchived = SetObjectIsArchived(
|
||||
repo = repo
|
||||
)
|
||||
}
|
|
@ -7,17 +7,6 @@ sealed class Command {
|
|||
val type: Block.Content.File.Type?
|
||||
)
|
||||
|
||||
/**
|
||||
* Command for archiving a document
|
||||
* @property context id of the context
|
||||
* @property target ids of the targets
|
||||
*/
|
||||
class ArchiveDocument(
|
||||
val context: Id,
|
||||
val target: List<Id>,
|
||||
val isArchived: Boolean
|
||||
)
|
||||
|
||||
/**
|
||||
* Command for turning simple blocks into documents
|
||||
* @property context id of the context
|
||||
|
|
|
@ -181,10 +181,6 @@ class BlockDataRepository(
|
|||
Redo.Result.Exhausted
|
||||
}
|
||||
|
||||
override suspend fun archiveDocument(
|
||||
command: Command.ArchiveDocument
|
||||
) = factory.remote.archiveDocument(command)
|
||||
|
||||
override suspend fun turnIntoDocument(
|
||||
command: Command.TurnIntoDocument
|
||||
): List<Id> = factory.remote.turnIntoDocument(command)
|
||||
|
@ -458,8 +454,13 @@ class BlockDataRepository(
|
|||
relations: List<Id>
|
||||
): Payload = factory.remote.removeFromFeaturedRelations(ctx, relations)
|
||||
|
||||
override fun setIsFavorite(
|
||||
override fun setObjectIsFavorite(
|
||||
ctx: Id,
|
||||
isFavorite: Boolean
|
||||
): Payload = factory.remote.setIsFavorite(ctx = ctx, isFavorite = isFavorite)
|
||||
): Payload = factory.remote.setObjectIsFavorite(ctx = ctx, isFavorite = isFavorite)
|
||||
|
||||
override fun setObjectIsArchived(
|
||||
ctx: Id,
|
||||
isArchived: Boolean
|
||||
): Payload = factory.remote.setObjectIsArchived(ctx = ctx, isArchived = isArchived)
|
||||
}
|
|
@ -42,7 +42,6 @@ interface BlockDataStore {
|
|||
suspend fun setupBookmark(command: Command.SetupBookmark): Payload
|
||||
suspend fun undo(command: Command.Undo): Payload
|
||||
suspend fun redo(command: Command.Redo): Payload
|
||||
suspend fun archiveDocument(command: Command.ArchiveDocument)
|
||||
suspend fun turnIntoDocument(command: Command.TurnIntoDocument): List<Id>
|
||||
suspend fun paste(command: Command.Paste): Response.Clipboard.Paste
|
||||
suspend fun copy(command: Command.Copy): Response.Clipboard.Copy
|
||||
|
@ -172,5 +171,6 @@ interface BlockDataStore {
|
|||
suspend fun addToFeaturedRelations(ctx: Id, relations: List<Id>): Payload
|
||||
suspend fun removeFromFeaturedRelations(ctx: Id, relations: List<Id>): Payload
|
||||
|
||||
fun setIsFavorite(ctx: Id, isFavorite: Boolean) : Payload
|
||||
fun setObjectIsFavorite(ctx: Id, isFavorite: Boolean) : Payload
|
||||
fun setObjectIsArchived(ctx: Id, isArchived: Boolean) : Payload
|
||||
}
|
|
@ -42,7 +42,6 @@ interface BlockRemote {
|
|||
suspend fun setupBookmark(command: Command.SetupBookmark) : Payload
|
||||
suspend fun undo(command: Command.Undo) : Payload
|
||||
suspend fun redo(command: Command.Redo) : Payload
|
||||
suspend fun archiveDocument(command: Command.ArchiveDocument)
|
||||
suspend fun turnIntoDocument(command: Command.TurnIntoDocument): List<Id>
|
||||
suspend fun paste(command: Command.Paste) : Response.Clipboard.Paste
|
||||
suspend fun copy(command: Command.Copy) : Response.Clipboard.Copy
|
||||
|
@ -172,5 +171,6 @@ interface BlockRemote {
|
|||
suspend fun addToFeaturedRelations(ctx: Id, relations: List<Id>): Payload
|
||||
suspend fun removeFromFeaturedRelations(ctx: Id, relations: List<Id>): Payload
|
||||
|
||||
fun setIsFavorite(ctx: Id, isFavorite: Boolean) : Payload
|
||||
fun setObjectIsFavorite(ctx: Id, isFavorite: Boolean) : Payload
|
||||
fun setObjectIsArchived(ctx: Id, isArchived: Boolean) : Payload
|
||||
}
|
|
@ -131,10 +131,6 @@ class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore {
|
|||
|
||||
override suspend fun redo(command: Command.Redo) = remote.redo(command)
|
||||
|
||||
override suspend fun archiveDocument(
|
||||
command: Command.ArchiveDocument
|
||||
) = remote.archiveDocument(command)
|
||||
|
||||
override suspend fun turnIntoDocument(
|
||||
command: Command.TurnIntoDocument
|
||||
): List<Id> = remote.turnIntoDocument(command)
|
||||
|
@ -392,8 +388,13 @@ class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore {
|
|||
relations: List<Id>
|
||||
): Payload = remote.removeFromFeaturedRelations(ctx, relations)
|
||||
|
||||
override fun setIsFavorite(
|
||||
override fun setObjectIsFavorite(
|
||||
ctx: Id,
|
||||
isFavorite: Boolean
|
||||
): Payload = remote.setIsFavorite(ctx = ctx, isFavorite = isFavorite)
|
||||
): Payload = remote.setObjectIsFavorite(ctx = ctx, isFavorite = isFavorite)
|
||||
|
||||
override fun setObjectIsArchived(
|
||||
ctx: Id,
|
||||
isArchived: Boolean
|
||||
): Payload = remote.setObjectIsArchived(ctx = ctx, isArchived = isArchived)
|
||||
}
|
|
@ -14,8 +14,6 @@ interface BlockRepository {
|
|||
suspend fun move(command: Command.Move): Payload
|
||||
suspend fun unlink(command: Command.Unlink): Payload
|
||||
|
||||
suspend fun archiveDocument(command: Command.ArchiveDocument)
|
||||
|
||||
suspend fun turnIntoDocument(command: Command.TurnIntoDocument): List<Id>
|
||||
|
||||
/**
|
||||
|
@ -227,5 +225,6 @@ interface BlockRepository {
|
|||
suspend fun addToFeaturedRelations(ctx: Id, relations: List<Id>): Payload
|
||||
suspend fun removeFromFeaturedRelations(ctx: Id, relations: List<Id>): Payload
|
||||
|
||||
fun setIsFavorite(ctx: Id, isFavorite: Boolean) : Payload
|
||||
fun setObjectIsFavorite(ctx: Id, isFavorite: Boolean) : Payload
|
||||
fun setObjectIsArchived(ctx: Id, isArchived: Boolean) : Payload
|
||||
}
|
|
@ -13,7 +13,7 @@ class AddToFavorite(
|
|||
) : BaseUseCase<Payload, AddToFavorite.Params>() {
|
||||
|
||||
override suspend fun run(params: Params) = safe {
|
||||
repo.setIsFavorite(ctx = params.target, isFavorite = true)
|
||||
repo.setObjectIsFavorite(ctx = params.target, isFavorite = true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,7 @@ class RemoveFromFavorite(
|
|||
) : BaseUseCase<Payload, RemoveFromFavorite.Params>() {
|
||||
|
||||
override suspend fun run(params: Params) = safe {
|
||||
repo.setIsFavorite(ctx = params.target, isFavorite = false)
|
||||
repo.setObjectIsFavorite(ctx = params.target, isFavorite = false)
|
||||
}
|
||||
|
||||
class Params(val target: Id)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.anytypeio.anytype.domain.objects
|
||||
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
|
||||
/**
|
||||
* Use-case for archiving (or restoring from archive) an object.
|
||||
*/
|
||||
class SetObjectIsArchived(
|
||||
private val repo: BlockRepository
|
||||
) : BaseUseCase<Payload, SetObjectIsArchived.Params>() {
|
||||
|
||||
override suspend fun run(params: Params) = safe {
|
||||
repo.setObjectIsArchived(
|
||||
ctx = params.context,
|
||||
isArchived = params.isArchived
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Params for archiving a document
|
||||
* @property context id of the context
|
||||
*/
|
||||
data class Params(
|
||||
val context: Id,
|
||||
val isArchived: Boolean
|
||||
)
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.page
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
|
||||
/**
|
||||
* Use-case for archiving a document
|
||||
*/
|
||||
class ArchiveDocument(
|
||||
private val repo: BlockRepository
|
||||
) : BaseUseCase<Unit, ArchiveDocument.Params>() {
|
||||
|
||||
override suspend fun run(params: Params) = try {
|
||||
repo.archiveDocument(
|
||||
command = Command.ArchiveDocument(
|
||||
context = params.context,
|
||||
target = params.targets,
|
||||
isArchived = params.isArchived
|
||||
)
|
||||
).let {
|
||||
Either.Right(it)
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
Either.Left(t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Params for archiving a document
|
||||
* @property context id of the context
|
||||
* @property targets list of ids of the targets (document we want to change archive status)
|
||||
* @property isArchived defines whether we archived or unarchive our document
|
||||
*/
|
||||
data class Params(
|
||||
val context: Id,
|
||||
val targets: List<Id>,
|
||||
val isArchived: Boolean
|
||||
)
|
||||
}
|
|
@ -153,10 +153,6 @@ class BlockMiddleware(
|
|||
command: Command.Redo
|
||||
): Payload = middleware.redo(command)
|
||||
|
||||
override suspend fun archiveDocument(
|
||||
command: Command.ArchiveDocument
|
||||
) = middleware.archiveDocument(command)
|
||||
|
||||
override suspend fun turnIntoDocument(
|
||||
command: Command.TurnIntoDocument
|
||||
): List<String> = middleware.turnIntoDocument(command)
|
||||
|
@ -420,8 +416,13 @@ class BlockMiddleware(
|
|||
relations: List<Id>
|
||||
): Payload = middleware.removeFromFeaturedRelations(ctx, relations)
|
||||
|
||||
override fun setIsFavorite(
|
||||
override fun setObjectIsFavorite(
|
||||
ctx: Id,
|
||||
isFavorite: Boolean
|
||||
): Payload = middleware.setIsFavorite(ctx = ctx, isFavorite = isFavorite)
|
||||
): Payload = middleware.setObjectIsFavorite(ctx = ctx, isFavorite = isFavorite)
|
||||
|
||||
override fun setObjectIsArchived(
|
||||
ctx: Id,
|
||||
isArchived: Boolean
|
||||
): Payload = middleware.setObjectIsArchived(ctx = ctx, isArchived = isArchived)
|
||||
}
|
|
@ -746,18 +746,6 @@ class Middleware(
|
|||
return response.event.toPayload()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun archiveDocument(command: Command.ArchiveDocument) {
|
||||
val request: BlockList.Set.Page.IsArchived.Request = BlockList.Set.Page.IsArchived.Request(
|
||||
contextId = command.context,
|
||||
blockIds = command.target,
|
||||
isArchived = command.isArchived
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.blockListSetPageIsArchived(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun turnIntoDocument(command: Command.TurnIntoDocument): List<String> {
|
||||
val request = BlockList.ConvertChildrenToPages.Request(
|
||||
|
@ -1420,7 +1408,7 @@ class Middleware(
|
|||
return response.event.toPayload()
|
||||
}
|
||||
|
||||
fun setIsFavorite(
|
||||
fun setObjectIsFavorite(
|
||||
ctx: Id,
|
||||
isFavorite: Boolean
|
||||
) : Payload {
|
||||
|
@ -1429,7 +1417,21 @@ class Middleware(
|
|||
isFavorite = isFavorite
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.setIsFavorite(request)
|
||||
val response = service.objectSetIsFavorite(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
return response.event.toPayload()
|
||||
}
|
||||
|
||||
fun setObjectIsArchived(
|
||||
ctx: Id,
|
||||
isArchived: Boolean
|
||||
) : Payload {
|
||||
val request = Rpc.Object.SetIsArchived.Request(
|
||||
contextId = ctx,
|
||||
isArchived = isArchived
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.objectSetIsArchived(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
return response.event.toPayload()
|
||||
}
|
||||
|
|
|
@ -196,5 +196,8 @@ interface MiddlewareService {
|
|||
fun featuredRelationsRemove(request: Object.FeaturedRelation.Remove.Request): Object.FeaturedRelation.Remove.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun setIsFavorite(request: Object.SetIsFavorite.Request): Object.SetIsFavorite.Response
|
||||
fun objectSetIsFavorite(request: Object.SetIsFavorite.Request): Object.SetIsFavorite.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun objectSetIsArchived(request: Object.SetIsArchived.Request): Object.SetIsArchived.Response
|
||||
}
|
|
@ -770,7 +770,7 @@ class MiddlewareServiceImplementation : MiddlewareService {
|
|||
}
|
||||
}
|
||||
|
||||
override fun setIsFavorite(request: Object.SetIsFavorite.Request): Object.SetIsFavorite.Response {
|
||||
override fun objectSetIsFavorite(request: Object.SetIsFavorite.Request): Object.SetIsFavorite.Response {
|
||||
val encoded = Service.objectSetIsFavorite(
|
||||
Object.SetIsFavorite.Request.ADAPTER.encode(request)
|
||||
)
|
||||
|
@ -782,4 +782,17 @@ class MiddlewareServiceImplementation : MiddlewareService {
|
|||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun objectSetIsArchived(request: Object.SetIsArchived.Request): Object.SetIsArchived.Response {
|
||||
val encoded = Service.objectSetIsFavorite(
|
||||
Object.SetIsArchived.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Object.SetIsArchived.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Object.SetIsArchived.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,6 +46,7 @@ import com.anytypeio.anytype.domain.editor.Editor
|
|||
import com.anytypeio.anytype.domain.error.Error
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.*
|
||||
import com.anytypeio.anytype.domain.page.navigation.GetListPages
|
||||
import com.anytypeio.anytype.domain.status.InterceptThreadStatus
|
||||
|
@ -116,7 +117,7 @@ class EditorViewModel(
|
|||
private val createDocument: CreateDocument,
|
||||
private val createObject: CreateObject,
|
||||
private val createNewDocument: CreateNewDocument,
|
||||
private val archiveDocument: ArchiveDocument,
|
||||
private val setObjectIsArchived: SetObjectIsArchived,
|
||||
private val interceptEvents: InterceptEvents,
|
||||
private val interceptThreadStatus: InterceptThreadStatus,
|
||||
private val updateLinkMarks: UpdateLinkMarks,
|
||||
|
@ -2780,10 +2781,9 @@ class EditorViewModel(
|
|||
Timber.d("onArchiveThisPageClicked, ")
|
||||
dispatch(command = Command.CloseKeyboard)
|
||||
viewModelScope.launch {
|
||||
archiveDocument(
|
||||
ArchiveDocument.Params(
|
||||
setObjectIsArchived(
|
||||
SetObjectIsArchived.Params(
|
||||
context = context,
|
||||
targets = listOf(context),
|
||||
isArchived = isArchived
|
||||
)
|
||||
).proceed(
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.anytypeio.anytype.domain.cover.SetDocCoverImage
|
|||
import com.anytypeio.anytype.domain.dataview.interactor.GetCompatibleObjectTypes
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.*
|
||||
import com.anytypeio.anytype.domain.page.navigation.GetListPages
|
||||
import com.anytypeio.anytype.domain.status.InterceptThreadStatus
|
||||
|
@ -31,7 +32,7 @@ open class EditorViewModelFactory(
|
|||
private val createDocument: CreateDocument,
|
||||
private val createObject: CreateObject,
|
||||
private val createNewDocument: CreateNewDocument,
|
||||
private val archiveDocument: ArchiveDocument,
|
||||
private val setObjectIsArchived: SetObjectIsArchived,
|
||||
private val setDocCoverImage: SetDocCoverImage,
|
||||
private val removeDocCover: RemoveDocCover,
|
||||
private val interceptEvents: InterceptEvents,
|
||||
|
@ -56,7 +57,7 @@ open class EditorViewModelFactory(
|
|||
return EditorViewModel(
|
||||
openPage = openPage,
|
||||
closePage = closeObject,
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
interceptEvents = interceptEvents,
|
||||
interceptThreadStatus = interceptThreadStatus,
|
||||
updateLinkMarks = updateLinkMarks,
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.anytypeio.anytype.core_models.Document
|
|||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ext.asMap
|
||||
import com.anytypeio.anytype.core_models.ext.content
|
||||
import com.anytypeio.anytype.core_utils.common.EventWrapper
|
||||
import com.anytypeio.anytype.core_utils.ext.switchToLatestFrom
|
||||
import com.anytypeio.anytype.core_utils.ext.withLatestFrom
|
||||
|
@ -18,7 +17,7 @@ import com.anytypeio.anytype.domain.base.Result
|
|||
import com.anytypeio.anytype.domain.editor.Editor
|
||||
import com.anytypeio.anytype.domain.error.Error
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.page.ArchiveDocument
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.CloseBlock
|
||||
import com.anytypeio.anytype.domain.page.OpenPage
|
||||
import com.anytypeio.anytype.presentation.common.StateReducer
|
||||
|
@ -49,7 +48,7 @@ sealed class ArchiveViewState {
|
|||
class ArchiveViewModel(
|
||||
private val openPage: OpenPage,
|
||||
private val closePage: CloseBlock,
|
||||
private val archiveDocument: ArchiveDocument,
|
||||
private val setObjectIsArchived: SetObjectIsArchived,
|
||||
private val interceptEvents: InterceptEvents,
|
||||
private val renderer: DefaultBlockViewRenderer,
|
||||
private val reducer: StateReducer<List<Block>, Event>,
|
||||
|
@ -197,31 +196,32 @@ class ArchiveViewModel(
|
|||
}
|
||||
|
||||
fun onPutBackClicked() {
|
||||
val selectedBlocks = selectionStateHolder.currentSelection().toList()
|
||||
if (selectedBlocks.isNotEmpty()) {
|
||||
val targets = mutableListOf<Id>()
|
||||
selectedBlocks.forEach { id ->
|
||||
targets.add(
|
||||
blocks.first { it.id == id }.content<Block.Content.Link>().target
|
||||
)
|
||||
}
|
||||
selectionStateHolder.clearSelections()
|
||||
viewModelScope.launch {
|
||||
archiveDocument(
|
||||
ArchiveDocument.Params(
|
||||
context = context,
|
||||
targets = targets,
|
||||
isArchived = false
|
||||
)
|
||||
).proceed(
|
||||
failure = { Timber.e(it, "Error while archiving page") },
|
||||
success = {
|
||||
Timber.d("Success to unarchive pages!")
|
||||
selectionStateHolder.clearSelections()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
// TODO Will be implemented later.
|
||||
// val selectedBlocks = selectionStateHolder.currentSelection().toList()
|
||||
// if (selectedBlocks.isNotEmpty()) {
|
||||
// val targets = mutableListOf<Id>()
|
||||
// selectedBlocks.forEach { id ->
|
||||
// targets.add(
|
||||
// blocks.first { it.id == id }.content<Block.Content.Link>().target
|
||||
// )
|
||||
// }
|
||||
// selectionStateHolder.clearSelections()
|
||||
// viewModelScope.launch {
|
||||
// setObjectIsArchived(
|
||||
// SetObjectIsArchived.Params(
|
||||
// context = context,
|
||||
// targets = targets,
|
||||
// isArchived = false
|
||||
// )
|
||||
// ).proceed(
|
||||
// failure = { Timber.e(it, "Error while archiving page") },
|
||||
// success = {
|
||||
// Timber.d("Success to unarchive pages!")
|
||||
// selectionStateHolder.clearSelections()
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fun onPageClicked(click: ListenerType) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.anytypeio.anytype.analytics.base.Analytics
|
|||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.page.ArchiveDocument
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.CloseBlock
|
||||
import com.anytypeio.anytype.domain.page.OpenPage
|
||||
import com.anytypeio.anytype.presentation.common.StateReducer
|
||||
|
@ -17,7 +17,7 @@ import com.anytypeio.anytype.presentation.editor.selection.SelectionStateHolder
|
|||
open class ArchiveViewModelFactory(
|
||||
private val openPage: OpenPage,
|
||||
private val closePage: CloseBlock,
|
||||
private val archiveDocument: ArchiveDocument,
|
||||
private val setObjectIsArchived: SetObjectIsArchived,
|
||||
private val interceptEvents: InterceptEvents,
|
||||
private val renderer: DefaultBlockViewRenderer,
|
||||
private val reducer: StateReducer<List<Block>, Event>,
|
||||
|
@ -31,7 +31,7 @@ open class ArchiveViewModelFactory(
|
|||
return ArchiveViewModel(
|
||||
openPage = openPage,
|
||||
closePage = closePage,
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
interceptEvents = interceptEvents,
|
||||
renderer = renderer,
|
||||
reducer = reducer,
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.anytypeio.anytype.core_models.Payload
|
|||
import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction
|
||||
import com.anytypeio.anytype.domain.dashboard.interactor.AddToFavorite
|
||||
import com.anytypeio.anytype.domain.dashboard.interactor.RemoveFromFavorite
|
||||
import com.anytypeio.anytype.domain.page.ArchiveDocument
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.presentation.common.BaseViewModel
|
||||
import com.anytypeio.anytype.presentation.editor.Editor
|
||||
import com.anytypeio.anytype.presentation.sets.ObjectSet
|
||||
|
@ -23,7 +23,7 @@ import kotlinx.coroutines.launch
|
|||
import timber.log.Timber
|
||||
|
||||
abstract class ObjectMenuViewModelBase(
|
||||
private val archiveDocument: ArchiveDocument,
|
||||
private val setObjectIsArchived: SetObjectIsArchived,
|
||||
private val addToFavorite: AddToFavorite,
|
||||
private val removeFromFavorite: RemoveFromFavorite,
|
||||
private val dispatcher: Dispatcher<Payload>
|
||||
|
@ -106,11 +106,10 @@ abstract class ObjectMenuViewModelBase(
|
|||
|
||||
fun proceedWithUpdatingArchivedStatus(ctx: Id, isArchived: Boolean) {
|
||||
viewModelScope.launch {
|
||||
archiveDocument(
|
||||
ArchiveDocument.Params(
|
||||
setObjectIsArchived(
|
||||
SetObjectIsArchived.Params(
|
||||
context = ctx,
|
||||
isArchived = isArchived,
|
||||
targets = listOf(ctx)
|
||||
isArchived = isArchived
|
||||
)
|
||||
).process(
|
||||
failure = {
|
||||
|
@ -153,14 +152,14 @@ abstract class ObjectMenuViewModelBase(
|
|||
}
|
||||
|
||||
class ObjectMenuViewModel(
|
||||
archiveDocument: ArchiveDocument,
|
||||
setObjectIsArchived: SetObjectIsArchived,
|
||||
addToFavorite: AddToFavorite,
|
||||
removeFromFavorite: RemoveFromFavorite,
|
||||
storage: Editor.Storage,
|
||||
dispatcher: Dispatcher<Payload>,
|
||||
private val analytics: Analytics
|
||||
) : ObjectMenuViewModelBase(
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
addToFavorite = addToFavorite,
|
||||
removeFromFavorite = removeFromFavorite,
|
||||
dispatcher = dispatcher
|
||||
|
@ -266,7 +265,7 @@ class ObjectMenuViewModel(
|
|||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class Factory(
|
||||
private val archiveDocument: ArchiveDocument,
|
||||
private val setObjectIsArchived: SetObjectIsArchived,
|
||||
private val addToFavorite: AddToFavorite,
|
||||
private val removeFromFavorite: RemoveFromFavorite,
|
||||
private val storage: Editor.Storage,
|
||||
|
@ -275,7 +274,7 @@ class ObjectMenuViewModel(
|
|||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
return ObjectMenuViewModel(
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
addToFavorite = addToFavorite,
|
||||
removeFromFavorite = removeFromFavorite,
|
||||
storage = storage,
|
||||
|
@ -287,14 +286,14 @@ class ObjectMenuViewModel(
|
|||
}
|
||||
|
||||
class ObjectSetMenuViewModel(
|
||||
archiveDocument: ArchiveDocument,
|
||||
setObjectIsArchived: SetObjectIsArchived,
|
||||
addToFavorite: AddToFavorite,
|
||||
removeFromFavorite: RemoveFromFavorite,
|
||||
dispatcher: Dispatcher<Payload>,
|
||||
private val analytics: Analytics,
|
||||
state: StateFlow<ObjectSet>
|
||||
) : ObjectMenuViewModelBase(
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
addToFavorite = addToFavorite,
|
||||
removeFromFavorite = removeFromFavorite,
|
||||
dispatcher = dispatcher
|
||||
|
@ -304,7 +303,7 @@ class ObjectSetMenuViewModel(
|
|||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class Factory(
|
||||
private val archiveDocument: ArchiveDocument,
|
||||
private val setObjectIsArchived: SetObjectIsArchived,
|
||||
private val addToFavorite: AddToFavorite,
|
||||
private val removeFromFavorite: RemoveFromFavorite,
|
||||
private val dispatcher: Dispatcher<Payload>,
|
||||
|
@ -313,7 +312,7 @@ class ObjectSetMenuViewModel(
|
|||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
return ObjectSetMenuViewModel(
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
addToFavorite = addToFavorite,
|
||||
removeFromFavorite = removeFromFavorite,
|
||||
analytics = analytics,
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.anytypeio.anytype.domain.dataview.interactor.SetRelationKey
|
|||
import com.anytypeio.anytype.domain.download.DownloadFile
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.*
|
||||
import com.anytypeio.anytype.domain.page.bookmark.SetupBookmark
|
||||
import com.anytypeio.anytype.domain.page.navigation.GetListPages
|
||||
|
@ -180,7 +181,7 @@ open class EditorViewModelTest {
|
|||
lateinit var createNewDocument: CreateNewDocument
|
||||
|
||||
@Mock
|
||||
lateinit var archiveDocument: ArchiveDocument
|
||||
lateinit var setObjectIsArchived: SetObjectIsArchived
|
||||
|
||||
@Mock
|
||||
lateinit var replaceBlock: ReplaceBlock
|
||||
|
@ -3053,12 +3054,11 @@ open class EditorViewModelTest {
|
|||
vm.onArchiveThisObjectClicked()
|
||||
|
||||
runBlockingTest {
|
||||
verify(archiveDocument, times(1)).invoke(
|
||||
verify(setObjectIsArchived, times(1)).invoke(
|
||||
params = eq(
|
||||
ArchiveDocument.Params(
|
||||
SetObjectIsArchived.Params(
|
||||
context = root,
|
||||
targets = listOf(root),
|
||||
isArchived = true
|
||||
isArchived = true
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -3114,11 +3114,10 @@ open class EditorViewModelTest {
|
|||
vm.onArchiveThisObjectClicked()
|
||||
|
||||
runBlockingTest {
|
||||
verify(archiveDocument, times(1)).invoke(
|
||||
verify(setObjectIsArchived, times(1)).invoke(
|
||||
params = eq(
|
||||
ArchiveDocument.Params(
|
||||
SetObjectIsArchived.Params(
|
||||
context = root,
|
||||
targets = listOf(root),
|
||||
isArchived = true
|
||||
)
|
||||
)
|
||||
|
@ -3135,15 +3134,19 @@ open class EditorViewModelTest {
|
|||
}
|
||||
|
||||
private fun stubArchiveDocument(
|
||||
params: ArchiveDocument.Params =
|
||||
ArchiveDocument.Params(
|
||||
params: SetObjectIsArchived.Params =
|
||||
SetObjectIsArchived.Params(
|
||||
context = root,
|
||||
targets = listOf(root),
|
||||
isArchived = true
|
||||
)
|
||||
) {
|
||||
archiveDocument.stub {
|
||||
onBlocking { invoke(params = params) } doReturn Either.Right(Unit)
|
||||
setObjectIsArchived.stub {
|
||||
onBlocking { invoke(params = params) } doReturn Either.Right(
|
||||
Payload(
|
||||
context = root,
|
||||
events = emptyList()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3917,7 +3920,7 @@ open class EditorViewModelTest {
|
|||
counter = Counter.Default(),
|
||||
coverImageHashProvider = coverImageHashProvider
|
||||
),
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
createDocument = createDocument,
|
||||
createNewDocument = createNewDocument,
|
||||
analytics = analytics,
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.anytypeio.anytype.domain.dataview.interactor.SetRelationKey
|
|||
import com.anytypeio.anytype.domain.download.DownloadFile
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.*
|
||||
import com.anytypeio.anytype.domain.page.bookmark.SetupBookmark
|
||||
import com.anytypeio.anytype.domain.page.navigation.GetListPages
|
||||
|
@ -156,7 +157,7 @@ open class EditorPresentationTestSetup {
|
|||
lateinit var createNewDocument: CreateNewDocument
|
||||
|
||||
@Mock
|
||||
lateinit var archiveDocument: ArchiveDocument
|
||||
lateinit var setObjectIsArchived: SetObjectIsArchived
|
||||
|
||||
@Mock
|
||||
lateinit var replaceBlock: ReplaceBlock
|
||||
|
@ -264,7 +265,7 @@ open class EditorPresentationTestSetup {
|
|||
counter = Counter.Default(),
|
||||
coverImageHashProvider = coverImageHashProvider
|
||||
),
|
||||
archiveDocument = archiveDocument,
|
||||
setObjectIsArchived = setObjectIsArchived,
|
||||
createDocument = createDocument,
|
||||
createNewDocument = createNewDocument,
|
||||
analytics = analytics,
|
||||
|
|
Loading…
Reference in New Issue
Block a user