Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Expose `FilePickerView.init(fileURLs:)` [#1049](https://github.com/GetStream/stream-chat-swiftui/pull/1049)
- Add `MessageComposerViewModel.updateAddedAssets()` [#1049](https://github.com/GetStream/stream-chat-swiftui/pull/1049)

### 🐞 Fixed
- Fix `Throttler` crash in `ChatChannelViewModel.handleMessageAppear()` [#1050](https://github.com/GetStream/stream-chat-swiftui/pull/1050)
- Remove unnecessary channel query call when leaving the channel view in a mid-page [#1050](https://github.com/GetStream/stream-chat-swiftui/pull/1050)

# [4.92.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.92.0)
_November 07, 2025_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
private var channelName = ""
private var onlineIndicatorShown = false
private var lastReadMessageId: String?
var throttler = Throttler(interval: 3, broadcastLatestEvent: true)
var throttler = Throttler(interval: 3, broadcastLatestEvent: true, queue: .main)

public var channelController: ChatChannelController
public var messageController: ChatMessageController?
Expand Down Expand Up @@ -833,14 +833,12 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
}

deinit {
throttler.cancel()
messageCachingUtils.clearCache()
if messageController == nil {
utils.channelControllerFactory.clearCurrentController()
cleanupAudioPlayer()
ImageCache.shared.trim(toCost: utils.messageListConfig.cacheSizeOnChatDismiss)
if !channelDataSource.hasLoadedAllNextMessages {
channelDataSource.loadFirstPage { _ in }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,31 @@ class ChatChannelViewModel_Tests: StreamChatTestCase {
XCTAssertEqual(0, channelController.markReadCallCount)
}

func test_chatChannelVM_handleMessageAppear_doesNotCrashWhenDeallocated() {
let message = ChatMessage.mock()
let channelController = makeChannelController(messages: [message])
channelController.hasLoadedAllNextMessages_mock = nil
channelController.channel_mock = .mock(
cid: .unique,
unreadCount: ChannelUnreadCount(messages: 1, mentions: 0)
)

for _ in 0..<1000 {
autoreleasepool {
let viewModel = ChatChannelViewModel(channelController: channelController)
viewModel.handleMessageAppear(index: 0, scrollDirection: .down)
viewModel.handleMessageAppear(index: 0, scrollDirection: .down)
viewModel.handleMessageAppear(index: 0, scrollDirection: .down)
viewModel.handleMessageAppear(index: 0, scrollDirection: .down)
viewModel.handleMessageAppear(index: 0, scrollDirection: .down)
viewModel.handleMessageAppear(index: 0, scrollDirection: .down)
}
}

// Then - Should not crash
XCTAssert(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like no reason to add, if crashes, then the test will crash and fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I know that, but I think it makes it easier to read the test, it's just for the sake of it. But I can remove it if you want 👍

}

// MARK: - highlightMessage Tests

func test_highlightMessage_highlightsWhenSkipHighlightMessageIdIsNotSet() {
Expand Down
Loading