Skip to content

Commit 5a1ec9a

Browse files
authored
Allow customizing channel and message search in the ChatChannelListViewModel (GetStream#690)
1 parent a58e648 commit 5a1ec9a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6+
### ✅ Added
7+
- Make `CreatePollView` public [#685](https://github.com/GetStream/stream-chat-swiftui/pull/685)
8+
- Allow customizing channel and message search in the `ChatChannelListViewModel` [#XYZ](ADD)
9+
- Allow overriding `ChatChannelListViewModel.performChannelSearch` and `ChatChannelListViewModel.performMessageSearch`
10+
- Make `ChatChannelListViewModel.channelListSearchController` and `ChatChannelListViewModel.messageSearchController` public
611
### 🐞 Fixed
712
- Fix message thread reply footnote view not shown if parent message not in cache [#681](https://github.com/GetStream/stream-chat-swiftui/pull/681)
813
### ⚡ Performance
914
- Improve message search performance [#680](https://github.com/GetStream/stream-chat-swiftui/pull/680)
10-
### ✅ Added
11-
- Make `CreatePollView` public [#685](https://github.com/GetStream/stream-chat-swiftui/pull/685)
1215
### 🔄 Changed
1316
- Update `VoiceRecordingContainerView` background colors and layout by moving the message text outside of the recording cell [#689](https://github.com/GetStream/stream-chat-swiftui/pull/689/)
1417

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
102102
}
103103

104104
private let searchType: ChannelListSearchType
105-
internal var channelListSearchController: ChatChannelListController?
106-
internal var messageSearchController: ChatMessageSearchController?
105+
/// The channel search controller which should be created only by ``performChannelSearch()``.
106+
public var channelListSearchController: ChatChannelListController?
107+
/// The message search controller which should be created only by ``performMessageSearch()``.
108+
public var messageSearchController: ChatMessageSearchController?
107109

108110
/// Serial queue used to process the search results.
109111
private let queue = DispatchQueue(label: "com.getstream.stream-chat-swiftui.ChatChannelListViewModel")
@@ -388,7 +390,8 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
388390
}
389391
}
390392

391-
private func performMessageSearch() {
393+
/// Creates a new message search controller, sets its delegate, and triggers the search operation.
394+
open func performMessageSearch() {
392395
messageSearchController = chatClient.messageSearchController()
393396
messageSearchController?.delegate = self
394397
loadingSearchResults = true
@@ -397,14 +400,16 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
397400
}
398401
}
399402

400-
private func performChannelSearch() {
403+
/// Creates a new channel search controller, sets its delegate, and triggers the search operation.
404+
open func performChannelSearch() {
401405
guard let userId = chatClient.currentUserId else { return }
402406
var query = ChannelListQuery(
403407
filter: .and([
404408
.autocomplete(.name, text: searchText),
405409
.containMembers(userIds: [userId])
406410
])
407411
)
412+
// Do not start watching any of the searched channels.
408413
query.options = []
409414
channelListSearchController = chatClient.channelListController(query: query)
410415
loadingSearchResults = true

0 commit comments

Comments
 (0)