Skip to content

Commit

Permalink
Use AppSettings.fileUploadConfig for setting supported UTI types for …
Browse files Browse the repository at this point in the history
…the file picker (#713)
  • Loading branch information
laevandus authored Jan 14, 2025
1 parent b016961 commit 67ab9f3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
# Upcoming

### ✅ Added
- Use `AppSettings.fileUploadConfig` for setting supported UTI types for the file picker [#713](https://github.com/GetStream/stream-chat-swiftui/pull/713)
- Colors and images for voice recording view [#704](https://github.com/GetStream/stream-chat-swiftui/pull/704)
- `ColorPalette.voiceMessageControlBackground`
- `Images.pauseFilled`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
//

import SwiftUI
import UniformTypeIdentifiers

/// SwiftUI wrapper for picking files from the device.
public struct FilePickerView: UIViewControllerRepresentable {
@Injected(\.chatClient) var client
@Binding var fileURLs: [URL]

public func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(forOpeningContentTypes: [.item])
let picker = UIDocumentPickerViewController(forOpeningContentTypes: openingContentTypes)
picker.delegate = context.coordinator
picker.allowsMultipleSelection = true
return picker
}

var openingContentTypes: [UTType] {
guard let settings = client.appSettings else { return [.item] }
let allowedUTITypes = settings.fileUploadConfig.allowedUTITypes.compactMap { UTType($0) }
return allowedUTITypes.isEmpty ? [.item] : allowedUTITypes
}

public func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {
// We don't need handling updates of the VC at the moment.
Expand Down
4 changes: 4 additions & 0 deletions StreamChatSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
4F7DD9A02BFC7C6100599AA6 /* ChatClient+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F7DD99F2BFC7C6100599AA6 /* ChatClient+Extensions.swift */; };
4F7DD9A22BFCB2EF00599AA6 /* ChatClientExtensions_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F7DD9A12BFCB2EF00599AA6 /* ChatClientExtensions_Tests.swift */; };
4FD3592A2C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */; };
4FD964622D353D88001B6838 /* FilePickerView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */; };
4FEAB3182BFF71F70057E511 /* SwiftUI+UIAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEAB3172BFF71F70057E511 /* SwiftUI+UIAlertController.swift */; };
8205B4142AD41CC700265B84 /* StreamSwiftTestHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = 8205B4132AD41CC700265B84 /* StreamSwiftTestHelpers */; };
8205B4182AD4267200265B84 /* StreamSwiftTestHelpers in Frameworks */ = {isa = PBXBuildFile; productRef = 8205B4172AD4267200265B84 /* StreamSwiftTestHelpers */; };
Expand Down Expand Up @@ -608,6 +609,7 @@
4F7DD99F2BFC7C6100599AA6 /* ChatClient+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChatClient+Extensions.swift"; sourceTree = "<group>"; };
4F7DD9A12BFCB2EF00599AA6 /* ChatClientExtensions_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatClientExtensions_Tests.swift; sourceTree = "<group>"; };
4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollViewModel_Tests.swift; sourceTree = "<group>"; };
4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilePickerView_Tests.swift; sourceTree = "<group>"; };
4FEAB3172BFF71F70057E511 /* SwiftUI+UIAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUI+UIAlertController.swift"; sourceTree = "<group>"; };
820A619F29D6D78E002257FB /* QuotedReply_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuotedReply_Tests.swift; sourceTree = "<group>"; };
825AADF3283CCDB000237498 /* ThreadPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadPage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2116,6 +2118,7 @@
84C94D5027591DE2007FE2B9 /* ChatMessageIDs_Tests.swift */,
84204BFD2C052BD600AE522B /* CreatePollView_Tests.swift */,
4FD359292C05EA8F00B1D63B /* CreatePollViewModel_Tests.swift */,
4FD964612D353D82001B6838 /* FilePickerView_Tests.swift */,
84AB7B20277203EF00631A10 /* GalleryView_Tests.swift */,
8469592E29BB235400134EA0 /* LazyImageExtensions_Tests.swift */,
840008BA27E8D64A00282D88 /* MessageActions_Tests.swift */,
Expand Down Expand Up @@ -2992,6 +2995,7 @@
84DEC8DF2760A1D100172876 /* MessageView_Tests.swift in Sources */,
847F7949282A91AD0009F74C /* ChatChannelView_Tests.swift in Sources */,
84CC3734290B0C2900689B73 /* ChatMessageControllerSUI_Mock.swift in Sources */,
4FD964622D353D88001B6838 /* FilePickerView_Tests.swift in Sources */,
91B763A6283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift in Sources */,
846608E9278C98CB00D3D7B3 /* TypingIndicatorView_Tests.swift in Sources */,
8421BCEC27A400E8000F977D /* ReactionsUsersView_Tests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright © 2025 Stream.io Inc. All rights reserved.
//

@testable import StreamChat
@testable import StreamChatSwiftUI
@testable import StreamChatTestTools
import UniformTypeIdentifiers
import XCTest

final class FilePickerView_Tests: StreamChatTestCase {
func test_openingContentTypes_default() {
let picker = FilePickerView(fileURLs: .constant([]))
XCTAssertEqual(picker.openingContentTypes, [UTType.item])
}

func test_openingContentTypes_allowedLists() {
chatClient.mockedAppSettings = .mock(fileUploadConfig: .mock(allowedFileExtensions: [".pdf"]))
XCTAssertEqual(FilePickerView(fileURLs: .constant([])).openingContentTypes, [UTType.pdf])

chatClient.mockedAppSettings = .mock(fileUploadConfig: .mock(allowedMimeTypes: ["audio/mp3"]))
XCTAssertEqual(FilePickerView(fileURLs: .constant([])).openingContentTypes, [UTType.mp3])
}
}

0 comments on commit 67ab9f3

Please sign in to comment.