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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

### 🔄 Changed
### 🐞 Fixed
- Fix openChannel not working when searching or another chat shown [#975](https://github.com/GetStream/stream-chat-swiftui/pull/975)

# [4.89.1](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.89.1)
_September 23, 2025_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
}
}
}

if isSearching {
searchText = ""
}

if selectedChannel != nil {
selectedChannel = nil
}

loadUntilFound()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,47 @@ class ChatChannelListViewModel_Tests: StreamChatTestCase {
}
wait(for: [expectation], timeout: 1.0)
}

func test_openChannel_whenSearching_shouldClearSearchState() {
// Given
let existingChannel = ChatChannel.mockDMChannel()
let channelListController = makeChannelListController(channels: [existingChannel])
let viewModel = ChatChannelListViewModel(
channelListController: channelListController,
selectedChannelId: nil,
searchType: .messages
)
viewModel.searchText = "query"
XCTAssertTrue(viewModel.isSearching, "Precondition failed: isSearching should be true before opening a channel")

// When
viewModel.openChannel(with: existingChannel.cid)

// Then
XCTAssertFalse(viewModel.isSearching, "isSearching should be false after opening a channel")
XCTAssertEqual(viewModel.searchText, "", "searchText should be cleared after opening a channel")
XCTAssertNil(viewModel.messageSearchController, "Message search controller should be cleared when search ends")
XCTAssertNil(viewModel.channelListSearchController, "Channel search controller should be cleared when search ends")
}

func test_openChannel_whenSelectedChannelIsSet_shouldClearSelectedChannel() {
// Given
let existingChannel = ChatChannel.mockDMChannel()
let targetChannel = ChatChannel.mockDMChannel() // not in the list
let channelListController = makeChannelListController(channels: [existingChannel])
let viewModel = ChatChannelListViewModel(
channelListController: channelListController,
selectedChannelId: nil
)
viewModel.selectedChannel = existingChannel.channelSelectionInfo
XCTAssertNotNil(viewModel.selectedChannel, "Precondition failed: selectedChannel should be set before opening a channel")

// When
viewModel.openChannel(with: targetChannel.cid)

// Then
XCTAssertNil(viewModel.selectedChannel, "selectedChannel should be cleared immediately when opening another channel")
}

// MARK: - private

Expand Down
Loading