Skip to content

Commit 56f8038

Browse files
authored
Merge pull request #4198 from anyproto/ios-5425-hide-chat-type-chat-widget-in-chat-spaces-from-every-wehere
IOS-5425 Hide chat layouts in chat spaces with space-aware filtering
2 parents d2d667e + 68e53d2 commit 56f8038

File tree

21 files changed

+166
-78
lines changed

21 files changed

+166
-78
lines changed

Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/GlobalSearchViewModel.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ final class GlobalSearchViewModel: ObservableObject {
1818
private var accountParticipantStorage: any ParticipantsStorageProtocol
1919
@Injected(\.objectActionsService)
2020
private var objectActionService: any ObjectActionsServiceProtocol
21-
21+
@Injected(\.spaceViewsStorage)
22+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
23+
2224
private let moduleData: GlobalSearchModuleData
2325

2426
private let dateFormatter = AnytypeRelativeDateTimeFormatter()
@@ -28,13 +30,15 @@ final class GlobalSearchViewModel: ObservableObject {
2830
@Published var dismiss = false
2931
@Published private var participantCanEdit = false
3032

33+
private var spaceUxType: SpaceUxType?
3134
private var searchResult = [SearchResultWithMeta]()
3235
private var sectionChanged = false
3336
var isInitial = true
3437

3538
init(data: GlobalSearchModuleData) {
3639
self.moduleData = data
3740
self.restoreState()
41+
self.loadSpaceUxType()
3842
}
3943

4044
func startParticipantTask() async {
@@ -97,6 +101,10 @@ final class GlobalSearchViewModel: ObservableObject {
97101
UISelectionFeedbackGenerator().selectionChanged()
98102
}
99103

104+
private func loadSpaceUxType() {
105+
spaceUxType = spaceViewsStorage.spaceView(spaceId: moduleData.spaceId)?.uxType
106+
}
107+
100108
private func updateSections() {
101109
guard searchResult.isNotEmpty else {
102110
sections = []
@@ -161,11 +169,11 @@ final class GlobalSearchViewModel: ObservableObject {
161169
}
162170

163171
private func buildLayouts() -> [DetailsLayout] {
164-
.builder {
172+
return .builder {
165173
if state.searchText.isEmpty {
166-
state.section.supportedLayouts.filter { $0 != .participant }
174+
state.section.supportedLayouts(spaceUxType: spaceUxType).filter { $0 != .participant }
167175
} else {
168-
state.section.supportedLayouts
176+
state.section.supportedLayouts(spaceUxType: spaceUxType)
169177
}
170178
}
171179
}

Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/GlobalSearch/Models/ObjectTypeSection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ enum ObjectTypeSection: String, CaseIterable, Codable {
3434
}
3535
}
3636

37-
var supportedLayouts: [DetailsLayout] {
37+
func supportedLayouts(spaceUxType: SpaceUxType?) -> [DetailsLayout] {
3838
switch self {
3939
case .all:
40-
DetailsLayout.visibleLayoutsWithFiles
40+
DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType)
4141
case .pages:
4242
DetailsLayout.editorLayouts
4343
case .lists:

Anytype/Sources/PresentationLayer/Common/SwiftUI/Search/ObjectSearchWithMeta/ObjectSearchWithMetaViewModel.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ final class ObjectSearchWithMetaViewModel: ObservableObject {
1111
private var searchWithMetaService: any SearchWithMetaServiceProtocol
1212
@Injected(\.searchWithMetaModelBuilder)
1313
private var searchWithMetaModelBuilder: any SearchWithMetaModelBuilderProtocol
14-
14+
@Injected(\.spaceViewsStorage)
15+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
16+
1517
private let dateFormatter = AnytypeRelativeDateTimeFormatter()
1618

1719
@Published var searchText = ""
@@ -36,7 +38,7 @@ final class ObjectSearchWithMetaViewModel: ObservableObject {
3638
searchResult = try await searchWithMetaService.search(
3739
text: searchText,
3840
spaceId: moduleData.spaceId,
39-
layouts: ObjectSearchWithMetaModuleData.supportedLayouts,
41+
layouts: supportedLayouts(),
4042
sorts: buildSorts(),
4143
excludedObjectIds: moduleData.excludedObjectIds
4244
)
@@ -109,9 +111,10 @@ final class ObjectSearchWithMetaViewModel: ObservableObject {
109111
)
110112
}
111113
}
112-
}
113114

114-
extension ObjectSearchWithMetaModuleData {
115-
static let supportedLayouts: [DetailsLayout] =
116-
ObjectTypeSection.pages.supportedLayouts + ObjectTypeSection.lists.supportedLayouts
115+
private func supportedLayouts() -> [DetailsLayout] {
116+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: moduleData.spaceId)?.uxType
117+
return ObjectTypeSection.pages.supportedLayouts(spaceUxType: spaceUxType) +
118+
ObjectTypeSection.lists.supportedLayouts(spaceUxType: spaceUxType)
119+
}
117120
}

Anytype/Sources/PresentationLayer/Modules/Date/Subscription/DateRelatedObjectsSubscriptionService.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ final class DateRelatedObjectsSubscriptionService: DateRelatedObjectsSubscriptio
1818

1919
@Injected(\.subscriptionStorageProvider)
2020
private var subscriptionStorageProvider: any SubscriptionStorageProviderProtocol
21+
@Injected(\.spaceViewsStorage)
22+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
2123
private lazy var subscriptionStorage: any SubscriptionStorageProtocol = {
2224
subscriptionStorageProvider.createSubscriptionStorage(subId: subscriptionId)
2325
}()
@@ -33,8 +35,9 @@ final class DateRelatedObjectsSubscriptionService: DateRelatedObjectsSubscriptio
3335
update: @escaping @MainActor ([ObjectDetails], Int) -> Void
3436
) async {
3537

38+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
3639
let filters: [DataviewFilter] = .builder {
37-
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles)
40+
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType))
3841
filters
3942
}
4043

Anytype/Sources/PresentationLayer/Modules/HomeNavigationContainer/Panel/HomeBottomNavigationPanelViewModel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ final class HomeBottomNavigationPanelViewModel: ObservableObject {
3737
private var objectActionsService: any ObjectActionsServiceProtocol
3838
@Injected(\.experimentalFeaturesStorage)
3939
private var experimentalFeaturesStorage: any ExperimentalFeaturesStorageProtocol
40-
40+
@Injected(\.spaceViewsStorage)
41+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
42+
4143
private weak var output: (any HomeBottomNavigationPanelModuleOutput)?
4244
private let subId = "HomeBottomNavigationProfile-\(UUID().uuidString)"
4345

@@ -161,8 +163,10 @@ final class HomeBottomNavigationPanelViewModel: ObservableObject {
161163

162164
private func typesSubscription() async {
163165
for await types in objectTypeProvider.objectTypesPublisher(spaceId: info.accountSpaceId).values {
166+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: info.accountSpaceId)?.uxType
167+
let supportedLayouts = DetailsLayout.supportedForCreation(spaceUxType: spaceUxType)
164168
let types = types.filter { type in
165-
DetailsLayout.supportedForCreation.contains { $0 == type.recommendedLayout }
169+
supportedLayouts.contains { $0 == type.recommendedLayout }
166170
&& !type.isTemplateType
167171
}
168172

Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Container/HomeWidgetsViewModel.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ final class HomeWidgetsViewModel {
158158

159159
private func startObjectTypesTask() async {
160160
let spaceId = spaceId
161-
161+
let spaceUxType = workspaceStorage.spaceView(spaceId: spaceId)?.uxType
162+
let allowedLayouts = DetailsLayout.widgetTypeLayouts(spaceUxType: spaceUxType)
163+
162164
let stream = objectTypeProvider.objectTypesPublisher(spaceId: spaceId)
163165
.values
164166
.map { objects in
165167
let objects = objects
166-
.filter { ($0.recommendedLayout.map { DetailsLayout.widgetTypeLayouts.contains($0) } ?? false) && !$0.isTemplateType }
168+
.filter { ($0.recommendedLayout.map { allowedLayouts.contains($0) } ?? false) && !$0.isTemplateType }
167169
return objects.map { ObjectTypeWidgetInfo(objectTypeId: $0.id, spaceId: spaceId) }
168170
}
169171
.removeDuplicates()

Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/ObjectType/Helpers/ObjectTypeRowsBuilder.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ actor ObjectTypeRowsBuilder: ObjectTypeRowsBuilderProtocol {
2424
private var setObjectWidgetOrderHelper: any SetObjectWidgetOrderHelperProtocol
2525
@LazyInjected(\.subscriptionStorageProvider)
2626
private var subscriptionStorageProvider: any SubscriptionStorageProviderProtocol
27-
27+
@LazyInjected(\.spaceViewsStorage)
28+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
29+
2830
private lazy var subscriptionStorage: any SubscriptionStorageProtocol = {
2931
subscriptionStorageProvider.createSubscriptionStorage(subId: subscriptionId)
3032
}()
@@ -71,7 +73,8 @@ actor ObjectTypeRowsBuilder: ObjectTypeRowsBuilderProtocol {
7173
private func startObjectsSubscription() async {
7274
do {
7375
try await setDocument.open()
74-
76+
77+
let spaceUxType = await spaceViewsStorage.spaceView(spaceId: setDocument.spaceId)?.uxType
7578
let subscriptionData = setSubscriptionDataBuilder.set(
7679
SetSubscriptionData(
7780
identifier: subscriptionId,
@@ -80,7 +83,8 @@ actor ObjectTypeRowsBuilder: ObjectTypeRowsBuilderProtocol {
8083
currentPage: 0,
8184
numberOfRowsPerPage: 6,
8285
collectionId: nil,
83-
objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId)
86+
objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId),
87+
spaceUxType: spaceUxType
8488
)
8589
)
8690

Anytype/Sources/PresentationLayer/Modules/HomeWidgets/Widgets/SpecificInternalModels/SetObjectWidgetInternalViewModel.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ final class SetObjectWidgetInternalViewModel {
3131
private var objectTypeProvider: any ObjectTypeProviderProtocol
3232
@Injected(\.setObjectWidgetOrderHelper) @ObservationIgnored
3333
private var setObjectWidgetOrderHelper: any SetObjectWidgetOrderHelperProtocol
34-
34+
@Injected(\.spaceViewsStorage) @ObservationIgnored
35+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
36+
3537
// MARK: - State
3638
@ObservationIgnored
3739
private var widgetInfo: BlockWidgetInfo?
@@ -207,7 +209,8 @@ final class SetObjectWidgetInternalViewModel {
207209
}
208210

209211
guard setDocument.canStartSubscription() else { return }
210-
212+
213+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: setDocument.spaceId)?.uxType
211214
let subscriptionData = setSubscriptionDataBuilder.set(
212215
SetSubscriptionData(
213216
identifier: subscriptionId,
@@ -216,7 +219,8 @@ final class SetObjectWidgetInternalViewModel {
216219
currentPage: 0,
217220
numberOfRowsPerPage: widgetInfo.fixedLimit,
218221
collectionId: setDocument.isCollection() ? setDocument.objectId : nil,
219-
objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId)
222+
objectOrderIds: setDocument.objectOrderIds(for: setSubscriptionDataBuilder.subscriptionId),
223+
spaceUxType: spaceUxType
220224
)
221225
)
222226

Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/Dataview/SetObjectCreationSettingsInteractor.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ final class SetObjectCreationSettingsInteractor: SetObjectCreationSettingsIntera
6262
private var typesService: any TypesServiceProtocol
6363
@Injected(\.dataviewService)
6464
private var dataviewService: any DataviewServiceProtocol
65-
65+
@Injected(\.spaceViewsStorage)
66+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
67+
6668
@Published private var templatesDetails = [ObjectDetails]()
6769
@Published private var defaultTemplateId: String
6870
@Published private var typeDefaultTemplateId: String = ""
@@ -152,13 +154,16 @@ final class SetObjectCreationSettingsInteractor: SetObjectCreationSettingsIntera
152154

153155
private func updateObjectTypes() {
154156
Task {
157+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: setDocument.spaceId)?.uxType
158+
let chatTypeVisible = spaceUxType?.showsChatLayouts ?? true
159+
let includeChat = FeatureFlags.multichats && chatTypeVisible
155160
objectTypes = try await typesService.searchObjectTypes(
156161
text: "",
157162
includePins: true,
158163
includeLists: true,
159164
includeBookmarks: true,
160165
includeFiles: false,
161-
includeChat: FeatureFlags.multichats,
166+
includeChat: includeChat,
162167
includeTemplates: false,
163168
incudeNotForCreation: false,
164169
spaceId: setDocument.spaceId

Anytype/Sources/PresentationLayer/ObjectTypeSearch/ObjectTypeSearchViewModel.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ final class ObjectTypeSearchViewModel: ObservableObject {
2929
private var pasteboardHelper: any PasteboardHelperProtocol
3030
@Injected(\.participantsStorage)
3131
private var accountParticipantStorage: any ParticipantsStorageProtocol
32-
32+
@Injected(\.spaceViewsStorage)
33+
private var spaceViewsStorage: any SpaceViewsStorageProtocol
34+
3335
private let onSelect: (TypeSelectionResult) -> Void
3436
private var searchTask: Task<(), any Error>?
3537

@@ -73,6 +75,9 @@ final class ObjectTypeSearchViewModel: ObservableObject {
7375
searchTask?.cancel()
7476

7577
searchTask = Task {
78+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
79+
let effectiveShowChat = settings.showChat && (spaceUxType?.showsChatLayouts ?? true)
80+
7681
let pinnedTypes = settings.showPins ? try await typesService.searchPinnedTypes(text: text, spaceId: spaceId) : []
7782
let listTypes = settings.showLists ? try await typesService.searchListTypes(
7883
text: searchText, includePins: !settings.showPins, spaceId: spaceId
@@ -83,7 +88,7 @@ final class ObjectTypeSearchViewModel: ObservableObject {
8388
includeLists: false,
8489
includeBookmarks: true,
8590
includeFiles: settings.showFiles,
86-
includeChat: settings.showChat,
91+
includeChat: effectiveShowChat,
8792
includeTemplates: settings.showTemplates,
8893
incudeNotForCreation: settings.incudeNotForCreation,
8994
spaceId: spaceId

0 commit comments

Comments
 (0)