From 835dba7e6c403cb1fb0573ca77c7ee92977cfd12 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Thu, 31 Oct 2024 22:13:26 +0000 Subject: [PATCH] Fix channel list state views not updating when the view is not visible (#3479) --- CHANGELOG.md | 2 ++ .../ChatChannelList/ChatChannelListVC.swift | 4 +++- .../ChatChannelListVC_Tests.swift | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c7ff85eb5..d872a53c3c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## StreamChatUI ### ✅ Added - Open `shouldMarkThreadRead` and `shouldMarkChannelRead` [#3468](https://github.com/GetStream/stream-chat-swift/pull/3468) +### 🐞 Fixed +- Fix channel list state views not updating when the view is not visible [#3479](https://github.com/GetStream/stream-chat-swift/pull/3479) # [4.65.0](https://github.com/GetStream/stream-chat-swift/releases/tag/4.65.0) _October 18, 2024_ diff --git a/Sources/StreamChatUI/ChatChannelList/ChatChannelListVC.swift b/Sources/StreamChatUI/ChatChannelList/ChatChannelListVC.swift index 329fbe2e6c2..1657316f756 100644 --- a/Sources/StreamChatUI/ChatChannelList/ChatChannelListVC.swift +++ b/Sources/StreamChatUI/ChatChannelList/ChatChannelListVC.swift @@ -410,12 +410,14 @@ open class ChatChannelListVC: _ViewController, _ controller: ChatChannelListController, didChangeChannels changes: [ListChange] ) { + handleStateChanges(controller.state) + if skipChannelUpdates { skippedRendering = true return } + reloadChannels() - handleStateChanges(controller.state) } // MARK: - DataControllerStateDelegate diff --git a/Tests/StreamChatUITests/SnapshotTests/ChatChannelList/ChatChannelListVC_Tests.swift b/Tests/StreamChatUITests/SnapshotTests/ChatChannelList/ChatChannelListVC_Tests.swift index ce932bcc555..4607292e2e1 100644 --- a/Tests/StreamChatUITests/SnapshotTests/ChatChannelList/ChatChannelListVC_Tests.swift +++ b/Tests/StreamChatUITests/SnapshotTests/ChatChannelList/ChatChannelListVC_Tests.swift @@ -267,6 +267,22 @@ final class ChatChannelListVC_Tests: XCTestCase { XCTAssertEqual(channelListVC.skippedRendering, true) } + func test_didChangeChannels_whenIsNotVisible_shouldStillUpdateStateViews() { + mockedChannelListController.channels_mock = [.mock(cid: .unique)] + mockedChannelListController.state_mock = .remoteDataFetched + let channelListVC = FakeChatChannelListVC() + channelListVC.components.isChatChannelListStatesEnabled = true + channelListVC.controller = mockedChannelListController + channelListVC.shouldMockViewIfLoaded = false + channelListVC.emptyView.isHidden = false + + channelListVC.controller(mockedChannelListController, didChangeChannels: []) + + XCTAssertEqual(channelListVC.emptyView.isHidden, true) + XCTAssertEqual(channelListVC.mockedCollectionView.performBatchUpdatesCallCount, 0) + XCTAssertEqual(channelListVC.mockedCollectionView.reloadDataCallCount, 0) + } + func test_didChangeChannels_whenEmptyViewVisible_whenNewChannelsNotEmpty_shouldHideEmptyView() { let channelListVC = FakeChatChannelListVC() channelListVC.components.isChatChannelListStatesEnabled = true