diff --git a/Anytype.xcodeproj/project.pbxproj b/Anytype.xcodeproj/project.pbxproj index 405627a180..845f463ced 100644 --- a/Anytype.xcodeproj/project.pbxproj +++ b/Anytype.xcodeproj/project.pbxproj @@ -1056,6 +1056,7 @@ 2E8825772C5A5B7E00FD59D3 /* VersionHistoryCoordinatorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E8825762C5A5B7E00FD59D3 /* VersionHistoryCoordinatorViewModel.swift */; }; 2E88257A2C5A61A200FD59D3 /* ObjectVersionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E8825792C5A61A200FD59D3 /* ObjectVersionView.swift */; }; 2E88257C2C5A61AC00FD59D3 /* ObjectVersionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E88257B2C5A61AC00FD59D3 /* ObjectVersionViewModel.swift */; }; + 2E88257E2C5BDF0D00FD59D3 /* DocumentMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E88257D2C5BDF0D00FD59D3 /* DocumentMode.swift */; }; 2E92219D294B8B5000968750 /* DataViewBlockViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E92219C294B8B5000968750 /* DataViewBlockViewModel.swift */; }; 2E92219F294B8CDE00968750 /* DataViewBlockConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E92219E294B8CDE00968750 /* DataViewBlockConfiguration.swift */; }; 2E9221A1294B8D4900968750 /* DataViewBlockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E9221A0294B8D4900968750 /* DataViewBlockView.swift */; }; @@ -2916,6 +2917,7 @@ 2E8825762C5A5B7E00FD59D3 /* VersionHistoryCoordinatorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionHistoryCoordinatorViewModel.swift; sourceTree = ""; }; 2E8825792C5A61A200FD59D3 /* ObjectVersionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectVersionView.swift; sourceTree = ""; }; 2E88257B2C5A61AC00FD59D3 /* ObjectVersionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectVersionViewModel.swift; sourceTree = ""; }; + 2E88257D2C5BDF0D00FD59D3 /* DocumentMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentMode.swift; sourceTree = ""; }; 2E92219C294B8B5000968750 /* DataViewBlockViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataViewBlockViewModel.swift; sourceTree = ""; }; 2E92219E294B8CDE00968750 /* DataViewBlockConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataViewBlockConfiguration.swift; sourceTree = ""; }; 2E9221A0294B8D4900968750 /* DataViewBlockView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataViewBlockView.swift; sourceTree = ""; }; @@ -4198,6 +4200,7 @@ 2AEAEE532C077C9D0060FE4C /* BaseDocumentProtocol+Sync.swift */, 2AEAEE572C08AB7E0060FE4C /* BaseDocumentUpdate.swift */, 2A12F0A12C11B0DD00E866BA /* Relation+DependedObject.swift */, + 2E88257D2C5BDF0D00FD59D3 /* DocumentMode.swift */, ); path = Document; sourceTree = ""; @@ -11844,6 +11847,7 @@ 2E0D0F712938CFE200674D3F /* DataviewGroupOrder+Update.swift in Sources */, 3D07ECE9261B735300C007E2 /* UINavigationController+UIGestureRecognizerDelegate.swift in Sources */, 535E02AD274FF0B100E1AF8C /* RelationValueView.swift in Sources */, + 2E88257E2C5BDF0D00FD59D3 /* DocumentMode.swift in Sources */, 3D547B852B988BDE000B030A /* MembershipTierSuccessView.swift in Sources */, 2A0F6C402BF219BA0041176E /* SpacePermissions.swift in Sources */, 2EA9D72B2B3093FE001CF0DE /* EventsBunch.swift in Sources */, diff --git a/Anytype/Sources/Models/Documents/Document/BaseDocument.swift b/Anytype/Sources/Models/Documents/Document/BaseDocument.swift index 06d03a2668..847fda4403 100644 --- a/Anytype/Sources/Models/Documents/Document/BaseDocument.swift +++ b/Anytype/Sources/Models/Documents/Document/BaseDocument.swift @@ -13,7 +13,8 @@ final class BaseDocument: BaseDocumentProtocol { // MARK: - Local state let objectId: String - let forPreview: Bool + let mode: DocumentMode + @Atomic private(set) var children = [BlockInformation]() @Atomic @@ -36,6 +37,8 @@ final class BaseDocument: BaseDocumentProtocol { private var relationBuilder: any RelationsBuilderProtocol @Injected(\.syncStatusStorage) private var syncStatusStorage: any SyncStatusStorageProtocol + @Injected(\.historyVersionsService) + private var historyVersionsService: any HistoryVersionsServiceProtocol private let relationDetailsStorage: any RelationDetailsStorageProtocol private let objectTypeProvider: any ObjectTypeProviderProtocol private let accountParticipantsStorage: any AccountParticipantsStorageProtocol @@ -59,7 +62,7 @@ final class BaseDocument: BaseDocumentProtocol { init( objectId: String, - forPreview: Bool, + mode: DocumentMode, objectLifecycleService: some ObjectLifecycleServiceProtocol, relationDetailsStorage: some RelationDetailsStorageProtocol, objectTypeProvider: some ObjectTypeProviderProtocol, @@ -72,7 +75,7 @@ final class BaseDocument: BaseDocumentProtocol { detailsStorage: ObjectDetailsStorage ) { self.objectId = objectId - self.forPreview = forPreview + self.mode = mode self.eventsListener = eventsListener self.viewModelSetter = viewModelSetter self.objectLifecycleService = objectLifecycleService @@ -88,7 +91,7 @@ final class BaseDocument: BaseDocumentProtocol { } deinit { - guard !forPreview, isOpened, UserDefaultsConfig.usersId.isNotEmpty else { return } + guard mode.isHandling, isOpened, UserDefaultsConfig.usersId.isNotEmpty else { return } Task.detached(priority: .userInitiated) { [objectLifecycleService, objectId] in try await objectLifecycleService.close(contextId: objectId) } @@ -102,30 +105,33 @@ final class BaseDocument: BaseDocumentProtocol { @MainActor func open() async throws { - if isOpened { - return - } - guard !forPreview else { - anytypeAssertionFailure("Document created for preview. You should use openForPreview() method.") - return + switch mode { + case .handling: + guard !isOpened else { return } + let model = try await objectLifecycleService.open(contextId: objectId) + setupView(model) + case .preview: + try await updateDocumentPreview() + case .version(let versionId): + try await updateDocumentVersion(versionId) } - let model = try await objectLifecycleService.open(contextId: objectId) - setupView(model) } @MainActor - func openForPreview() async throws { - guard forPreview else { - anytypeAssertionFailure("Document created for handling. You should use open() method.") - return + func update() async throws { + switch mode { + case .handling: + anytypeAssertionFailure("Document was created in `handling` mode. You can't update it") + case .preview: + try await updateDocumentPreview() + case .version(let versionId): + try await updateDocumentVersion(versionId) } - let model = try await objectLifecycleService.openForPreview(contextId: objectId) - setupView(model) } @MainActor func close() async throws { - guard !forPreview, isOpened, UserDefaultsConfig.usersId.isNotEmpty else { return } + guard mode.isHandling, isOpened, UserDefaultsConfig.usersId.isNotEmpty else { return } try await objectLifecycleService.close(contextId: objectId) isOpened = false } @@ -156,13 +162,25 @@ final class BaseDocument: BaseDocumentProtocol { // MARK: - Private methods + @MainActor + private func updateDocumentPreview() async throws { + let model = try await objectLifecycleService.openForPreview(contextId: objectId) + setupView(model) + } + + @MainActor + private func updateDocumentVersion(_ versionId: String) async throws { + let model = try await historyVersionsService.showVersion(objectId: objectId, versionId: versionId) + setupView(model) + } + private func setup() { eventsListener.onUpdatesReceive = { [weak self] updates in DispatchQueue.main.async { [weak self] in self?.triggerSync(updates: updates) } } - if !forPreview { + if mode.isHandling { eventsListener.startListening() } } diff --git a/Anytype/Sources/Models/Documents/Document/BaseDocumentProtocol.swift b/Anytype/Sources/Models/Documents/Document/BaseDocumentProtocol.swift index b0e445552a..dfbf0ed459 100644 --- a/Anytype/Sources/Models/Documents/Document/BaseDocumentProtocol.swift +++ b/Anytype/Sources/Models/Documents/Document/BaseDocumentProtocol.swift @@ -12,7 +12,7 @@ protocol BaseDocumentProtocol: AnyObject { var isLocked: Bool { get } var isEmpty: Bool { get } var isOpened: Bool { get } - var forPreview: Bool { get } + var mode: DocumentMode { get } var details: ObjectDetails? { get } var permissions: ObjectPermissions { get } var syncStatus: SyncStatus? { get } @@ -22,8 +22,10 @@ protocol BaseDocumentProtocol: AnyObject { @MainActor func open() async throws + @MainActor - func openForPreview() async throws + func update() async throws + @MainActor func close() async throws } diff --git a/Anytype/Sources/Models/Documents/Document/DocumentMode.swift b/Anytype/Sources/Models/Documents/Document/DocumentMode.swift new file mode 100644 index 0000000000..2b1b94dcbe --- /dev/null +++ b/Anytype/Sources/Models/Documents/Document/DocumentMode.swift @@ -0,0 +1,9 @@ +enum DocumentMode: Hashable, Codable { + case handling + case preview + case version(String) + + var isHandling: Bool { + self == .handling + } +} diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchData.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchData.swift index fa815e2751..a875e11aed 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchData.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/LinkToObject/LinkToObjectSearchData.swift @@ -33,7 +33,7 @@ struct LinkToObjectSearchData: SearchDataProtocol { self.description = "" self.callout = "" self.typeId = "" - self.editorScreenData = .page(EditorPageObject(objectId: "", spaceId: "", isOpenedForPreview: false)) + self.editorScreenData = .page(EditorPageObject(objectId: "", spaceId: "")) } } diff --git a/Anytype/Sources/PresentationLayer/Flows/HomeFlow/HomeCoordinatorViewModel.swift b/Anytype/Sources/PresentationLayer/Flows/HomeFlow/HomeCoordinatorViewModel.swift index 8a2fc73d07..735c655542 100644 --- a/Anytype/Sources/PresentationLayer/Flows/HomeFlow/HomeCoordinatorViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Flows/HomeFlow/HomeCoordinatorViewModel.swift @@ -305,8 +305,8 @@ final class HomeCoordinatorViewModel: ObservableObject, case .invite(let cid, let key): spaceJoinData = SpaceJoinModuleData(cid: cid, key: key) case .object(let objectId, _): - let document = documentsProvider.document(objectId: objectId, forPreview: true) - try await document.openForPreview() + let document = documentsProvider.document(objectId: objectId, mode: .preview) + try await document.open() guard let editorData = document.details?.editorScreenData() else { return } try await push(data: editorData) case .spaceShareTip: @@ -325,8 +325,8 @@ final class HomeCoordinatorViewModel: ObservableObject, editorPath.push(data) return } - let document = documentsProvider.document(objectId: objectId, forPreview: true) - try await document.openForPreview() + let document = documentsProvider.document(objectId: objectId, mode: .preview) + try await document.open() guard let details = document.details else { return } @@ -375,8 +375,8 @@ final class HomeCoordinatorViewModel: ObservableObject, // Restore last open page if currentSpaceId.isNil, let lastOpenPage = UserDefaultsConfig.lastOpenedPage { if let objectId = lastOpenPage.objectId { - let document = documentsProvider.document(objectId: objectId, forPreview: true) - try await document.openForPreview() + let document = documentsProvider.document(objectId: objectId, mode: .preview) + try await document.open() // Check space is deleted or switched if document.spaceId == newInfo.accountSpaceId { path.push(lastOpenPage) diff --git a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift index ea07967c61..04a62d897d 100644 --- a/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/CodeLanguage/CodeLanguageListViewModel.swift @@ -18,7 +18,7 @@ final class CodeLanguageListViewModel: ObservableObject { private let data: CodeLanguageListData private lazy var document: any BaseDocumentProtocol = { - documentsProvider.document(objectId: data.documentId, forPreview: false) + documentsProvider.document(objectId: data.documentId) }() private var selectedLanguage: CodeLanguage? diff --git a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/ObjectWidgetInternalViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/ObjectWidgetInternalViewModel.swift index 0bca4b7a1d..3dbbe7d51c 100644 --- a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/ObjectWidgetInternalViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/ObjectWidgetInternalViewModel.swift @@ -74,8 +74,8 @@ final class ObjectWidgetInternalViewModel: ObservableObject, WidgetInternalViewM func onCreateObjectTap() { guard let linkedObjectDetails else { return } Task { - let document = documentsProvider.document(objectId: linkedObjectDetails.id, forPreview: true) - try await document.openForPreview() + let document = documentsProvider.document(objectId: linkedObjectDetails.id, mode: .preview) + try await document.open() guard let lastBlockId = document.children.last?.id else { return } let details = try await defaultObjectService.createDefaultObject(name: "", shouldDeleteEmptyObject: true, spaceId: widgetObject.spaceId) diff --git a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift index a3069a83ee..f9f7387d09 100644 --- a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift @@ -210,13 +210,13 @@ final class SetObjectWidgetInternalViewModel: ObservableObject { private func updateSetDocument(objectId: String) async { guard objectId != setDocument?.objectId else { - try? await setDocument?.openForPreview() + try? await setDocument?.update() await updateModelState() return } - setDocument = documentsProvider.setDocument(objectId: objectId, forPreview: true) - try? await setDocument?.openForPreview() + setDocument = documentsProvider.setDocument(objectId: objectId, mode: .preview) + try? await setDocument?.open() rowDetails = nil dataviewState = nil diff --git a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetLegacyInternalViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetLegacyInternalViewModel.swift index 0a0439ce58..b81b1275e3 100644 --- a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetLegacyInternalViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetLegacyInternalViewModel.swift @@ -169,13 +169,13 @@ final class SetObjectWidgetLegacyInternalViewModel: ObservableObject, WidgetData private func updateSetDocument(objectId: String) async { guard objectId != setDocument?.objectId else { - try? await setDocument?.openForPreview() + try? await setDocument?.update() updateModelState() return } - setDocument = documentsProvider.setDocument(objectId: objectId, forPreview: true) - try? await setDocument?.openForPreview() + setDocument = documentsProvider.setDocument(objectId: objectId, mode: .preview) + try? await setDocument?.open() updateModelState() details = nil diff --git a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/SetObjectCreationSettingsCoordinator.swift b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/SetObjectCreationSettingsCoordinator.swift index 3b3e36b0ad..52397517bb 100644 --- a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/SetObjectCreationSettingsCoordinator.swift +++ b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/SetObjectCreationSettingsCoordinator.swift @@ -72,7 +72,6 @@ final class SetObjectCreationSettingsCoordinator: data: EditorPageObject( objectId: setting.templateId, spaceId: setting.spaceId, - isOpenedForPreview: false, usecase: .templateEditing ), showHeader: false, diff --git a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/TemplatesCoordinator.swift b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/TemplatesCoordinator.swift index 5c4e9cdb94..cb6e9f6418 100644 --- a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/TemplatesCoordinator.swift +++ b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/TemplatesCoordinator.swift @@ -45,7 +45,6 @@ extension TemplatesCoordinator: TemplatePickerViewModuleOutput { data: EditorPageObject( objectId: template.id, spaceId: template.spaceId, - isOpenedForPreview: false, usecase: .templateEditing ), showHeader: false, diff --git a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsView.swift b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsView.swift index 17b07ee7a6..2dcc846aec 100644 --- a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsView.swift +++ b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsView.swift @@ -108,7 +108,7 @@ struct SetObjectCreationSettingsView: View { #Preview { SetObjectCreationSettingsView( - setDocument: Container.shared.documentsProvider().setDocument(objectId: "", forPreview: false), + setDocument: Container.shared.documentsProvider().setDocument(objectId: ""), viewId: "viewId", output: nil ) diff --git a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsViewModel.swift b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsViewModel.swift index 50844c6ce3..0b3e908520 100644 --- a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsViewModel.swift +++ b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsViewModel.swift @@ -290,8 +290,8 @@ final class SetObjectCreationSettingsViewModel: ObservableObject { } private func retrieveObjectDetails(objectId: String) async -> ObjectDetails? { - let targetDocument = documentsProvider.document(objectId: objectId, forPreview: true) - try? await targetDocument.openForPreview() + let targetDocument = documentsProvider.document(objectId: objectId, mode: .preview) + try? await targetDocument.open() return targetDocument.details } diff --git a/Anytype/Sources/PresentationLayer/Settings/Coordinator/SettingsCoordinatorViewModel.swift b/Anytype/Sources/PresentationLayer/Settings/Coordinator/SettingsCoordinatorViewModel.swift index 41a65cab86..f82f2b8826 100644 --- a/Anytype/Sources/PresentationLayer/Settings/Coordinator/SettingsCoordinatorViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Settings/Coordinator/SettingsCoordinatorViewModel.swift @@ -49,7 +49,7 @@ final class SettingsCoordinatorViewModel: ObservableObject, } func onChangeIconSelected(objectId: String) { - let document = documentService.document(objectId: objectId, forPreview: true) + let document = documentService.document(objectId: objectId, mode: .preview) objectIconPickerData = ObjectIconPickerData(document: document) } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/SlashMenu/Handler/SlashMenuActionHandler.swift b/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/SlashMenu/Handler/SlashMenuActionHandler.swift index 60fda1211e..198bd7b567 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/SlashMenu/Handler/SlashMenuActionHandler.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/SlashMenu/Handler/SlashMenuActionHandler.swift @@ -107,7 +107,7 @@ final class SlashMenuActionHandler { if objectType.isListType { return .set(EditorSetObject(objectId: objectId, spaceId: objectType.spaceId)) } else { - return .page(EditorPageObject(objectId: objectId, spaceId: objectType.spaceId, isOpenedForPreview: false)) + return .page(EditorPageObject(objectId: objectId, spaceId: objectType.spaceId)) } } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData+Details.swift b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData+Details.swift index dfd9584b6a..a32083836a 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData+Details.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData+Details.swift @@ -4,18 +4,19 @@ import Services // MARK: - Init helpers extension EditorScreenData { - init(details: ObjectDetails, isOpenedForPreview: Bool = false, blockId: String? = nil, activeViewId: String? = nil) { + init(details: ObjectDetails, mode: DocumentMode = .handling, blockId: String? = nil, activeViewId: String? = nil) { switch details.editorViewType { case .page: self = .page(EditorPageObject( details: details, - isOpenedForPreview: isOpenedForPreview, + mode: mode, blockId: blockId )) case .set: self = .set(EditorSetObject( details: details, - activeViewId: activeViewId + activeViewId: activeViewId, + mode: mode )) } } @@ -24,24 +25,25 @@ extension EditorScreenData { extension EditorPageObject { init( details: ObjectDetails, - isOpenedForPreview: Bool = false, + mode: DocumentMode = .handling, blockId: String? = nil, usecase: ObjectHeaderEmptyData.ObjectHeaderEmptyUsecase = .editor ) { self.objectId = details.id self.spaceId = details.spaceId - self.isOpenedForPreview = isOpenedForPreview + self.mode = mode self.blockId = blockId self.usecase = usecase } } extension EditorSetObject { - init(details: ObjectDetails, activeViewId: String? = nil) { + init(details: ObjectDetails, activeViewId: String? = nil, mode: DocumentMode = .handling) { self.objectId = details.id self.spaceId = details.spaceId self.activeViewId = activeViewId self.inline = nil + self.mode = mode } } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData.swift b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData.swift index 877dadbbcb..aa79352d21 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/EditorScreenData.swift @@ -16,20 +16,20 @@ enum EditorScreenData: Hashable, Codable { struct EditorPageObject: Hashable, Codable { let objectId: String let spaceId: String - let isOpenedForPreview: Bool + let mode: DocumentMode var blockId: String? let usecase: ObjectHeaderEmptyData.ObjectHeaderEmptyUsecase init( objectId: String, spaceId: String, - isOpenedForPreview: Bool, + mode: DocumentMode = .handling, blockId: String? = nil, usecase: ObjectHeaderEmptyData.ObjectHeaderEmptyUsecase = .editor ) { self.objectId = objectId self.spaceId = spaceId - self.isOpenedForPreview = isOpenedForPreview + self.mode = mode self.blockId = blockId self.usecase = usecase } @@ -40,17 +40,20 @@ struct EditorSetObject: Hashable, Codable { let spaceId: String let activeViewId: String? var inline: EditorInlineSetObject? + let mode: DocumentMode init( objectId: String, spaceId: String, activeViewId: String? = nil, - inline: EditorInlineSetObject? = nil + inline: EditorInlineSetObject? = nil, + mode: DocumentMode = .handling ) { self.objectId = objectId self.spaceId = spaceId self.activeViewId = activeViewId self.inline = inline + self.mode = mode } } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift index aa15a314f2..3c2d8eb384 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Assembly/Page/EditorPageModuleAssembly.swift @@ -47,7 +47,7 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { let document = documentService.document( objectId: data.objectId, - forPreview: data.isOpenedForPreview + mode: data.mode ) let router = EditorRouter( viewController: controller, @@ -65,7 +65,6 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { blocksSelectionOverlayViewModel: blocksSelectionOverlayView.viewModel, bottomNavigationManager: bottomNavigationManager, configuration: EditorPageViewModelConfiguration( - isOpenedForPreview: data.isOpenedForPreview, blockId: data.blockId, usecase: data.usecase ), @@ -123,7 +122,7 @@ final class EditorPageModuleAssembly: EditorPageModuleAssemblyProtocol { blocksSelectionOverlayViewModel: blocksSelectionOverlayViewModel, actionHandler: actionHandler, router: router, - initialEditingState: configuration.isOpenedForPreview ? .readonly : .editing, + initialEditingState: document.mode.isHandling ? .editing : .readonly, viewInput: viewInput, bottomNavigationManager: bottomNavigationManager ) diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageBlocksStateManager.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageBlocksStateManager.swift index 1b35f67167..0f20976de7 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageBlocksStateManager.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageBlocksStateManager.swift @@ -275,7 +275,7 @@ final class EditorPageBlocksStateManager: EditorPageBlocksStateManagerProtocol { case let .object(blockId): if let info = document.infoContainer.get(id: blockId), case let .link(content) = info.content { - let targetDocument = documentsProvider.document(objectId: content.targetBlockID, forPreview: false) + let targetDocument = documentsProvider.document(objectId: content.targetBlockID) Task { @MainActor [weak self] in try? await targetDocument.open() diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift index bd1b11d2d6..d21781a030 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModel.swift @@ -223,10 +223,8 @@ extension EditorPageViewModel { Task { @MainActor in do { - if configuration.isOpenedForPreview { - try await document.openForPreview() - } else { - try await document.open() + try await document.open() + if document.mode.isHandling { blocksStateManager.checkOpenedState() } } catch ObjectOpenError.anytypeNeedsUpgrade { diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModelConfiguration.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModelConfiguration.swift index f0550e02b4..089ce41129 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModelConfiguration.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageViewModelConfiguration.swift @@ -1,7 +1,6 @@ import Foundation struct EditorPageViewModelConfiguration { - let isOpenedForPreview: Bool let blockId: String? let usecase: ObjectHeaderEmptyData.ObjectHeaderEmptyUsecase } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Header/Entities/ObjectHeaderViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Header/Entities/ObjectHeaderViewModel.swift index 3212eaed81..b020777254 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Header/Entities/ObjectHeaderViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Header/Entities/ObjectHeaderViewModel.swift @@ -24,14 +24,13 @@ final class ObjectHeaderViewModel: ObservableObject { // MARK: - Private variables private lazy var onIconTap = { [weak self] in - guard let self = self, !self.configuration.isOpenedForPreview else { return } - guard document.permissions.canChangeIcon else { return } + guard let self, document.mode.isHandling, document.permissions.canChangeIcon else { return } UISelectionFeedbackGenerator().selectionChanged() self.onIconPickerTap?(document) } private lazy var onCoverTap = { [weak self] in - guard let self, !configuration.isOpenedForPreview else { return } + guard let self, document.mode.isHandling else { return } guard document.details?.layoutValue != .note else { return } guard document.permissions.canChangeCover else { return } UISelectionFeedbackGenerator().selectionChanged() diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Coordinator/VersionHistoryCoordinatorViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Coordinator/VersionHistoryCoordinatorViewModel.swift index d35598d5c2..43ab31d345 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Coordinator/VersionHistoryCoordinatorViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Coordinator/VersionHistoryCoordinatorViewModel.swift @@ -23,7 +23,8 @@ final class VersionHistoryCoordinatorViewModel: ObservableObject, VersionHistory objectVersionData = ObjectVersionData( title: title, icon: icon, - objectId: data.objectId, + objectId: data.objectId, + spaceId: data.spaceId, versionId: versionId, isListType: data.isListType ) diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionView.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionView.swift index 42404e4345..f9c278d27a 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionView.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionView.swift @@ -14,6 +14,9 @@ struct ObjectVersionView: View { .overlay(alignment: .topLeading) { header } + .task { + await model.setupObject() + } } private var header: some View { diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionViewModel.swift index bd6751882f..c2b22d58b9 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/Object/ObjectVersionViewModel.swift @@ -5,6 +5,7 @@ struct ObjectVersionData: Identifiable, Hashable { let title: String let icon: ObjectIcon? let objectId: String + let spaceId: String let versionId: String let isListType: Bool @@ -17,18 +18,20 @@ final class ObjectVersionViewModel: ObservableObject { @Published var screenData: EditorScreenData? let data: ObjectVersionData - private let openDocumentProvider: OpenedDocumentsProviderProtocol = Container.shared.documentService() - init(data: ObjectVersionData) { self.data = data + } + + func setupObject() async { self.screenData = currentScreenData() } private func currentScreenData() -> EditorScreenData? { + let mode: DocumentMode = .version(data.versionId) if data.isListType { - return openDocumentProvider.setDocument(objectId: data.objectId).details?.editorScreenData() + return .set(EditorSetObject(objectId: data.objectId, spaceId: data.spaceId, mode: mode)) } else { - return openDocumentProvider.document(objectId: data.objectId).details?.editorScreenData() + return .page(EditorPageObject(objectId: data.objectId, spaceId: data.spaceId, mode: mode)) } } } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryDataBuilder.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryDataBuilder.swift index 084759fc53..0e3a4b56d3 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryDataBuilder.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryDataBuilder.swift @@ -44,11 +44,18 @@ final class VersionHistoryDataBuilder: VersionHistoryDataBuilderProtocol { for (key, versions) in versionsByDay { var versionsByAuthor = [VersionHistory]() var versionsByAuthors = [[VersionHistory]]() - var lastParticipantId = versions.first?.authorID + var lastVersion = versions.first for version in versions { - if let lastParticipantId, lastParticipantId == version.authorID { - versionsByAuthor.append(version) + if let lastVersion, lastVersion.authorID == version.authorID { + let sameVersion = lastVersion.id == version.id + let sameMinute = date( + buildDate(for: lastVersion), + isEqualToMinutes: buildDate(for: version) + ) + if sameVersion || !sameMinute { + versionsByAuthor.append(version) + } } else { versionsByAuthors.append(versionsByAuthor) versionsByAuthor = [version] @@ -58,7 +65,7 @@ final class VersionHistoryDataBuilder: VersionHistoryDataBuilderProtocol { versionsByAuthors.append(versionsByAuthor) } - lastParticipantId = version.authorID + lastVersion = version } versionsByDayByAuthor[key] = versionsByAuthors @@ -131,6 +138,10 @@ final class VersionHistoryDataBuilder: VersionHistoryDataBuilderProtocol { let timeInterval = Double(version.time) return Date(timeIntervalSince1970: timeInterval) } + + private func date(_ date1: Date, isEqualToMinutes date2: Date) -> Bool { + dateTimeFormatter.calendar.isDate(date1, equalTo: date2, toGranularity: .minute) + } } extension Container { diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryView.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryView.swift index 73a77b22b7..97aab547b0 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryView.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/History/VersionHistoryView.swift @@ -50,7 +50,7 @@ struct VersionHistoryView: View { private func content(for versions: [[VersionHistoryItem]]) -> some View { ForEach(versions, id: \.self) { versions in - if let version = versions.first { + ForEach(versions, id: \.self) { version in itemRow(for: version) } } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/Icon/Space/SpaceObjectIconPickerViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/Icon/Space/SpaceObjectIconPickerViewModel.swift index c3bed2cf7a..f779051883 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/Icon/Space/SpaceObjectIconPickerViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/Icon/Space/SpaceObjectIconPickerViewModel.swift @@ -18,7 +18,7 @@ final class SpaceObjectIconPickerViewModel: ObservableObject { private var openDocumentProvider: any OpenedDocumentsProviderProtocol private lazy var document: any BaseDocumentProtocol = { - openDocumentProvider.document(objectId: spaceViewId, forPreview: false) + openDocumentProvider.document(objectId: spaceViewId) }() @Published private(set) var isRemoveEnabled: Bool = false diff --git a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/ObjectActions/ObjectActionsViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/ObjectActions/ObjectActionsViewModel.swift index 4242b0e253..692d527b8e 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/ObjectActions/ObjectActionsViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Views/Settings/ObjectActions/ObjectActionsViewModel.swift @@ -137,8 +137,8 @@ final class ObjectActionsViewModel: ObservableObject { anytypeAssertionFailure("Default layout not found") return } - let widgetObject = documentsProvider.document(objectId: info.widgetsId, forPreview: true) - try await widgetObject.openForPreview() + let widgetObject = documentsProvider.document(objectId: info.widgetsId, mode: .preview) + try await widgetObject.open() guard let first = widgetObject.children.first else { anytypeAssertionFailure("First children not found") return @@ -182,8 +182,8 @@ final class ObjectActionsViewModel: ObservableObject { private func onObjectSelection(objectId: String, currentObjectId: String) { Task { @MainActor in - let targetDocument = documentsProvider.document(objectId: objectId, forPreview: true) - try? await targetDocument.openForPreview() + let targetDocument = documentsProvider.document(objectId: objectId, mode: .preview) + try? await targetDocument.open() guard let id = targetDocument.children.last?.id, let details = targetDocument.details else { return } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift index 8e6d4db8d0..cba95c5769 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift @@ -177,14 +177,13 @@ final class EditorSetViewModel: ObservableObject { init(data: EditorSetObject, showHeader: Bool, output: (any EditorSetModuleOutput)?) { self.setDocument = documentsProvider.setDocument( objectId: data.objectId, - forPreview: false, + mode: data.mode, inlineParameters: data.inline ) self.headerModel = ObjectHeaderViewModel( document: setDocument.document, targetObjectId: setDocument.targetObjectId, configuration: EditorPageViewModelConfiguration( - isOpenedForPreview: false, blockId: nil, usecase: .editor ), diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocument.swift b/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocument.swift index 165e849b25..c115220757 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocument.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocument.swift @@ -24,7 +24,7 @@ final class SetDocument: SetDocumentProtocol { document.detailsPublisher } - var forPreview: Bool { document.forPreview } + var mode: DocumentMode { document.mode } var blockDataview: BlockDataview? { let blockId = inlineParameters?.blockId ?? SetConstants.dataviewBlockId @@ -204,8 +204,8 @@ final class SetDocument: SetDocumentProtocol { } @MainActor - func openForPreview() async throws { - try await document.openForPreview() + func update() async throws { + try await document.update() await setup() } diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocumentProtocol.swift b/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocumentProtocol.swift index 1380ebe21a..8903809de6 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocumentProtocol.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Set/Models/SetDocumentProtocol.swift @@ -58,7 +58,7 @@ protocol SetDocumentProtocol: AnyObject { func open() async throws @MainActor - func openForPreview() async throws + func update() async throws @MainActor func close() async throws diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Set/Views/Header/SetHeaderSettingsView.swift b/Anytype/Sources/PresentationLayer/TextEditor/Set/Views/Header/SetHeaderSettingsView.swift index 4b023bdd1e..1e934c4925 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Set/Views/Header/SetHeaderSettingsView.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Set/Views/Header/SetHeaderSettingsView.swift @@ -92,7 +92,7 @@ struct SetHeaderSettings_Previews: PreviewProvider { static var previews: some View { SetHeaderSettingsView( model: SetHeaderSettingsViewModel( - setDocument: Container.shared.documentsProvider().setDocument(objectId: "", forPreview: false), + setDocument: Container.shared.documentsProvider().setDocument(objectId: ""), onViewTap: {}, onSettingsTap: {}, onCreateTap:{}, diff --git a/Anytype/Sources/PresentationLayer/ToastPresenter/ToastPresenter.swift b/Anytype/Sources/PresentationLayer/ToastPresenter/ToastPresenter.swift index 8f92a07c0a..274917beb5 100644 --- a/Anytype/Sources/PresentationLayer/ToastPresenter/ToastPresenter.swift +++ b/Anytype/Sources/PresentationLayer/ToastPresenter/ToastPresenter.swift @@ -127,8 +127,8 @@ final class ToastPresenter: ToastPresenterProtocol { } private func retrieveObjectDetails(objectId: String) async -> ObjectDetails? { - let targetDocument = documentsProvider.document(objectId: objectId, forPreview: true) - try? await targetDocument.openForPreview() + let targetDocument = documentsProvider.document(objectId: objectId, mode: .preview) + try? await targetDocument.open() return targetDocument.details } diff --git a/Anytype/Sources/ServiceLayer/DocumentsProvider/DocumentsProvider.swift b/Anytype/Sources/ServiceLayer/DocumentsProvider/DocumentsProvider.swift index 0538caa4da..6502cfb55c 100644 --- a/Anytype/Sources/ServiceLayer/DocumentsProvider/DocumentsProvider.swift +++ b/Anytype/Sources/ServiceLayer/DocumentsProvider/DocumentsProvider.swift @@ -2,20 +2,37 @@ import Foundation import Services protocol DocumentsProviderProtocol { - func document(objectId: String, forPreview: Bool) -> any BaseDocumentProtocol + func document(objectId: String, mode: DocumentMode) -> any BaseDocumentProtocol func setDocument( objectId: String, - forPreview: Bool, + mode: DocumentMode, inlineParameters: EditorInlineSetObject? ) -> any SetDocumentProtocol } extension DocumentsProviderProtocol { + func document(objectId: String) -> any BaseDocumentProtocol { + document(objectId: objectId, mode: .handling) + } + + func setDocument( + objectId: String, + mode: DocumentMode + ) -> any SetDocumentProtocol { + setDocument(objectId: objectId, mode: mode, inlineParameters: nil) + } + func setDocument( objectId: String, - forPreview: Bool + inlineParameters: EditorInlineSetObject? + ) -> any SetDocumentProtocol { + setDocument(objectId: objectId, mode: .handling, inlineParameters: inlineParameters) + } + + func setDocument( + objectId: String ) -> any SetDocumentProtocol { - setDocument(objectId: objectId, forPreview: forPreview, inlineParameters: nil) + setDocument(objectId: objectId, mode: .handling, inlineParameters: nil) } } @@ -31,16 +48,16 @@ final class DocumentsProvider: DocumentsProviderProtocol { @Injected(\.accountParticipantsStorage) private var accountParticipantsStorage: any AccountParticipantsStorageProtocol - func document(objectId: String, forPreview: Bool) -> any BaseDocumentProtocol { - internalDocument(objectId: objectId, forPreview: forPreview) + func document(objectId: String, mode: DocumentMode) -> any BaseDocumentProtocol { + internalDocument(objectId: objectId, mode: mode) } func setDocument( objectId: String, - forPreview: Bool, + mode: DocumentMode, inlineParameters: EditorInlineSetObject? ) -> any SetDocumentProtocol { - let document = internalDocument(objectId: objectId, forPreview: forPreview) + let document = internalDocument(objectId: objectId, mode: mode) return SetDocument( document: document, @@ -54,9 +71,9 @@ final class DocumentsProvider: DocumentsProviderProtocol { // MARK: - Private - private func internalDocument(objectId: String, forPreview: Bool) -> any BaseDocumentProtocol { - if forPreview { - let document = createBaseDocument(objectId: objectId, forPreview: forPreview) + private func internalDocument(objectId: String, mode: DocumentMode) -> any BaseDocumentProtocol { + if !mode.isHandling { + let document = createBaseDocument(objectId: objectId, mode: mode) return document } @@ -64,13 +81,13 @@ final class DocumentsProvider: DocumentsProviderProtocol { return value } - let document = createBaseDocument(objectId: objectId, forPreview: forPreview) + let document = createBaseDocument(objectId: objectId, mode: mode) documentCache.setObject(document, forKey: objectId as NSString) return document } - private func createBaseDocument(objectId: String, forPreview: Bool) -> some BaseDocumentProtocol { + private func createBaseDocument(objectId: String, mode: DocumentMode) -> some BaseDocumentProtocol { let infoContainer = InfoContainer() let relationLinksStorage = RelationLinksStorage() let restrictionsContainer = ObjectRestrictionsContainer() @@ -90,7 +107,7 @@ final class DocumentsProvider: DocumentsProviderProtocol { ) return BaseDocument( objectId: objectId, - forPreview: forPreview, + mode: mode, objectLifecycleService: objectLifecycleService, relationDetailsStorage: relationDetailsStorage, objectTypeProvider: objectTypeProvider, diff --git a/Anytype/Sources/ServiceLayer/Subscriptions/OpenedDocumentsProvider.swift b/Anytype/Sources/ServiceLayer/Subscriptions/OpenedDocumentsProvider.swift index 168dc3ecd7..506260d60f 100644 --- a/Anytype/Sources/ServiceLayer/Subscriptions/OpenedDocumentsProvider.swift +++ b/Anytype/Sources/ServiceLayer/Subscriptions/OpenedDocumentsProvider.swift @@ -1,17 +1,19 @@ import Foundation protocol OpenedDocumentsProviderProtocol: AnyObject { - func document(objectId: String, forPreview: Bool) -> any BaseDocumentProtocol - func setDocument(objectId: String, forPreview: Bool) -> any SetDocumentProtocol + func document(objectId: String, mode: DocumentMode) -> any BaseDocumentProtocol + func setDocument(objectId: String, mode: DocumentMode) -> any SetDocumentProtocol } // Default arguments extension OpenedDocumentsProviderProtocol { + func document(objectId: String) -> any BaseDocumentProtocol { - return document(objectId: objectId, forPreview: false) + return document(objectId: objectId, mode: .handling) } + func setDocument(objectId: String) -> any SetDocumentProtocol { - return setDocument(objectId: objectId, forPreview: false) + return setDocument(objectId: objectId, mode: .handling) } } @@ -21,32 +23,24 @@ final class OpenedDocumentsProvider: OpenedDocumentsProviderProtocol { private var documentsProvider: any DocumentsProviderProtocol // MARK: - DocumentServiceProtocol - func document(objectId: String, forPreview: Bool) -> any BaseDocumentProtocol { - let document = documentsProvider.document(objectId: objectId, forPreview: forPreview) + func document(objectId: String, mode: DocumentMode) -> any BaseDocumentProtocol { + let document = documentsProvider.document(objectId: objectId, mode: mode) Task { @MainActor in - if forPreview { - try await document.openForPreview() - } else { - try await document.open() - } + try await document.open() } return document } - func setDocument(objectId: String, forPreview: Bool) -> any SetDocumentProtocol { + func setDocument(objectId: String, mode: DocumentMode) -> any SetDocumentProtocol { let document = documentsProvider.setDocument( objectId: objectId, - forPreview: forPreview + mode: mode ) Task { @MainActor in - if forPreview { - try await document.openForPreview() - } else { - try await document.open() - } + try await document.open() } return document