Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -28,13 +30,15 @@ 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

init(data: GlobalSearchModuleData) {
self.moduleData = data
self.restoreState()
self.loadSpaceUxType()
}

func startParticipantTask() async {
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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
)
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>?

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading