Skip to content

Commit 2dde7a4

Browse files
committed
Added back the fillComposer function again
1 parent 61e30b6 commit 2dde7a4

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -274,37 +274,23 @@ open class MessageComposerViewModel: ObservableObject {
274274
)
275275
}
276276

277+
/// Populates the composer with the edited message.
277278
public func fillEditedMessage(_ editedMessage: ChatMessage?) {
278279
guard let message = editedMessage else {
279280
clearInputData()
280281
return
281282
}
282283

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

294287
/// Populates the draft message in the composer with the current controller's draft information.
295288
public func fillDraftMessage() {
296-
guard let message = draftMessage else {
289+
guard let draft = draftMessage else {
297290
return
298291
}
299292

300-
text = message.text
301-
mentionedUsers = message.mentionedUsers
302-
quotedMessage?.wrappedValue = message.quotedMessage
303-
showReplyInChannel = message.showReplyInChannel
304-
selectedRangeLocation = message.text.count
305-
306-
let composerAssets = attachmentsConverter.attachmentsToAssets(message.attachments)
307-
updateComposerAssets(composerAssets)
293+
fillComposer(with: ChatMessage(draft))
308294
}
309295

310296
/// Updates the draft message locally and on the server.
@@ -649,6 +635,18 @@ open class MessageComposerViewModel: ObservableObject {
649635

650636
// MARK: - private
651637

638+
private func fillComposer(with message: ChatMessage) {
639+
text = message.text
640+
mentionedUsers = message.mentionedUsers
641+
quotedMessage?.wrappedValue = message.quotedMessage
642+
showReplyInChannel = message.showReplyInChannel
643+
selectedRangeLocation = message.text.count
644+
645+
attachmentsConverter.attachmentsToAssets(message.allAttachments) { [weak self] assets in
646+
self?.updateComposerAssets(assets)
647+
}
648+
}
649+
652650
private func updateComposerAssets(_ assets: ComposerAssets) {
653651
addedAssets = assets.mediaAssets
654652
addedFileURLs = assets.fileAssets.map(\.url)

0 commit comments

Comments
 (0)