Skip to content

Commit

Permalink
Use uploadFile capability in the message composer
Browse files Browse the repository at this point in the history
  • Loading branch information
nuno-vieira committed Nov 8, 2024
1 parent 4931ab5 commit c0548bc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum AttachmentPickerType {

/// View for picking the attachment type (media or giphy commands).
public struct AttachmentPickerTypeView: View {
@EnvironmentObject private var composerViewModel: MessageComposerViewModel
@Injected(\.images) private var images
@Injected(\.colors) private var colors

Expand All @@ -49,7 +50,7 @@ public struct AttachmentPickerTypeView: View {
HStack(spacing: 16) {
switch pickerTypeState {
case let .expanded(attachmentPickerType):
if channelConfig?.uploadsEnabled == true {
if composerViewModel.channelController.channel?.canUploadFile == true {
PickerTypeButton(
pickerTypeState: $pickerTypeState,
pickerType: .media,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
state: $viewModel.pickerTypeState,
channelConfig: channelConfig
)
.environmentObject(viewModel)

factory.makeComposerInputView(
text: $viewModel.text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MessageComposerView_Tests: StreamChatTestCase {
// Given
let factory = DefaultViewFactory.shared
let channelController = ChatChannelTestHelpers.makeChannelController(chatClient: chatClient)

// When
let view = MessageComposerView(
viewFactory: factory,
Expand Down Expand Up @@ -194,6 +194,40 @@ class MessageComposerView_Tests: StreamChatTestCase {
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_leadingComposerView_uploadFileCapability() {
// Given
let factory = DefaultViewFactory.shared
let mockChannelController = ChatChannelTestHelpers.makeChannelController(chatClient: chatClient)
mockChannelController.channel_mock = .mockDMChannel(ownCapabilities: [.uploadFile])
let viewModel = MessageComposerViewModel(channelController: mockChannelController, messageController: nil)

// When
let pickerTypeState: Binding<PickerTypeState> = .constant(.expanded(.none))
let view = factory.makeLeadingComposerView(state: pickerTypeState, channelConfig: nil)
.environmentObject(viewModel)
.frame(width: 36, height: 36)

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_leadingComposerView_withoutUploadFileCapability() {
// Given
let factory = DefaultViewFactory.shared
let mockChannelController = ChatChannelTestHelpers.makeChannelController(chatClient: chatClient)
mockChannelController.channel_mock = .mockDMChannel(ownCapabilities: [])
let viewModel = MessageComposerViewModel(channelController: mockChannelController, messageController: nil)

// When
let pickerTypeState: Binding<PickerTypeState> = .constant(.expanded(.none))
let view = factory.makeLeadingComposerView(state: pickerTypeState, channelConfig: nil)
.environmentObject(viewModel)
.frame(width: 36, height: 36)

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_composerInputView_inputTextView() {
// Given
let view = InputTextView(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c0548bc

Please sign in to comment.