Skip to content

Commit 7f30dc7

Browse files
committed
IOS-5425 Hide Chat type and objects in Chat spaces with space-aware filtering
Added conditional filtering to exclude Chat type from type pickers and Chat objects from search results when in Chat spaces. - Added SearchHelper.filterOutChatType() to filter Chat objects by uniqueKey - Extended SearchFiltersBuilder with space-aware overload that applies Chat filter - Updated all search services to use space-aware filtering (SearchWithMetaService, MentionObjectsService, SearchService, DateRelatedObjectsSubscriptionService) - Added TypesService filter to exclude Chat type from type pickers when includeChat=false - Created Optional<SpaceUxType>.showsChatLayouts extension to eliminate duplicated logic - Replaced !(spaceUxType?.showsChatLayouts ?? true) pattern with cleaner !spaceUxType.showsChatLayouts Fixes chat type/object visibility in: - Global search results - Mention suggestions (@mention) - Link to object search - Attach object menu in chat input - Type pickers for new object creation
1 parent 47fc338 commit 7f30dc7

File tree

9 files changed

+65
-32
lines changed

9 files changed

+65
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class DateRelatedObjectsSubscriptionService: DateRelatedObjectsSubscriptio
3737

3838
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
3939
let filters: [DataviewFilter] = .builder {
40-
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType))
40+
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType), spaceUxType: spaceUxType)
4141
filters
4242
}
4343

Anytype/Sources/ServiceLayer/Block/Mention/MentionObjectsService.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ protocol MentionObjectsServiceProtocol: AnyObject, Sendable {
77
}
88

99
final class MentionObjectsService: MentionObjectsServiceProtocol, Sendable {
10-
10+
1111
private let searchMiddleService: any SearchMiddleServiceProtocol = Container.shared.searchMiddleService()
12-
12+
private let spaceViewsStorage: any SpaceViewsStorageProtocol = Container.shared.spaceViewsStorage()
13+
1314
func searchMentions(spaceId: String, text: String, excludedObjectIds: [String], limitLayout: [DetailsLayout]) async throws -> [MentionObject] {
1415
let sort = SearchHelper.sort(
1516
relation: .lastOpenedDate,
1617
type: .desc
1718
)
18-
19+
20+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
1921
let filters: [DataviewFilter] = .builder {
20-
SearchFiltersBuilder.build(isArchived: false, layouts: limitLayout)
22+
SearchFiltersBuilder.build(isArchived: false, layouts: limitLayout, spaceUxType: spaceUxType)
2123
SearchHelper.excludedIdsFilter(excludedObjectIds)
2224
}
23-
25+
2426
let details = try await searchMiddleService.search(spaceId: spaceId, filters: filters, sorts: [sort], fullText: text)
25-
27+
2628
return details.map { MentionObject(details: $0) }
2729
}
2830

Anytype/Sources/ServiceLayer/Object/Search/SearchService.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ final class SearchService: SearchServiceProtocol, Sendable {
7979
let filters: [DataviewFilter] = .builder {
8080
SearchHelper.excludedIdsFilter(excludedObjectIds)
8181
if typeIds.isEmpty {
82-
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayouts(spaceUxType: spaceUxType))
82+
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayouts(spaceUxType: spaceUxType), spaceUxType: spaceUxType)
8383
} else {
8484
SearchFiltersBuilder.build(isArchived: false)
8585
SearchHelper.typeFilter(typeIds)
@@ -107,7 +107,7 @@ final class SearchService: SearchServiceProtocol, Sendable {
107107
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
108108

109109
let filters: [DataviewFilter] = .builder {
110-
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType))
110+
SearchFiltersBuilder.build(isArchived: false, layouts: DetailsLayout.visibleLayoutsWithFiles(spaceUxType: spaceUxType), spaceUxType: spaceUxType)
111111
SearchHelper.excludedIdsFilter(excludedObjectIds)
112112
SearchHelper.excludedLayoutFilter(excludedLayouts)
113113
}
@@ -116,9 +116,12 @@ final class SearchService: SearchServiceProtocol, Sendable {
116116
}
117117

118118
func searchRelationOptions(text: String, relationKey: String, excludedObjectIds: [String], spaceId: String) async throws -> [PropertyOption] {
119+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
120+
119121
var filters = SearchFiltersBuilder.build(
120122
isArchived: false,
121-
layouts: [DetailsLayout.relationOption]
123+
layouts: [DetailsLayout.relationOption],
124+
spaceUxType: spaceUxType
122125
)
123126
filters.append(SearchHelper.relationKey(relationKey))
124127
filters.append(SearchHelper.excludedIdsFilter(excludedObjectIds))
@@ -133,9 +136,12 @@ final class SearchService: SearchServiceProtocol, Sendable {
133136
}
134137

135138
func searchRelationOptions(optionIds: [String], spaceId: String) async throws -> [PropertyOption] {
139+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
140+
136141
var filters = SearchFiltersBuilder.build(
137142
isArchived: false,
138-
layouts: [DetailsLayout.relationOption]
143+
layouts: [DetailsLayout.relationOption],
144+
spaceUxType: spaceUxType
139145
)
140146
filters.append(SearchHelper.includeIdsFilter(optionIds))
141147

@@ -149,14 +155,15 @@ final class SearchService: SearchServiceProtocol, Sendable {
149155
type: .desc,
150156
includeTime: true
151157
)
152-
158+
159+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
153160
let filters: [DataviewFilter] = .builder {
154-
SearchFiltersBuilder.build(isArchived: false, layouts: [DetailsLayout.relation])
161+
SearchFiltersBuilder.build(isArchived: false, layouts: [DetailsLayout.relation], spaceUxType: spaceUxType)
155162
SearchHelper.relationReadonlyValue(false)
156163
SearchHelper.excludedRelationKeys(BundledPropertyKey.internalKeys.map(\.rawValue))
157164
SearchHelper.excludedIdsFilter(excludedIds)
158165
}
159-
166+
160167
let details = try await searchMiddleService.search(spaceId: spaceId, filters: filters, sorts: [sort], fullText: text)
161168
return details.map { PropertyDetails(details: $0) }
162169
}
@@ -190,12 +197,13 @@ final class SearchService: SearchServiceProtocol, Sendable {
190197
relation: BundledPropertyKey.lastOpenedDate,
191198
type: .desc
192199
)
193-
200+
201+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
194202
let filters: [DataviewFilter] = .builder {
195-
SearchFiltersBuilder.build(isArchived: false, layouts: layouts)
203+
SearchFiltersBuilder.build(isArchived: false, layouts: layouts, spaceUxType: spaceUxType)
196204
SearchHelper.excludedIdsFilter(excludedIds)
197205
}
198-
206+
199207
return try await searchMiddleService.search(spaceId: spaceId, filters: filters, sorts: [sort], fullText: text, limit: SearchDefaults.objectsLimit)
200208
}
201209

Anytype/Sources/ServiceLayer/Object/SearchWithMeta/SearchWithMetaService.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ protocol SearchWithMetaServiceProtocol: AnyObject, Sendable {
1313
}
1414

1515
final class SearchWithMetaService: SearchWithMetaServiceProtocol, Sendable {
16-
16+
1717
private let searchWithMetaMiddleService: any SearchWithMetaMiddleServiceProtocol = Container.shared.searchWithMetaMiddleService()
18-
18+
private let spaceViewsStorage: any SpaceViewsStorageProtocol = Container.shared.spaceViewsStorage()
19+
1920
// MARK: - SearchServiceProtocol
20-
21+
2122
func search(
2223
text: String,
2324
spaceId: String,
2425
layouts: [DetailsLayout],
2526
sorts: [DataviewSort],
2627
excludedObjectIds: [String]
2728
) async throws -> [SearchResultWithMeta] {
28-
29+
30+
let spaceUxType = spaceViewsStorage.spaceView(spaceId: spaceId)?.uxType
2931
let filters: [DataviewFilter] = .builder {
30-
SearchFiltersBuilder.build(isArchived: false, layouts: layouts)
32+
SearchFiltersBuilder.build(isArchived: false, layouts: layouts, spaceUxType: spaceUxType)
3133
SearchHelper.excludedIdsFilter(excludedObjectIds)
3234
}
33-
35+
3436
return try await searchWithMetaMiddleService.search(spaceId: spaceId, filters: filters, sorts: sorts, fullText: text, limit: SearchDefaults.objectsLimit)
3537
}
3638
}

Anytype/Sources/ServiceLayer/Object/TypesService/TypesService.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ final class TypesService: TypesServiceProtocol, Sendable {
8484
if !includeTemplates {
8585
SearchHelper.uniqueKeyFilter(key: ObjectTypeUniqueKey.template.value, include: false)
8686
}
87+
if !includeChat {
88+
SearchHelper.uniqueKeyFilter(key: ObjectTypeUniqueKey.chatDerived.value, include: false)
89+
}
8790
}
8891

8992
let result = try await searchMiddleService.search(spaceId: spaceId, filters: filters, sorts: sort, fullText: text)

Modules/Services/Sources/Models/Extensions/DetailsLayoutExtension.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ public extension DetailsLayout {
2727

2828
public extension DetailsLayout {
2929
static func visibleLayouts(spaceUxType: SpaceUxType?) -> [DetailsLayout] {
30-
guard !(spaceUxType?.showsChatLayouts ?? true) else { return visibleLayoutsBase }
30+
guard !spaceUxType.showsChatLayouts else { return visibleLayoutsBase }
3131
return visibleLayoutsBase.filter { $0 != .chatDerived }
3232
}
3333

3434
static func visibleLayoutsWithFiles(spaceUxType: SpaceUxType?) -> [DetailsLayout] {
35-
guard !(spaceUxType?.showsChatLayouts ?? true) else { return visibleLayoutsWithFilesBase }
35+
guard !spaceUxType.showsChatLayouts else { return visibleLayoutsWithFilesBase }
3636
return visibleLayoutsWithFilesBase.filter { $0 != .chatDerived }
3737
}
3838

3939
static func supportedForCreation(spaceUxType: SpaceUxType?) -> [DetailsLayout] {
40-
guard !(spaceUxType?.showsChatLayouts ?? true) else { return supportedForCreationBase }
40+
guard !spaceUxType.showsChatLayouts else { return supportedForCreationBase }
4141
return supportedForCreationBase.filter { $0 != .chatDerived }
4242
}
4343

4444
static func widgetTypeLayouts(spaceUxType: SpaceUxType?) -> [DetailsLayout] {
45-
guard !(spaceUxType?.showsChatLayouts ?? true) else { return widgetTypeLayoutsBase }
45+
guard !spaceUxType.showsChatLayouts else { return widgetTypeLayoutsBase }
4646
return widgetTypeLayoutsBase.filter { $0 != .chatDerived }
4747
}
4848
}

Modules/Services/Sources/Models/Space/SpaceUxType+Extensions.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ public extension SpaceUxType {
44
var isStream: Bool {
55
self == .stream
66
}
7-
7+
88
var isChat: Bool {
99
self == .chat
1010
}
11-
11+
1212
var isData: Bool {
1313
self == .data
1414
}
@@ -23,3 +23,9 @@ public extension SpaceUxType {
2323
}
2424
}
2525

26+
public extension Optional where Wrapped == SpaceUxType {
27+
var showsChatLayouts: Bool {
28+
self?.showsChatLayouts ?? true
29+
}
30+
}
31+

Modules/Services/Sources/Services/SearchService/SearchFiltersBuilder.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ public final class SearchFiltersBuilder {
55
SearchHelper.notHiddenFilters(isArchive: isArchived)
66
}
77
}
8-
9-
public static func build(isArchived: Bool, layouts: [DetailsLayout]) -> [DataviewFilter] {
8+
9+
public static func build(isArchived: Bool, layouts: [DetailsLayout], spaceUxType: SpaceUxType?) -> [DataviewFilter] {
1010
var filters = build(isArchived: isArchived)
1111
filters.append(SearchHelper.layoutFilter(layouts))
1212
filters.append(SearchHelper.templateScheme(include: false))
13+
if !spaceUxType.showsChatLayouts {
14+
filters.append(SearchHelper.filterOutChatType())
15+
}
1316
return filters
1417
}
1518
}

Modules/Services/Sources/Services/SearchService/SearchHelper.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,16 @@ public class SearchHelper {
264264

265265
return filter
266266
}
267-
267+
268+
public static func filterOutChatType() -> DataviewFilter {
269+
var filter = DataviewFilter()
270+
filter.condition = .notEqual
271+
filter.relationKey = "\(BundledPropertyKey.uniqueKey.rawValue)"
272+
filter.value = ObjectTypeUniqueKey.chatDerived.value.protobufValue
273+
274+
return filter
275+
}
276+
268277
public static func filterOutTypeType() -> DataviewFilter {
269278
var filter = DataviewFilter()
270279
filter.condition = .notEqual

0 commit comments

Comments
 (0)