diff --git a/CHANGELOG.md b/CHANGELOG.md index ae2c3ac5..f9360c50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### ✅ Added - Open `ChatChannelInfoViewModel.leaveButtonTitle` and `ChatChannelInfoViewModel.leaveConversationDescription` [#1018](https://github.com/GetStream/stream-chat-swiftui/pull/1018) +- Open `ChatThreadListViewModel.preselectThreadIfNeeded()` [#1069](https://github.com/GetStream/stream-chat-swiftui/pull/1069) ### 🐞 Fixed - Use `muteChannel` capability for showing mute channel button in the `ChatChannelInfoView` [#1018](https://github.com/GetStream/stream-chat-swiftui/pull/1018) - Fix `PollOptionAllVotesViewModel` not loading more votes [#1067](https://github.com/GetStream/stream-chat-swiftui/pull/1067) diff --git a/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift b/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift index a466da38..bc88697c 100644 --- a/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift @@ -155,6 +155,15 @@ open class ChatThreadListViewModel: ObservableObject, ChatThreadListControllerDe } } + /// Preselects the the thread if needed, for example, when inside an iPad Split View. + open func preselectThreadIfNeeded() { + guard isIPad else { return } + guard let firstThread = threads.first else { return } + guard selectedThread == nil else { return } + + selectedThread = .init(thread: firstThread) + } + public func controller( _ controller: ChatThreadListController, didChangeThreads changes: [ListChange] @@ -184,12 +193,4 @@ open class ChatThreadListViewModel: ObservableObject, ChatThreadListControllerDe private func makeDefaultEventsController() { eventsController = chatClient.eventsController() } - - private func preselectThreadIfNeeded() { - guard isIPad else { return } - guard let firstThread = threads.first else { return } - guard selectedThread == nil else { return } - - selectedThread = .init(thread: firstThread) - } }