Skip to content

Commit a52ff7b

Browse files
Fix race condition when clearing text (#966)
1 parent 114141b commit a52ff7b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
- Fix replacing an image while editing a message not showing the new image in the message list [#956](https://github.com/GetStream/stream-chat-swiftui/pull/956)
1414
- Improve precision when scrolling to the newest message with long text [#958](https://github.com/GetStream/stream-chat-swiftui/pull/958)
1515
- Fix draft attachments being sent with local file urls to the server [#964](https://github.com/GetStream/stream-chat-swiftui/pull/964)
16+
- Fix race condition when clearing text in a regular TextField [#955](https://github.com/GetStream/stream-chat-swiftui/pull/955)
1617
### 🔄 Changed
1718
- Change the gallery header view to show the message timestamp instead of online status [#962](https://github.com/GetStream/stream-chat-swiftui/pull/962)
1819

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ open class MessageComposerViewModel: ObservableObject {
743743
}
744744

745745
private func clearInputData() {
746-
text = ""
747746
addedAssets = []
748747
addedFileURLs = []
749748
addedVoiceRecordings = []

StreamChatSwiftUITests/Tests/ChatChannel/MessageComposerViewModel_Tests.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,12 @@ class MessageComposerViewModel_Tests: StreamChatTestCase {
996996
viewModel.sendMessage(quotedMessage: nil, editedMessage: nil) {}
997997

998998
// Then
999-
// Sending a message will clear the input, deleting the draft message.
1000-
XCTAssertEqual(channelController.deleteDraftMessage_callCount, 1)
999+
let expectation = XCTestExpectation(description: "Text cleared")
1000+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
1001+
XCTAssertEqual(channelController.deleteDraftMessage_callCount, 1)
1002+
expectation.fulfill()
1003+
}
1004+
wait(for: [expectation], timeout: 1.0)
10011005
}
10021006

10031007
func test_messageComposerVM_whenMessagePublished_deleteDraftReply() {
@@ -1020,7 +1024,12 @@ class MessageComposerViewModel_Tests: StreamChatTestCase {
10201024
viewModel.sendMessage(quotedMessage: nil, editedMessage: nil) {}
10211025

10221026
// Then
1023-
XCTAssertEqual(messageController.deleteDraftReply_callCount, 1)
1027+
let expectation = XCTestExpectation(description: "Text cleared")
1028+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
1029+
XCTAssertEqual(messageController.deleteDraftReply_callCount, 1)
1030+
expectation.fulfill()
1031+
}
1032+
wait(for: [expectation], timeout: 1.0)
10241033
}
10251034

10261035
func test_messageComposerVM_draftMessageUpdatedEvent() throws {

0 commit comments

Comments
 (0)