Skip to content

Commit

Permalink
Support for editing custom attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski committed Aug 1, 2023
1 parent 621e0a2 commit cb6965d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

import StreamChat
import SwiftUI

/// Config for customizing the composer.
Expand All @@ -13,20 +14,27 @@ 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,
inputViewMaxHeight: CGFloat = 76,
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
self.inputViewCornerRadius = inputViewCornerRadius
self.inputFont = inputFont
self.adjustMessageOnSend = adjustMessageOnSend
self.adjustMessageOnRead = adjustMessageOnRead
self.attachmentPayloadConverter = attachmentPayloadConverter
}

public static var defaultAttachmentPayloadConverter: (ChatMessage) -> [AnyAttachmentPayload] = { message in
message.allAttachments.toAnyAttachmentPayload()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cb6965d

Please sign in to comment.