Skip to content

Commit 5dc5309

Browse files
committed
Add the maxGalleryAssetsCount to the composer config to limit the maximum number of assets to be fetched from the gallery.
1 parent 9eae155 commit 5dc5309

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/ComposerConfig.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public struct ComposerConfig {
1313
public var inputViewCornerRadius: CGFloat
1414
public var inputFont: UIFont
1515
public var gallerySupportedTypes: GallerySupportedTypes
16+
public var maxGalleryAssetsCount: Int?
1617
public var inputPaddingsConfig: PaddingsConfig
1718
public var adjustMessageOnSend: (String) -> (String)
1819
public var adjustMessageOnRead: (String) -> (String)
@@ -33,6 +34,7 @@ public struct ComposerConfig {
3334
inputViewCornerRadius: CGFloat = 20,
3435
inputFont: UIFont = UIFont.preferredFont(forTextStyle: .body),
3536
gallerySupportedTypes: GallerySupportedTypes = .imagesAndVideo,
37+
maxGalleryAssetsCount: Int? = nil,
3638
inputPaddingsConfig: PaddingsConfig = .composerInput,
3739
adjustMessageOnSend: @escaping (String) -> (String) = { $0 },
3840
adjustMessageOnRead: @escaping (String) -> (String) = { $0 },
@@ -47,6 +49,7 @@ public struct ComposerConfig {
4749
self.adjustMessageOnRead = adjustMessageOnRead
4850
self.attachmentPayloadConverter = attachmentPayloadConverter
4951
self.gallerySupportedTypes = gallerySupportedTypes
52+
self.maxGalleryAssetsCount = maxGalleryAssetsCount
5053
self.inputPaddingsConfig = inputPaddingsConfig
5154
self.isVoiceRecordingEnabled = isVoiceRecordingEnabled
5255
}

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ open class MessageComposerViewModel: ObservableObject {
689689
fetchOptions.predicate = predicate
690690
}
691691
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
692+
if let maxGalleryAssetsCount = utils.composerConfig.maxGalleryAssetsCount {
693+
fetchOptions.fetchLimit = maxGalleryAssetsCount
694+
}
692695
let assets = PHAsset.fetchAssets(with: fetchOptions)
693696
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
694697
self?.imageAssets = assets

0 commit comments

Comments
 (0)