Skip to content

Commit 7fef385

Browse files
authored
Change message composer to use uploadFile capability when showing attachment picker icon (#646)
* Use uploadFile capability in the message composer * Update CHANGELOG.md * Fix snapshot tests
1 parent 4931ab5 commit 7fef385

10 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44
# Upcoming
55

66
### 🔄 Changed
7+
- Message composer now uses `.uploadFile` capability when showing attachment picker icon [#646](https://github.com/GetStream/stream-chat-swiftui/pull/646)
78

89
# [4.66.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.66.0)
910
_November 06, 2024_

Sources/StreamChatSwiftUI/ChatChannel/Composer/AttachmentPickerTypeView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public enum AttachmentPickerType {
2727

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

@@ -49,7 +50,7 @@ public struct AttachmentPickerTypeView: View {
4950
HStack(spacing: 16) {
5051
switch pickerTypeState {
5152
case let .expanded(attachmentPickerType):
52-
if channelConfig?.uploadsEnabled == true {
53+
if composerViewModel.channelController.channel?.canUploadFile == true {
5354
PickerTypeButton(
5455
pickerTypeState: $pickerTypeState,
5556
pickerType: .media,

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public struct MessageComposerView<Factory: ViewFactory>: View, KeyboardReadable
6868
state: $viewModel.pickerTypeState,
6969
channelConfig: channelConfig
7070
)
71+
.environmentObject(viewModel)
7172

7273
factory.makeComposerInputView(
7374
text: $viewModel.text,

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelTestHelpers.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class ChatChannelTestHelpers {
1515
lastActiveWatchers: [ChatUser] = []
1616
) -> ChatChannelController_Mock {
1717
let config = ChannelConfig(commands: [Command(name: "giphy", description: "", set: "", args: "")])
18-
let channel = chatChannel ?? ChatChannel.mockDMChannel(config: config, lastActiveWatchers: lastActiveWatchers)
18+
let channel = chatChannel ?? ChatChannel.mockDMChannel(
19+
config: config,
20+
ownCapabilities: [.uploadFile],
21+
lastActiveWatchers: lastActiveWatchers
22+
)
1923
let channelQuery = ChannelQuery(cid: channel.cid)
2024
let channelListQuery = ChannelListQuery(filter: .containMembers(userIds: [chatClient.currentUserId ?? .unique]))
2125
let channelController = ChatChannelController_Mock.mock(

StreamChatSwiftUITests/Tests/ChatChannel/MessageComposerView_Tests.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MessageComposerView_Tests: StreamChatTestCase {
2525
// Given
2626
let factory = DefaultViewFactory.shared
2727
let channelController = ChatChannelTestHelpers.makeChannelController(chatClient: chatClient)
28-
28+
2929
// When
3030
let view = MessageComposerView(
3131
viewFactory: factory,
@@ -194,6 +194,40 @@ class MessageComposerView_Tests: StreamChatTestCase {
194194
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
195195
}
196196

197+
func test_leadingComposerView_uploadFileCapability() {
198+
// Given
199+
let factory = DefaultViewFactory.shared
200+
let mockChannelController = ChatChannelTestHelpers.makeChannelController(chatClient: chatClient)
201+
mockChannelController.channel_mock = .mockDMChannel(ownCapabilities: [.uploadFile])
202+
let viewModel = MessageComposerViewModel(channelController: mockChannelController, messageController: nil)
203+
204+
// When
205+
let pickerTypeState: Binding<PickerTypeState> = .constant(.expanded(.none))
206+
let view = factory.makeLeadingComposerView(state: pickerTypeState, channelConfig: nil)
207+
.environmentObject(viewModel)
208+
.frame(width: 36, height: 36)
209+
210+
// Then
211+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
212+
}
213+
214+
func test_leadingComposerView_withoutUploadFileCapability() {
215+
// Given
216+
let factory = DefaultViewFactory.shared
217+
let mockChannelController = ChatChannelTestHelpers.makeChannelController(chatClient: chatClient)
218+
mockChannelController.channel_mock = .mockDMChannel(ownCapabilities: [])
219+
let viewModel = MessageComposerViewModel(channelController: mockChannelController, messageController: nil)
220+
221+
// When
222+
let pickerTypeState: Binding<PickerTypeState> = .constant(.expanded(.none))
223+
let view = factory.makeLeadingComposerView(state: pickerTypeState, channelConfig: nil)
224+
.environmentObject(viewModel)
225+
.frame(width: 36, height: 36)
226+
227+
// Then
228+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
229+
}
230+
197231
func test_composerInputView_inputTextView() {
198232
// Given
199233
let view = InputTextView(
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)