diff --git a/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift b/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift index 0eb5a7b2..0c4e995f 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift @@ -13,6 +13,7 @@ public struct ComposerConfig { public var inputViewCornerRadius: CGFloat public var inputFont: UIFont public var gallerySupportedTypes: GallerySupportedTypes + public var maxGalleryAssetsCount: Int? public var inputPaddingsConfig: PaddingsConfig public var adjustMessageOnSend: (String) -> (String) public var adjustMessageOnRead: (String) -> (String) @@ -33,6 +34,7 @@ public struct ComposerConfig { inputViewCornerRadius: CGFloat = 20, inputFont: UIFont = UIFont.preferredFont(forTextStyle: .body), gallerySupportedTypes: GallerySupportedTypes = .imagesAndVideo, + maxGalleryAssetsCount: Int? = nil, inputPaddingsConfig: PaddingsConfig = .composerInput, adjustMessageOnSend: @escaping (String) -> (String) = { $0 }, adjustMessageOnRead: @escaping (String) -> (String) = { $0 }, @@ -47,6 +49,7 @@ public struct ComposerConfig { self.adjustMessageOnRead = adjustMessageOnRead self.attachmentPayloadConverter = attachmentPayloadConverter self.gallerySupportedTypes = gallerySupportedTypes + self.maxGalleryAssetsCount = maxGalleryAssetsCount self.inputPaddingsConfig = inputPaddingsConfig self.isVoiceRecordingEnabled = isVoiceRecordingEnabled } diff --git a/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift index 545b5a57..6768d384 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift @@ -689,6 +689,9 @@ open class MessageComposerViewModel: ObservableObject { fetchOptions.predicate = predicate } fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] + if let maxGalleryAssetsCount = utils.composerConfig.maxGalleryAssetsCount { + fetchOptions.fetchLimit = maxGalleryAssetsCount + } let assets = PHAsset.fetchAssets(with: fetchOptions) DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in self?.imageAssets = assets