Skip to content

Commit

Permalink
Typing users did not update reliably in the message list because view…
Browse files Browse the repository at this point in the history
… model did not propagate channel changes to the view
  • Loading branch information
laevandus committed Aug 29, 2024
1 parent e5c85bd commit 274d686
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### 🔄 Changed

### 🐞 Fixed
- Typing users did not update reliably in the message list [#591](https://github.com/GetStream/stream-chat-swiftui/pull/591)

# [4.62.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.62.0)
_August 16, 2024_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
}
}

public var channel: ChatChannel? {
channelController.channel
}
@Published public private(set) var channel: ChatChannel?

public var isMessageThread: Bool {
messageController != nil
Expand Down Expand Up @@ -150,6 +148,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
}
channelDataSource.delegate = self
messages = channelDataSource.messages
channel = channelController.channel

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
if let scrollToMessage, let parentMessageId = scrollToMessage.parentMessageId, messageController == nil {
Expand Down Expand Up @@ -445,6 +444,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
didUpdateChannel channel: EntityChange<ChatChannel>,
channelController: ChatChannelController
) {
self.channel = channel.item
checkReadIndicators(for: channel)
checkTypingIndicator()
checkHeaderType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@ import SwiftUI
import XCTest

class ChatChannelViewModel_Tests: StreamChatTestCase {

func test_chatChannelVM_channelIsUpdated() {
// Given
let cid = ChannelId.unique
let initialChannel = ChatChannel.mock(cid: cid)
let channelController = makeChannelController()
channelController.channel_mock = initialChannel
let viewModel = ChatChannelViewModel(channelController: channelController)
XCTAssertEqual(initialChannel, viewModel.channel)

// When
let updatedChannel = ChatChannel.mock(cid: cid)
channelController.channel_mock = updatedChannel
channelController.delegate?.channelController(
channelController,
didUpdateChannel: .update(updatedChannel)
)

// Then
XCTAssertEqual(updatedChannel, viewModel.channel)
}

func test_chatChannelVM_messagesLoaded() {
// Given
let channelController = makeChannelController()
Expand Down

0 comments on commit 274d686

Please sign in to comment.