Skip to content

Commit cb6965d

Browse files
Support for editing custom attachments
1 parent 621e0a2 commit cb6965d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright © 2023 Stream.io Inc. All rights reserved.
33
//
44

5+
import StreamChat
56
import SwiftUI
67

78
/// Config for customizing the composer.
@@ -13,20 +14,27 @@ public struct ComposerConfig {
1314
public var inputFont: UIFont
1415
public var adjustMessageOnSend: (String) -> (String)
1516
public var adjustMessageOnRead: (String) -> (String)
17+
public var attachmentPayloadConverter: (ChatMessage) -> [AnyAttachmentPayload]
1618

1719
public init(
1820
inputViewMinHeight: CGFloat = 38,
1921
inputViewMaxHeight: CGFloat = 76,
2022
inputViewCornerRadius: CGFloat = 20,
2123
inputFont: UIFont = UIFont.preferredFont(forTextStyle: .body),
2224
adjustMessageOnSend: @escaping (String) -> (String) = { $0 },
23-
adjustMessageOnRead: @escaping (String) -> (String) = { $0 }
25+
adjustMessageOnRead: @escaping (String) -> (String) = { $0 },
26+
attachmentPayloadConverter: @escaping (ChatMessage) -> [AnyAttachmentPayload] = ComposerConfig.defaultAttachmentPayloadConverter
2427
) {
2528
self.inputViewMinHeight = inputViewMinHeight
2629
self.inputViewMaxHeight = inputViewMaxHeight
2730
self.inputViewCornerRadius = inputViewCornerRadius
2831
self.inputFont = inputFont
2932
self.adjustMessageOnSend = adjustMessageOnSend
3033
self.adjustMessageOnRead = adjustMessageOnRead
34+
self.attachmentPayloadConverter = attachmentPayloadConverter
35+
}
36+
37+
public static var defaultAttachmentPayloadConverter: (ChatMessage) -> [AnyAttachmentPayload] = { message in
38+
message.allAttachments.toAnyAttachmentPayload()
3139
}
3240
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ open class MessageComposerViewModel: ObservableObject {
471471

472472
messageController.editMessage(
473473
text: adjustedText,
474-
attachments: message.allAttachments.toAnyAttachmentPayload()
474+
attachments: utils.composerConfig.attachmentPayloadConverter(message)
475475
) { [weak self] error in
476476
if error != nil {
477477
self?.errorShown = true

0 commit comments

Comments
 (0)