10000 Fix draft not deleted when attachments are removed from the composer … · GetStream/stream-chat-swift@8e47cd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e47cd2

Browse files
authored
Fix draft not deleted when attachments are removed from the composer (#3631)
* Fix draft not deleted when attachments are removed from the composer * Update CHANGELOG.md
1 parent 1f30ff4 commit 8e47cd2

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6-
### 🔄 Changed
6+
7+
### StreamChatUI
8+
### 🐞 Fixed
9+
- Fix draft not deleted when attachments are removed from the composer [#3631](https://github.com/GetStream/stream-chat-swift/pull/3631)
710

811
# [4.75.0](https://github.com/GetStream/stream-chat-swift/releases/tag/4.75.0)
912
_March 26, 2025_

Sources/StreamChatUI/Composer/ComposerVC.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ open class ComposerVC: _ViewController,
324324
public var content: Content = .initial() {
325325
didSet {
326326
updateContentIfNeeded()
327+
328+
/// If the input message was erased or the attachments have been removed, delete the draft message.
329+
if !oldValue.isEmpty && content.isEmpty {
330+
deleteDraftMessageIfNeeded()
331+
}
327332
}
328333
}
329334

@@ -553,6 +558,7 @@ open class ComposerVC: _ViewController,
553558

554559
override open func updateContent() {
555560
super.updateContent()
561+
556562
// Note: The order of the calls is important.
557563
updateText()
558564
updateKeystrokeEvents()
@@ -1544,11 +1550,6 @@ open class ComposerVC: _ViewController,
15441550
guard textView.text != content.text else { return }
15451551

15461552
content.text = textView.text
1547-
1548-
/// If the input message was erased and there is a draft message, the draft message should be deleted.
1549-
if content.isEmpty {
1550-
deleteDraftMessageIfNeeded()
1551-
}
15521553
}
15531554

15541555
open func textView(

Tests/StreamChatUITests/SnapshotTests/Composer/ComposerVC_Tests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,32 @@ final class ComposerVC_Tests: XCTestCase {
11461146
XCTAssertEqual(mock.updateDraftMessage_callCount, 1)
11471147
}
11481148

1149+
func test_content_whenAttachmentsCleared_whenHasDraft_deletesDraft() {
1150+
composerVC.content.text = ""
1151+
composerVC.content.attachments = [.mockFile]
1152+
1153+
let mock = ChatChannelController_Mock.mock()
1154+
mock.channel_mock = .mock(cid: .unique, draftMessage: .mock())
1155+
composerVC.channelController = mock
1156+
1157+
composerVC.content.attachments = []
1158+
1159+
XCTAssertEqual(mock.deleteDraftMessage_callCount, 1)
1160+
}
1161+
1162+
func test_content_whenAttachmentsCleared_whenHasText_doesNotCallDeleteDraft() {
1163+
composerVC.content.text = "Hey"
1164+
composerVC.content.attachments = [.mockFile]
1165+
1166+
let mock = ChatChannelController_Mock.mock()
1167+
mock.channel_mock = .mock(cid: .unique, draftMessage: .mock())
1168+
composerVC.channelController = mock
1169+
1170+
composerVC.content.attachments = []
1171+
1172+
XCTAssertEqual(mock.deleteDraftMessage_callCount, 0)
1173+
}
1174+
11491175
func test_textViewDidChange_whenInputIsEmpty_whenHasDraft_deletesDraft() {
11501176
composerVC.content.text = "Hey"
11511177
let mock = ChatChannelController_Mock.mock()

0 commit comments

Comments
 (0)
0