diff --git a/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift b/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift index 919566f6..071c260c 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift @@ -2,6 +2,7 @@ // Copyright © 2023 Stream.io Inc. All rights reserved. // +import StreamChat import SwiftUI /// Config for customizing the composer. @@ -13,6 +14,7 @@ public struct ComposerConfig { public var inputFont: UIFont public var adjustMessageOnSend: (String) -> (String) public var adjustMessageOnRead: (String) -> (String) + public var attachmentPayloadConverter: (ChatMessage) -> [AnyAttachmentPayload] public init( inputViewMinHeight: CGFloat = 38, @@ -20,7 +22,8 @@ public struct ComposerConfig { inputViewCornerRadius: CGFloat = 20, inputFont: UIFont = UIFont.preferredFont(forTextStyle: .body), adjustMessageOnSend: @escaping (String) -> (String) = { $0 }, - adjustMessageOnRead: @escaping (String) -> (String) = { $0 } + adjustMessageOnRead: @escaping (String) -> (String) = { $0 }, + attachmentPayloadConverter: @escaping (ChatMessage) -> [AnyAttachmentPayload] = ComposerConfig.defaultAttachmentPayloadConverter ) { self.inputViewMinHeight = inputViewMinHeight self.inputViewMaxHeight = inputViewMaxHeight @@ -28,5 +31,10 @@ public struct ComposerConfig { self.inputFont = inputFont self.adjustMessageOnSend = adjustMessageOnSend self.adjustMessageOnRead = adjustMessageOnRead + self.attachmentPayloadConverter = attachmentPayloadConverter + } + + public static var defaultAttachmentPayloadConverter: (ChatMessage) -> [AnyAttachmentPayload] = { message in + message.allAttachments.toAnyAttachmentPayload() } } diff --git a/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift index 2fea0a4c..cd722fe0 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift @@ -471,7 +471,7 @@ open class MessageComposerViewModel: ObservableObject { messageController.editMessage( text: adjustedText, - attachments: message.allAttachments.toAnyAttachmentPayload() + attachments: utils.composerConfig.attachmentPayloadConverter(message) ) { [weak self] error in if error != nil { self?.errorShown = true