Skip to content

Commit 8f3f169

Browse files
Added a method for configuring the channel alert type (#801)
1 parent c413786 commit 8f3f169

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
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
- Allow pasting images to the composer [#797](https://github.com/GetStream/stream-chat-swiftui/pull/797)
8+
- Add `ChatChannelListViewModel.setChannelAlertType` for setting the alert type [#801](https://github.com/GetStream/stream-chat-swiftui/pull/801)
89
### 🐞 Fixed
910
- Fix allowing to send Polls when the current user does not have the capability [#798](https://github.com/GetStream/stream-chat-swiftui/pull/798)
1011
- Fix showing a double error indicator when sending attachments without any text [#799](https://github.com/GetStream/stream-chat-swiftui/pull/799)

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
202202
}
203203

204204
public func onDeleteTapped(channel: ChatChannel) {
205-
channelAlertType = .deleteChannel(channel)
205+
setChannelAlertType(.deleteChannel(channel))
206206
}
207207

208208
public func onMoreTapped(channel: ChatChannel) {
@@ -217,13 +217,17 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
217217
controller.deleteChannel { [weak self] error in
218218
if error != nil {
219219
// handle error
220-
self?.channelAlertType = .error
220+
self?.setChannelAlertType(.error)
221221
}
222222
}
223223
}
224224

225225
open func showErrorPopup(_ error: Error?) {
226-
channelAlertType = .error
226+
setChannelAlertType(.error)
227+
}
228+
229+
open func setChannelAlertType(_ channelAlertType: ChannelAlertType) {
230+
self.channelAlertType = channelAlertType
227231
}
228232

229233
// MARK: - ChatChannelListControllerDelegate
@@ -328,7 +332,7 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
328332
self.loading = false
329333
if error != nil {
330334
// handle error
331-
self.channelAlertType = .error
335+
self.setChannelAlertType(.error)
332336
} else {
333337
// access channels
334338
self.updateChannels()

StreamChatSwiftUITests/Tests/ChatChannelList/ChatChannelListViewModel_Tests.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,19 @@ class ChatChannelListViewModel_Tests: StreamChatTestCase {
110110
XCTAssert(viewModel.channelAlertType == .error)
111111
XCTAssert(viewModel.alertShown == true)
112112
}
113-
113+
114+
func test_channelListVM_setChannelAlertType() {
115+
// Given
116+
let viewModel = makeDefaultChannelListVM()
117+
118+
// When
119+
viewModel.setChannelAlertType(.error)
120+
121+
// Then
122+
XCTAssert(viewModel.channelAlertType == .error)
123+
XCTAssert(viewModel.alertShown == true)
124+
}
125+
114126
func test_channelListVM_nameForChannel() {
115127
// Given
116128
let expectedName = "test"

0 commit comments

Comments
 (0)