File tree Expand file tree Collapse file tree 3 files changed +36
-6
lines changed
Sources/StreamChatUI/Composer
Tests/StreamChatUITests/SnapshotTests/Composer Expand file tree Collapse file tree 3 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
3
3
4
4
# Upcoming
5
5
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 )
7
10
8
11
# [ 4.75.0] ( https://github.com/GetStream/stream-chat-swift/releases/tag/4.75.0 )
9
12
_ March 26, 2025_
Original file line number Diff line number Diff line change @@ -324,6 +324,11 @@ open class ComposerVC: _ViewController,
324
324
public var content : Content = . initial( ) {
325
325
didSet {
326
326
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
+ }
327
332
}
328
333
}
329
334
@@ -553,6 +558,7 @@ open class ComposerVC: _ViewController,
553
558
554
559
override open func updateContent( ) {
555
560
super. updateContent ( )
561
+
556
562
// Note: The order of the calls is important.
557
563
updateText ( )
558
564
updateKeystrokeEvents ( )
@@ -1544,11 +1550,6 @@ open class ComposerVC: _ViewController,
1544
1550
guard textView. text != content. text else { return }
1545
1551
1546
1552
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
- }
1552
1553
}
1553
1554
1554
1555
open func textView(
Original file line number Diff line number Diff line change @@ -1146,6 +1146,32 @@ final class ComposerVC_Tests: XCTestCase {
1146
1146
XCTAssertEqual ( mock. updateDraftMessage_callCount, 1 )
1147
1147
}
1148
1148
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
+
1149
1175
func test_textViewDidChange_whenInputIsEmpty_whenHasDraft_deletesDraft( ) {
1150
1176
composerVC. content. text = " Hey "
1151
1177
let mock = ChatChannelController_Mock . mock ( )
You can’t perform that action at this time.
0 commit comments