Skip to content

Commit 257563a

Browse files
authored
Expose ChatThreadListViewModel.preselectThreadIfNeeded() (#1069)
* Expose `ChatThreadListViewModel.preselectThreadIfNeeded()` * Update CHANGELOG.md
1 parent 3d9a87f commit 257563a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
### ✅ Added
77
- Open `ChatChannelInfoViewModel.leaveButtonTitle` and `ChatChannelInfoViewModel.leaveConversationDescription` [#1018](https://github.com/GetStream/stream-chat-swiftui/pull/1018)
8+
- Open `ChatThreadListViewModel.preselectThreadIfNeeded()` [#1069](https://github.com/GetStream/stream-chat-swiftui/pull/1069)
89
### 🐞 Fixed
910
- Use `muteChannel` capability for showing mute channel button in the `ChatChannelInfoView` [#1018](https://github.com/GetStream/stream-chat-swiftui/pull/1018)
1011
- Fix `PollOptionAllVotesViewModel` not loading more votes [#1067](https://github.com/GetStream/stream-chat-swiftui/pull/1067)

Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ open class ChatThreadListViewModel: ObservableObject, ChatThreadListControllerDe
155155
}
156156
}
157157

158+
/// Preselects the the thread if needed, for example, when inside an iPad Split View.
159+
open func preselectThreadIfNeeded() {
160+
guard isIPad else { return }
161+
guard let firstThread = threads.first else { return }
162+
guard selectedThread == nil else { return }
163+
164+
selectedThread = .init(thread: firstThread)
165+
}
166+
158167
public func controller(
159168
_ controller: ChatThreadListController,
160169
didChangeThreads changes: [ListChange<ChatThread>]
@@ -184,12 +193,4 @@ open class ChatThreadListViewModel: ObservableObject, ChatThreadListControllerDe
184193
private func makeDefaultEventsController() {
185194
eventsController = chatClient.eventsController()
186195
}
187-
188-
private func preselectThreadIfNeeded() {
189-
guard isIPad else { return }
190-
guard let firstThread = threads.first else { return }
191-
guard selectedThread == nil else { return }
192-
193-
selectedThread = .init(thread: firstThread)
194-
}
195196
}

0 commit comments

Comments
 (0)