Skip to content

Commit 15a3f5d

Browse files
authored
Fix quoted message shown in the composer when editing a quoting message (#943)
* Fix editing a quoting message displays quoted banner in composer * Update CHANGELOG.md
1 parent 44b22f5 commit 15a3f5d

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
- Add `ColorPalette.navigationBarTitle`, `ColorPalette.navigationBarSubtitle`, `ColorPalette.navigationBarTintColor`, `ColorPalette.navigationBarBackground` [#939](https://github.com/GetStream/stream-chat-swiftui/pull/939)
88
### 🐞 Fixed
99
- Long message with a link preview was truncated sometimes [#940](https://github.com/GetStream/stream-chat-swiftui/pull/940)
10+
- Fix quoted message shown in the composer when editing a quoting message [#943](https://github.com/GetStream/stream-chat-swiftui/pull/943)
1011

1112
# [4.87.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.87.0)
1213
_September 01, 2025_

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,13 @@ open class MessageComposerViewModel: ObservableObject {
281281
return
282282
}
283283

284-
fillComposer(with: message)
284+
text = message.text
285+
mentionedUsers = message.mentionedUsers
286+
showReplyInChannel = message.showReplyInChannel
287+
selectedRangeLocation = message.text.count
288+
attachmentsConverter.attachmentsToAssets(message.allAttachments) { [weak self] assets in
289+
self?.updateComposerAssets(assets)
290+
}
285291
}
286292

287293
/// Populates the draft message in the composer with the current controller's draft information.
@@ -290,7 +296,15 @@ open class MessageComposerViewModel: ObservableObject {
290296
return
291297
}
292298

293-
fillComposer(with: ChatMessage(draft))
299+
let message = ChatMessage(draft)
300+
text = message.text
301+
mentionedUsers = message.mentionedUsers
302+
quotedMessage?.wrappedValue = message.quotedMessage
303+
showReplyInChannel = message.showReplyInChannel
304+
selectedRangeLocation = message.text.count
305+
attachmentsConverter.attachmentsToAssets(message.allAttachments) { [weak self] assets in
306+
self?.updateComposerAssets(assets)
307+
}
294308
}
295309

296310
/// Updates the draft message locally and on the server.
@@ -642,18 +656,6 @@ open class MessageComposerViewModel: ObservableObject {
642656

643657
// MARK: - private
644658

645-
private func fillComposer(with message: ChatMessage) {
646-
text = message.text
647-
mentionedUsers = message.mentionedUsers
648-
quotedMessage?.wrappedValue = message.quotedMessage
649-
showReplyInChannel = message.showReplyInChannel
650-
selectedRangeLocation = message.text.count
651-
652-
attachmentsConverter.attachmentsToAssets(message.allAttachments) { [weak self] assets in
653-
self?.updateComposerAssets(assets)
654-
}
655-
}
656-
657659
private func updateComposerAssets(_ assets: ComposerAssets) {
658660
addedAssets = assets.mediaAssets
659661
addedFileURLs = assets.fileAssets.map(\.url)

StreamChatSwiftUITests/Tests/ChatChannel/MessageComposerView_Tests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,22 @@ class MessageComposerView_Tests: StreamChatTestCase {
647647
AssertSnapshot(view, variants: [.defaultLight], size: size)
648648
}
649649

650+
func test_composerView_editingMessageWithQuotedMessage() {
651+
let size = CGSize(width: defaultScreenSize.width, height: 100)
652+
let mockEditedMessage = ChatMessage.mock(
653+
id: .unique,
654+
cid: .unique,
655+
text: "This is a message being edited",
656+
author: .mock(id: .unique),
657+
quotedMessage: .mock(text: "Should not appear")
658+
)
659+
660+
let view = makeComposerViewWithEditedMessage(mockEditedMessage)
661+
.frame(width: size.width, height: size.height)
662+
663+
AssertSnapshot(view, variants: [.defaultLight], size: size)
664+
}
665+
650666
func test_composerView_editingMessageWithImageAttachment() throws {
651667
let size = CGSize(width: defaultScreenSize.width, height: 200)
652668
let mockEditedMessage = ChatMessage.mock(
8.07 KB
Loading

0 commit comments

Comments
 (0)