diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/GlobalSearchViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/GlobalSearchViewModel.swift index 7308220d9b..109b842775 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/GlobalSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/GlobalSearchViewModel.swift @@ -18,7 +18,9 @@ final class GlobalSearchViewModel: ObservableObject { private var accountParticipantStorage: any ParticipantsStorageProtocol @Injected(\.objectActionsService) private var objectActionService: any ObjectActionsServiceProtocol - + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol + private let moduleData: GlobalSearchModuleData private let dateFormatter = AnytypeRelativeDateTimeFormatter() @@ -28,6 +30,7 @@ final class GlobalSearchViewModel: ObservableObject { @Published var dismiss = false @Published private var participantCanEdit = false + private var spaceUxType: SpaceUxType? private var searchResult = [SearchResultWithMeta]() private var sectionChanged = false var isInitial = true @@ -35,6 +38,7 @@ final class GlobalSearchViewModel: ObservableObject { init(data: GlobalSearchModuleData) { self.moduleData = data self.restoreState() + self.loadSpaceUxType() } func startParticipantTask() async { @@ -97,6 +101,10 @@ final class GlobalSearchViewModel: ObservableObject { UISelectionFeedbackGenerator().selectionChanged() } + private func loadSpaceUxType() { + spaceUxType = spaceViewsStorage.spaceView(spaceId: moduleData.spaceId)?.uxType + } + private func updateSections() { guard searchResult.isNotEmpty else { sections = [] @@ -161,11 +169,11 @@ final class GlobalSearchViewModel: ObservableObject { } private func buildLayouts() -> [DetailsLayout] { - .builder { + return .builder { if state.searchText.isEmpty { - state.section.supportedLayouts.filter { $0 != .participant } + state.section.supportedLayouts(spaceUxType: spaceUxType).filter { $0 != .participant } } else { - state.section.supportedLayouts + state.section.supportedLayouts(spaceUxType: spaceUxType) } } } diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/Models/ObjectTypeSection.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/Models/ObjectTypeSection.swift index 02ca1b9087..b1978f9a3f 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/Models/ObjectTypeSection.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/Models/ObjectTypeSection.swift @@ -34,10 +34,10 @@ enum ObjectTypeSection: String, CaseIterable, Codable { } } - var supportedLayouts: [DetailsLayout] { + func supportedLayouts(spaceUxType: SpaceUxType?) -> [DetailsLayout] { switch self { case .all: - DetailsLayout.visibleLayoutsWithFiles + DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType) case .pages: DetailsLayout.editorLayouts case .lists: diff --git a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchWithMeta/ObjectSearchWithMetaViewModel.swift b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchWithMeta/ObjectSearchWithMetaViewModel.swift index 24a65a7819..a201bf801b 100644 --- a/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchWithMeta/ObjectSearchWithMetaViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchWithMeta/ObjectSearchWithMetaViewModel.swift @@ -11,7 +11,9 @@ final class ObjectSearchWithMetaViewModel: ObservableObject { private var searchWithMetaService: any SearchWithMetaServiceProtocol @Injected(\.searchWithMetaModelBuilder) private var searchWithMetaModelBuilder: any SearchWithMetaModelBuilderProtocol - + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol + private let dateFormatter = AnytypeRelativeDateTimeFormatter() @Published var searchText = "" @@ -36,7 +38,7 @@ final class ObjectSearchWithMetaViewModel: ObservableObject { searchResult = try await searchWithMetaService.search( text: searchText, spaceId: moduleData.spaceId, - layouts: ObjectSearchWithMetaModuleData.supportedLayouts, + layouts: supportedLayouts(), sorts: buildSorts(), excludedObjectIds: moduleData.excludedObjectIds ) @@ -109,9 +111,10 @@ final class ObjectSearchWithMetaViewModel: ObservableObject { ) } } -} -extension ObjectSearchWithMetaModuleData { - static let supportedLayouts: [DetailsLayout] = - ObjectTypeSection.pages.supportedLayouts + ObjectTypeSection.lists.supportedLayouts + private func supportedLayouts() -> [DetailsLayout] { + let spaceUxType = spaceViewsStorage.spaceView(spaceId: moduleData.spaceId)?.uxType + return ObjectTypeSection.pages.supportedLayouts(spaceUxType: spaceUxType) + + ObjectTypeSection.lists.supportedLayouts(spaceUxType: spaceUxType) + } } diff --git a/Anytype/Sources/PresentationLayer/Modules/Date/Subscription/DateRelatedObjectsSubscriptionService.swift b/Anytype/Sources/PresentationLayer/Modules/Date/Subscription/DateRelatedObjectsSubscriptionService.swift index d4e205b36e..6d933a5d17 100644 --- a/Anytype/Sources/PresentationLayer/Modules/Date/Subscription/DateRelatedObjectsSubscriptionService.swift +++ b/Anytype/Sources/PresentationLayer/Modules/Date/Subscription/DateRelatedObjectsSubscriptionService.swift @@ -18,6 +18,8 @@ final class DateRelatedObjectsSubscriptionService: DateRelatedObjectsSubscriptio @Injected(\.subscriptionStorageProvider) private var subscriptionStorageProvider: any SubscriptionStorageProviderProtocol + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol private lazy var subscriptionStorage: any SubscriptionStorageProtocol = { subscriptionStorageProvider.createSubscriptionStorage(subId: subscriptionId) }() @@ -33,8 +35,9 @@ final class DateRelatedObjectsSubscriptionService: DateRelatedObjectsSubscriptio update: @escaping @MainActor ([ObjectDetails], Int) -> Void ) async { + let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType let filters: [DataviewFilter] = .builder { - SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles) + SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType)) filters } diff --git a/Anytype/Sources/PresentationLayer/Modules/HomeNavigationContainer/Panel/HomeBottomNavigationPanelViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/HomeNavigationContainer/Panel/HomeBottomNavigationPanelViewModel.swift index 3781a0d16f..20f6587e7c 100644 --- a/Anytype/Sources/PresentationLayer/Modules/HomeNavigationContainer/Panel/HomeBottomNavigationPanelViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/HomeNavigationContainer/Panel/HomeBottomNavigationPanelViewModel.swift @@ -37,7 +37,9 @@ final class HomeBottomNavigationPanelViewModel: ObservableObject { private var objectActionsService: any ObjectActionsServiceProtocol @Injected(\.experimentalFeaturesStorage) private var experimentalFeaturesStorage: any ExperimentalFeaturesStorageProtocol - + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol + private weak var output: (any HomeBottomNavigationPanelModuleOutput)? private let subId = "HomeBottomNavigationProfile-\(UUID().uuidString)" @@ -161,8 +163,10 @@ final class HomeBottomNavigationPanelViewModel: ObservableObject { private func typesSubscription() async { for await types in objectTypeProvider.objectTypesPublisher(spaceId: info.accountSpaceId).values { + let spaceUxType = spaceViewsStorage.spaceView(spaceId: info.accountSpaceId)?.uxType + let supportedLayouts = DetailsLayout.supportedForCreation(spaceUxType: spaceUxType) let types = types.filter { type in - DetailsLayout.supportedForCreation.contains { $0 == type.recommendedLayout } + supportedLayouts.contains { $0 == type.recommendedLayout } && !type.isTemplateType } diff --git a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Container/HomeWidgetsViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Container/HomeWidgetsViewModel.swift index 4c08c50833..8846ece67f 100644 --- a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Container/HomeWidgetsViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Container/HomeWidgetsViewModel.swift @@ -158,12 +158,14 @@ final class HomeWidgetsViewModel { private func startObjectTypesTask() async { let spaceId = spaceId - + let spaceUxType = workspaceStorage.spaceView(spaceId: spaceId)?.uxType + let allowedLayouts = DetailsLayout.widgetTypeLayouts(spaceUxType: spaceUxType) + let stream = objectTypeProvider.objectTypesPublisher(spaceId: spaceId) .values .map { objects in let objects = objects - .filter { ($0.recommendedLayout.map { DetailsLayout.widgetTypeLayouts.contains($0) } ?? false) && !$0.isTemplateType } + .filter { ($0.recommendedLayout.map { allowedLayouts.contains($0) } ?? false) && !$0.isTemplateType } return objects.map { ObjectTypeWidgetInfo(objectTypeId: $0.id, spaceId: spaceId) } } .removeDuplicates() diff --git a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/ObjectType/Helpers/ObjectTypeRowsBuilder.swift b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/ObjectType/Helpers/ObjectTypeRowsBuilder.swift index 0cce636228..01296090d6 100644 --- a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/ObjectType/Helpers/ObjectTypeRowsBuilder.swift +++ b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/ObjectType/Helpers/ObjectTypeRowsBuilder.swift @@ -24,7 +24,9 @@ actor ObjectTypeRowsBuilder: ObjectTypeRowsBuilderProtocol { private var setObjectWidgetOrderHelper: any SetObjectWidgetOrderHelperProtocol @LazyInjected(\.subscriptionStorageProvider) private var subscriptionStorageProvider: any SubscriptionStorageProviderProtocol - + @LazyInjected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol + private lazy var subscriptionStorage: any SubscriptionStorageProtocol = { subscriptionStorageProvider.createSubscriptionStorage(subId: subscriptionId) }() @@ -71,7 +73,8 @@ actor ObjectTypeRowsBuilder: ObjectTypeRowsBuilderProtocol { private func startObjectsSubscription() async { do { try await setDocument.open() - + + let spaceUxType = await spaceViewsStorage.spaceView(spaceId: setDocument.spaceId)?.uxType let subscriptionData = setSubscriptionDataBuilder.set( SetSubscriptionData( identifier: subscriptionId, @@ -80,7 +83,8 @@ actor ObjectTypeRowsBuilder: ObjectTypeRowsBuilderProtocol { currentPage: 0, numberOfRowsPerPage: 6, collectionId: nil, - objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId) + objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId), + spaceUxType: spaceUxType ) ) diff --git a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift index c2f8f30a71..4859c945e8 100644 --- a/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift +++ b/Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift @@ -31,7 +31,9 @@ final class SetObjectWidgetInternalViewModel { private var objectTypeProvider: any ObjectTypeProviderProtocol @Injected(\.setObjectWidgetOrderHelper) @ObservationIgnored private var setObjectWidgetOrderHelper: any SetObjectWidgetOrderHelperProtocol - + @Injected(\.spaceViewsStorage) @ObservationIgnored + private var spaceViewsStorage: any SpaceViewsStorageProtocol + // MARK: - State @ObservationIgnored private var widgetInfo: BlockWidgetInfo? @@ -207,7 +209,8 @@ final class SetObjectWidgetInternalViewModel { } guard setDocument.canStartSubscription() else { return } - + + let spaceUxType = spaceViewsStorage.spaceView(spaceId: setDocument.spaceId)?.uxType let subscriptionData = setSubscriptionDataBuilder.set( SetSubscriptionData( identifier: subscriptionId, @@ -216,7 +219,8 @@ final class SetObjectWidgetInternalViewModel { currentPage: 0, numberOfRowsPerPage: widgetInfo.fixedLimit, collectionId: setDocument.isCollection() ? setDocument.objectId : nil, - objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId) + objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId), + spaceUxType: spaceUxType ) ) diff --git a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/Dataview/SetObjectCreationSettingsInteractor.swift b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/Dataview/SetObjectCreationSettingsInteractor.swift index 028734cc6a..5fadf2e84e 100644 --- a/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/Dataview/SetObjectCreationSettingsInteractor.swift +++ b/Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/Dataview/SetObjectCreationSettingsInteractor.swift @@ -62,7 +62,9 @@ final class SetObjectCreationSettingsInteractor: SetObjectCreationSettingsIntera private var typesService: any TypesServiceProtocol @Injected(\.dataviewService) private var dataviewService: any DataviewServiceProtocol - + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol + @Published private var templatesDetails = [ObjectDetails]() @Published private var defaultTemplateId: String @Published private var typeDefaultTemplateId: String = "" @@ -152,13 +154,16 @@ final class SetObjectCreationSettingsInteractor: SetObjectCreationSettingsIntera private func updateObjectTypes() { Task { + let spaceUxType = spaceViewsStorage.spaceView(spaceId: setDocument.spaceId)?.uxType + let chatTypeVisible = spaceUxType?.showsChatLayouts ?? true + let includeChat = FeatureFlags.multichats && chatTypeVisible objectTypes = try await typesService.searchObjectTypes( text: "", includePins: true, includeLists: true, includeBookmarks: true, includeFiles: false, - includeChat: FeatureFlags.multichats, + includeChat: includeChat, includeTemplates: false, incudeNotForCreation: false, spaceId: setDocument.spaceId diff --git a/Anytype/Sources/PresentationLayer/ObjectTypeSearch/ObjectTypeSearchViewModel.swift b/Anytype/Sources/PresentationLayer/ObjectTypeSearch/ObjectTypeSearchViewModel.swift index d692e22f4a..53213b4673 100644 --- a/Anytype/Sources/PresentationLayer/ObjectTypeSearch/ObjectTypeSearchViewModel.swift +++ b/Anytype/Sources/PresentationLayer/ObjectTypeSearch/ObjectTypeSearchViewModel.swift @@ -29,7 +29,9 @@ final class ObjectTypeSearchViewModel: ObservableObject { private var pasteboardHelper: any PasteboardHelperProtocol @Injected(\.participantsStorage) private var accountParticipantStorage: any ParticipantsStorageProtocol - + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol + private let onSelect: (TypeSelectionResult) -> Void private var searchTask: Task<(), any Error>? @@ -73,6 +75,9 @@ final class ObjectTypeSearchViewModel: ObservableObject { searchTask?.cancel() searchTask = Task { + let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType + let effectiveShowChat = settings.showChat && (spaceUxType?.showsChatLayouts ?? true) + let pinnedTypes = settings.showPins ? try await typesService.searchPinnedTypes(text: text, spaceId: spaceId) : [] let listTypes = settings.showLists ? try await typesService.searchListTypes( text: searchText, includePins: !settings.showPins, spaceId: spaceId @@ -83,7 +88,7 @@ final class ObjectTypeSearchViewModel: ObservableObject { includeLists: false, includeBookmarks: true, includeFiles: settings.showFiles, - includeChat: settings.showChat, + includeChat: effectiveShowChat, includeTemplates: settings.showTemplates, incudeNotForCreation: settings.incudeNotForCreation, spaceId: spaceId diff --git a/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/Mention/MentionViewController/MentionsViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/Mention/MentionViewController/MentionsViewModel.swift index ab75b53484..710407a4a2 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/Mention/MentionViewController/MentionsViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/AccessoryView/Mention/MentionViewController/MentionsViewModel.swift @@ -21,7 +21,9 @@ final class MentionsViewModel { private var defaultObjectService: any DefaultObjectCreationServiceProtocol @Injected(\.objectDateByTimestampService) private var objectDateByTimestampService: any ObjectDateByTimestampServiceProtocol - + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol + private var searchTask: Task<(), any Error>? private let router: any EditorRouterProtocol @@ -51,14 +53,17 @@ final class MentionsViewModel { updatedMentions.append(contentsOf: dateMentions.map { .mention($0) }) updatedMentions.append(.selectDate) } - + + let spaceUxType = spaceViewsStorage.spaceView(spaceId: document.spaceId)?.uxType + let objectLayouts = DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType) - [.date] + let objectsMentions = try await mentionService.searchMentions( spaceId: document.spaceId, text: filterString, excludedObjectIds: [document.objectId], - limitLayout: DetailsLayout.visibleLayoutsWithFiles - [.date] + limitLayout: objectLayouts ) - + if objectsMentions.isNotEmpty { updatedMentions.append(.header(title: Loc.objects)) updatedMentions.append(contentsOf: objectsMentions.map { .mention($0) }) diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift b/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift index d200ba9e16..50750cb685 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Set/EditorSetViewModel.swift @@ -213,6 +213,8 @@ final class EditorSetViewModel: ObservableObject { private var setGroupSubscriptionDataBuilder: any SetGroupSubscriptionDataBuilderProtocol @Injected(\.propertyDetailsStorage) private var propertyDetailsStorage: any PropertyDetailsStorageProtocol + @Injected(\.spaceViewsStorage) + private var spaceViewsStorage: any SpaceViewsStorageProtocol private let documentsProvider: any DocumentsProviderProtocol = Container.shared.documentsProvider() private var subscriptions = [AnyCancellable]() @@ -550,7 +552,8 @@ final class EditorSetViewModel: ObservableObject { } guard setDocument.canStartSubscription() else { return } - + + let spaceUxType = spaceViewsStorage.spaceView(spaceId: setDocument.spaceId)?.uxType let data = setSubscriptionDataBuilder.set( SetSubscriptionData( identifier: subscriptionId, @@ -559,7 +562,8 @@ final class EditorSetViewModel: ObservableObject { currentPage: currentPage, // show first page for empty request numberOfRowsPerPage: numberOfRowsPerPage, collectionId: setDocument.isCollection() ? objectId : nil, - objectOrderIds: setDocument.objectOrderIds(for: subscriptionId) + objectOrderIds: setDocument.objectOrderIds(for: subscriptionId), + spaceUxType: spaceUxType ) ) diff --git a/Anytype/Sources/PresentationLayer/TextEditor/Set/Subscriptions/Set/SetSubscriptionData.swift b/Anytype/Sources/PresentationLayer/TextEditor/Set/Subscriptions/Set/SetSubscriptionData.swift index aa03dad2c3..b1800c6ef5 100644 --- a/Anytype/Sources/PresentationLayer/TextEditor/Set/Subscriptions/Set/SetSubscriptionData.swift +++ b/Anytype/Sources/PresentationLayer/TextEditor/Set/Subscriptions/Set/SetSubscriptionData.swift @@ -20,7 +20,8 @@ struct SetSubscriptionData: Hashable { currentPage: Int, numberOfRowsPerPage: Int, collectionId: String?, - objectOrderIds: [String] + objectOrderIds: [String], + spaceUxType: SpaceUxType? ) { self.identifier = identifier self.source = document.details?.filteredSetOf @@ -55,7 +56,7 @@ struct SetSubscriptionData: Hashable { if let groupFilter { filters.append(groupFilter) } - filters.append(SearchHelper.layoutFilter(DetailsLayout.visibleLayoutsWithFiles)) + filters.append(SearchHelper.layoutFilter(DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType))) filters.append(contentsOf: SearchHelper.notHiddenFilters()) self.filters = filters self.options = view.options diff --git a/Anytype/Sources/ServiceLayer/Object/Search/SearchService.swift b/Anytype/Sources/ServiceLayer/Object/Search/SearchService.swift index 3c38c73aa2..6c5fb3bb87 100644 --- a/Anytype/Sources/ServiceLayer/Object/Search/SearchService.swift +++ b/Anytype/Sources/ServiceLayer/Object/Search/SearchService.swift @@ -10,11 +10,13 @@ enum SearchDefaults { final class SearchService: SearchServiceProtocol, Sendable { private let searchMiddleService: any SearchMiddleServiceProtocol = Container.shared.searchMiddleService() - + private let spaceViewsStorage: any SpaceViewsStorageProtocol = Container.shared.spaceViewsStorage() + // MARK: - SearchServiceProtocol func search(text: String, spaceId: String) async throws -> [ObjectDetails] { - try await searchObjectsWithLayouts(text: text, layouts: DetailsLayout.visibleLayouts, excludedIds: [], spaceId: spaceId) + let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType + return try await searchObjectsWithLayouts(text: text, layouts: DetailsLayout.visibleLayouts(spaceUxType: spaceUxType), excludedIds: [], spaceId: spaceId) } func searchFiles(text: String, excludedFileIds: [String], spaceId: String) async throws -> [ObjectDetails] { @@ -73,10 +75,11 @@ final class SearchService: SearchServiceProtocol, Sendable { relation: BundledPropertyKey.lastOpenedDate, type: .desc ) + let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType let filters: [DataviewFilter] = .builder { SearchHelper.excludedIdsFilter(excludedObjectIds) if typeIds.isEmpty { - SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayouts) + SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayouts(spaceUxType: spaceUxType)) } else { SearchFiltersBuilder.build(isArchived: false) SearchHelper.typeFilter(typeIds) @@ -101,9 +104,10 @@ final class SearchService: SearchServiceProtocol, Sendable { relation: sortRelationKey ?? .lastOpenedDate, type: .desc ) - + let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType + let filters: [DataviewFilter] = .builder { - SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles) + SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType)) SearchHelper.excludedIdsFilter(excludedObjectIds) SearchHelper.excludedLayoutFilter(excludedLayouts) } diff --git a/Anytype/Sources/ServiceLayer/Object/TypeProvider/Subscription/ObjectTypeSubscriptionDataBuilder.swift b/Anytype/Sources/ServiceLayer/Object/TypeProvider/Subscription/ObjectTypeSubscriptionDataBuilder.swift index 6bc9e78e11..0824ebf6be 100644 --- a/Anytype/Sources/ServiceLayer/Object/TypeProvider/Subscription/ObjectTypeSubscriptionDataBuilder.swift +++ b/Anytype/Sources/ServiceLayer/Object/TypeProvider/Subscription/ObjectTypeSubscriptionDataBuilder.swift @@ -12,12 +12,13 @@ final class ObjectTypeSubscriptionDataBuilder: MultispaceSubscriptionDataBuilder let filters = [ SearchHelper.layoutFilter([DetailsLayout.objectType]) ] - + + let spaceUxType = workspaceStorage.spaceView(spaceId: spaceId)?.uxType return .search( SubscriptionData.Search( identifier: subId, spaceId: spaceId, - sorts: SearchHelper.defaultObjectTypeSort(isChat: workspaceStorage.spaceIsChat(spaceId: spaceId)), + sorts: SearchHelper.defaultObjectTypeSort(spaceUxType: spaceUxType), filters: filters, limit: 0, offset: 0, diff --git a/Anytype/Sources/ServiceLayer/Object/TypesService/SearchHelper+Extension.swift b/Anytype/Sources/ServiceLayer/Object/TypesService/SearchHelper+Extension.swift index 1ab9e0bf66..5de5c571b5 100644 --- a/Anytype/Sources/ServiceLayer/Object/TypesService/SearchHelper+Extension.swift +++ b/Anytype/Sources/ServiceLayer/Object/TypesService/SearchHelper+Extension.swift @@ -1,11 +1,12 @@ import Services extension SearchHelper { - - static func defaultObjectTypeSort(isChat: Bool) -> [DataviewSort] { + + static func defaultObjectTypeSort(spaceUxType: SpaceUxType?) -> [DataviewSort] { let nameSort = SearchHelper.sort(relation: .name, type: .asc) - - let customSort = isChat + + let showsChatLayouts = spaceUxType?.showsChatLayouts ?? true + let customSort = !showsChatLayouts ? SearchHelper.customSort(relationKey: BundledPropertyKey.uniqueKey.rawValue, values: [ ObjectTypeUniqueKey.image.value, ObjectTypeUniqueKey.bookmark.value, @@ -30,7 +31,8 @@ extension SearchHelper { ObjectTypeUniqueKey.image.value, ObjectTypeUniqueKey.file.value, ObjectTypeUniqueKey.video.value, - ObjectTypeUniqueKey.audio.value + ObjectTypeUniqueKey.audio.value, + ObjectTypeUniqueKey.chatDerived.value ]) let orderIdSort = SearchHelper.sort(relation: .orderId, type: .asc, emptyPlacement: .end) diff --git a/Anytype/Sources/ServiceLayer/Object/TypesService/TypesService.swift b/Anytype/Sources/ServiceLayer/Object/TypesService/TypesService.swift index ea0067e62d..c20c098991 100644 --- a/Anytype/Sources/ServiceLayer/Object/TypesService/TypesService.swift +++ b/Anytype/Sources/ServiceLayer/Object/TypesService/TypesService.swift @@ -55,11 +55,12 @@ final class TypesService: TypesServiceProtocol, Sendable { spaceId: String ) async throws -> [ObjectDetails] { let excludedTypeIds = includePins ? [] : try await searchPinnedTypes(text: "", spaceId: spaceId).map { $0.id } - - let sort = SearchHelper.defaultObjectTypeSort(isChat: workspaceStorage.spaceIsChat(spaceId: spaceId)) - - var layouts = includeFiles ? DetailsLayout.visibleLayoutsWithFiles : DetailsLayout.visibleLayouts - + + let spaceUxType = workspaceStorage.spaceView(spaceId: spaceId)?.uxType + let sort = SearchHelper.defaultObjectTypeSort(spaceUxType: spaceUxType) + + var layouts = includeFiles ? DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType) : DetailsLayout.visibleLayouts(spaceUxType: spaceUxType) + if !includeLists { layouts.removeAll(where: { $0.isList }) } @@ -96,9 +97,10 @@ final class TypesService: TypesServiceProtocol, Sendable { spaceId: String ) async throws -> [ObjectType] { let excludedTypeIds = includePins ? [] : try await searchPinnedTypes(text: "", spaceId: spaceId).map { $0.id } - - let sort = SearchHelper.defaultObjectTypeSort(isChat: workspaceStorage.spaceIsChat(spaceId: spaceId)) - + + let spaceUxType = workspaceStorage.spaceView(spaceId: spaceId)?.uxType + let sort = SearchHelper.defaultObjectTypeSort(spaceUxType: spaceUxType) + let filters: [DataviewFilter] = .builder { SearchFiltersBuilder.build(isArchived: false) SearchHelper.layoutFilter([DetailsLayout.objectType]) @@ -112,12 +114,13 @@ final class TypesService: TypesServiceProtocol, Sendable { func searchLibraryObjectTypes(text: String, includeInstalledTypes: Bool, spaceId: String) async throws -> [ObjectDetails] { let excludedIds = includeInstalledTypes ? [] : typeProvider.objectTypes(spaceId: spaceId).map(\.sourceObject) - - let sort = SearchHelper.defaultObjectTypeSort(isChat: workspaceStorage.spaceIsChat(spaceId: spaceId)) - + + let spaceUxType = workspaceStorage.spaceView(spaceId: spaceId)?.uxType + let sort = SearchHelper.defaultObjectTypeSort(spaceUxType: spaceUxType) + let filters = Array.builder { SearchHelper.layoutFilter([DetailsLayout.objectType]) - SearchHelper.recomendedLayoutFilter(DetailsLayout.visibleLayouts) + SearchHelper.recomendedLayoutFilter(DetailsLayout.visibleLayouts(spaceUxType: spaceUxType)) SearchHelper.excludedIdsFilter(excludedIds) } diff --git a/Anytype/Sources/ServiceLayer/SpaceStorage/SpaceViewsStorage.swift b/Anytype/Sources/ServiceLayer/SpaceStorage/SpaceViewsStorage.swift index 4be707e470..2cf0fa84eb 100644 --- a/Anytype/Sources/ServiceLayer/SpaceStorage/SpaceViewsStorage.swift +++ b/Anytype/Sources/ServiceLayer/SpaceStorage/SpaceViewsStorage.swift @@ -32,10 +32,6 @@ extension SpaceViewsStorageProtocol { .removeDuplicates() .eraseToAnyPublisher() } - - func spaceIsChat(spaceId: String) -> Bool { - spaceView(spaceId: spaceId)?.uxType.isChat ?? false - } } final class SpaceViewsStorage: SpaceViewsStorageProtocol { diff --git a/Anytype/Sources/ServiceLayer/Subscriptions/RecentSubscriptionService.swift b/Anytype/Sources/ServiceLayer/Subscriptions/RecentSubscriptionService.swift index a7efaf4de7..517acf1a95 100644 --- a/Anytype/Sources/ServiceLayer/Subscriptions/RecentSubscriptionService.swift +++ b/Anytype/Sources/ServiceLayer/Subscriptions/RecentSubscriptionService.swift @@ -41,10 +41,11 @@ final class RecentSubscriptionService: RecentSubscriptionServiceProtocol { ) async { let sort = makeSort(type: type) - + let spaceUxType = workspaceStorage.spaceView(spaceId: spaceId)?.uxType + let filters: [DataviewFilter] = .builder { SearchHelper.notHiddenFilters() - SearchHelper.layoutFilter(DetailsLayout.visibleLayouts) + SearchHelper.layoutFilter(DetailsLayout.visibleLayouts(spaceUxType: spaceUxType)) SearchHelper.templateScheme(include: false) makeDateFilter(type: type, spaceId: spaceId) } diff --git a/Modules/Services/Sources/Models/Extensions/DetailsLayoutExtension.swift b/Modules/Services/Sources/Models/Extensions/DetailsLayoutExtension.swift index 58ce2b100c..ca9a8b66df 100644 --- a/Modules/Services/Sources/Models/Extensions/DetailsLayoutExtension.swift +++ b/Modules/Services/Sources/Models/Extensions/DetailsLayoutExtension.swift @@ -8,34 +8,58 @@ public extension DetailsLayout { static let fileLayouts: [DetailsLayout] = [ .file, .pdf ] static let mediaLayouts: [DetailsLayout] = [ .image, .audio, .video ] static let fileAndMediaLayouts = DetailsLayout.fileLayouts + DetailsLayout.mediaLayouts - static let chatLayouts: [DetailsLayout] = FeatureFlags.multichats ? [.chatDerived] : [] - - static let visibleLayouts: [DetailsLayout] = listLayouts + editorLayouts + [.bookmark, .participant, .date, .objectType] + chatLayouts - static let visibleLayoutsWithFiles = visibleLayouts + fileAndMediaLayouts - - static let supportedForCreation: [DetailsLayout] = supportedForCreationInSets + listLayouts + chatLayouts + + fileprivate static let visibleLayoutsBase: [DetailsLayout] = listLayouts + editorLayouts + [.bookmark, .participant, .date, .objectType] + chatLayouts + fileprivate static let visibleLayoutsWithFilesBase = visibleLayoutsBase + fileAndMediaLayouts + + fileprivate static let supportedForCreationBase: [DetailsLayout] = supportedForCreationInSets + listLayouts + chatLayouts static let supportedForSharingExtension: [DetailsLayout] = [.collection] + editorLayouts - - static let widgetTypeLayouts = listLayouts + editorLayouts + [.bookmark] + fileAndMediaLayouts + chatLayouts - - private static let supportedForOpening: [DetailsLayout] = visibleLayoutsWithFiles + [.objectType] + + fileprivate static let widgetTypeLayoutsBase = listLayouts + editorLayouts + [.bookmark] + fileAndMediaLayouts + chatLayouts + + private static let supportedForOpening: [DetailsLayout] = visibleLayoutsWithFilesBase + [.objectType] private static let supportedForCreationInSets: [DetailsLayout] = editorLayouts + [.bookmark] + listLayouts private static let layoutsWithIcon: [DetailsLayout] = listLayouts + fileAndMediaLayouts + [.basic, .profile, .objectType] private static let layoutsWithCover: [DetailsLayout] = layoutsWithIcon + [.bookmark, .todo] + private static let chatLayouts: [DetailsLayout] = FeatureFlags.multichats ? [.chatDerived] : [] +} + +// MARK: - Space-aware filtering + +public extension DetailsLayout { + static func visibleLayouts(spaceUxType: SpaceUxType?) -> [DetailsLayout] { + guard !(spaceUxType?.showsChatLayouts ?? true) else { return visibleLayoutsBase } + return visibleLayoutsBase.filter { $0 != .chatDerived } + } + + static func visibleLayoutsWithFiles(spaceUxType: SpaceUxType?) -> [DetailsLayout] { + guard !(spaceUxType?.showsChatLayouts ?? true) else { return visibleLayoutsWithFilesBase } + return visibleLayoutsWithFilesBase.filter { $0 != .chatDerived } + } + + static func supportedForCreation(spaceUxType: SpaceUxType?) -> [DetailsLayout] { + guard !(spaceUxType?.showsChatLayouts ?? true) else { return supportedForCreationBase } + return supportedForCreationBase.filter { $0 != .chatDerived } + } + + static func widgetTypeLayouts(spaceUxType: SpaceUxType?) -> [DetailsLayout] { + guard !(spaceUxType?.showsChatLayouts ?? true) else { return widgetTypeLayoutsBase } + return widgetTypeLayoutsBase.filter { $0 != .chatDerived } + } } // MARK: - Computed properties public extension DetailsLayout { - var isVisible: Bool { DetailsLayout.visibleLayouts.contains(self) } - var isVisibleOrFile: Bool { DetailsLayout.visibleLayoutsWithFiles.contains(self) } + var isVisible: Bool { DetailsLayout.visibleLayoutsBase.contains(self) } + var isVisibleOrFile: Bool { DetailsLayout.visibleLayoutsWithFilesBase.contains(self) } var isEditorLayout: Bool { DetailsLayout.editorLayouts.contains(self) } var isFile: Bool { Self.fileLayouts.contains(self) } var isFileOrMedia: Bool { Self.fileAndMediaLayouts.contains(self) } var isSupportedForCreationInSets: Bool { Self.supportedForCreationInSets.contains(self) } var isSupportedForOpening: Bool { Self.supportedForOpening.contains(self) } - var isSupportedForCreation: Bool { Self.supportedForCreation.contains(self) } + var isSupportedForCreation: Bool { Self.supportedForCreationBase.contains(self) } var haveIcon: Bool { Self.layoutsWithIcon.contains(self) } var haveCover: Bool { Self.layoutsWithCover.contains(self) } diff --git a/Modules/Services/Sources/Models/Space/SpaceUxType+Extensions.swift b/Modules/Services/Sources/Models/Space/SpaceUxType+Extensions.swift index a92cb30bd1..e7a44891c7 100644 --- a/Modules/Services/Sources/Models/Space/SpaceUxType+Extensions.swift +++ b/Modules/Services/Sources/Models/Space/SpaceUxType+Extensions.swift @@ -12,5 +12,14 @@ public extension SpaceUxType { var isData: Bool { self == .data } + + var showsChatLayouts: Bool { + switch self { + case .chat, .stream, .none, .UNRECOGNIZED: + return false + case .data: + return true + } + } }