Skip to content

Added a method for configuring the channel alert type #801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### ✅ Added
- Allow pasting images to the composer [#797](https://github.com/GetStream/stream-chat-swiftui/pull/797)
- Add `ChatChannelListViewModel.setChannelAlertType` for setting the alert type [#801](https://github.com/GetStream/stream-chat-swiftui/pull/801)
### 🐞 Fixed
- Fix allowing to send Polls when the current user does not have the capability [#798](https://github.com/GetStream/stream-chat-swiftui/pull/798)
- Fix showing a double error indicator when sending attachments without any text [#799](https://github.com/GetStream/stream-chat-swiftui/pull/799)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
}

public func onDeleteTapped(channel: ChatChannel) {
channelAlertType = .deleteChannel(channel)
setChannelAlertType(.deleteChannel(channel))
}

public func onMoreTapped(channel: ChatChannel) {
Expand All @@ -217,13 +217,17 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
controller.deleteChannel { [weak self] error in
if error != nil {
// handle error
self?.channelAlertType = .error
self?.setChannelAlertType(.error)
Copy link
Member

@nuno-vieira nuno-vieira Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the customer have access to the actual error? 🤔 Otherwise, if they want to display an alert depending on the error type, it will be difficult. To make this more flexible, we should have at least in the future something like we do on the ThreadList, where a customer can totaly customize the Error view by implementing a modifier: https://getstream.io/chat/docs/sdk/ios/swiftui/thread-list/#thread-list-states

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can expose a modifier in the future. Basically this customer wants to disable all errors.

}
}
}

open func showErrorPopup(_ error: Error?) {
channelAlertType = .error
setChannelAlertType(.error)
}

open func setChannelAlertType(_ channelAlertType: ChannelAlertType) {
self.channelAlertType = channelAlertType
}

// MARK: - ChatChannelListControllerDelegate
Expand Down Expand Up @@ -328,7 +332,7 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
self.loading = false
if error != nil {
// handle error
self.channelAlertType = .error
self.setChannelAlertType(.error)
} else {
// access channels
self.updateChannels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,19 @@ class ChatChannelListViewModel_Tests: StreamChatTestCase {
XCTAssert(viewModel.channelAlertType == .error)
XCTAssert(viewModel.alertShown == true)
}


func test_channelListVM_setChannelAlertType() {
// Given
let viewModel = makeDefaultChannelListVM()

// When
viewModel.setChannelAlertType(.error)

// Then
XCTAssert(viewModel.channelAlertType == .error)
XCTAssert(viewModel.alertShown == true)
}

func test_channelListVM_nameForChannel() {
// Given
let expectedName = "test"
Expand Down
Loading