Skip to content

Commit

Permalink
Allow the uploads capability to manage the recordButton's appearance (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis authored Aug 31, 2023
1 parent 0ad815f commit 26f2138
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

## StreamChatUI
### 🔄 Changed
- Make record button in composer, visible depending on the channel's capabilities. [#2758](https://github.com/GetStream/stream-chat-swift/pull/2758)

# [4.36.0](https://github.com/GetStream/stream-chat-swift/releases/tag/4.36.0)
_August 28, 2023_
Expand Down
6 changes: 3 additions & 3 deletions Sources/StreamChatUI/Composer/ComposerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ open class ComposerVC: _ViewController,
Animate {
self.composerView.confirmButton.isHidden = true
self.composerView.sendButton.isHidden = self.content.isSlowModeOn
self.composerView.recordButton.isHidden = self.composerView.sendButton.isHidden || !self.components.isVoiceRecordingEnabled
self.composerView.recordButton.isHidden = self.composerView.sendButton.isHidden || !self.components.isVoiceRecordingEnabled || !self.isAttachmentsEnabled
self.composerView.headerView.isHidden = true
self.composerView.cooldownView.isHidden = !self.content.isSlowModeOn
self.composerView.leadingContainer.isHidden = false
Expand All @@ -493,7 +493,7 @@ open class ComposerVC: _ViewController,
Animate {
self.composerView.confirmButton.isHidden = true
self.composerView.sendButton.isHidden = self.content.isSlowModeOn
self.composerView.recordButton.isHidden = self.composerView.sendButton.isHidden || !self.components.isVoiceRecordingEnabled
self.composerView.recordButton.isHidden = self.composerView.sendButton.isHidden || !self.components.isVoiceRecordingEnabled || !self.isAttachmentsEnabled
self.composerView.headerView.isHidden = false
self.composerView.cooldownView.isHidden = !self.content.isSlowModeOn
self.composerView.leadingContainer.isHidden = false
Expand All @@ -504,7 +504,7 @@ open class ComposerVC: _ViewController,
Animate {
self.composerView.confirmButton.isHidden = false
self.composerView.sendButton.isHidden = true
self.composerView.recordButton.isHidden = self.composerView.confirmButton.isHidden
self.composerView.recordButton.isHidden = self.composerView.confirmButton.isHidden || !self.isAttachmentsEnabled
self.composerView.headerView.isHidden = false
self.composerView.cooldownView.isHidden = true
self.composerView.leadingContainer.isHidden = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,22 @@ final class ComposerVC_Tests: XCTestCase {
XCTAssertEqual(composerVC.composerView.attachmentButton.isHidden, false)
}

func test_canUploadFiles_hasRecordButtonShown() {
composerVC.appearance = Appearance.default
composerVC.content = .initial()

var components = Components.default
components.isVoiceRecordingEnabled = true
composerVC.components = components

let mock = ChatChannelController_Mock.mock()
mock.channel_mock = .mock(cid: .unique, ownCapabilities: [.uploadFile, .sendMessage])
composerVC.channelController = mock
composerVC.updateContent()

XCTAssertEqual(composerVC.composerView.recordButton.isHidden, false)
}

func test_canNotUploadFiles_hasAttachmentButtonHidden() {
composerVC.appearance = Appearance.default
composerVC.content = .initial()
Expand All @@ -348,6 +364,18 @@ final class ComposerVC_Tests: XCTestCase {
XCTAssertEqual(composerVC.composerView.attachmentButton.isHidden, true)
}

func test_canNotUploadFiles_hasRecordButtonHidden() {
composerVC.appearance = Appearance.default
composerVC.content = .initial()

let mock = ChatChannelController_Mock.mock()
mock.channel_mock = .mock(cid: .unique, ownCapabilities: [.sendMessage])
composerVC.channelController = mock
composerVC.updateContent()

XCTAssertEqual(composerVC.composerView.recordButton.isHidden, true)
}

func test_isAttachmentsEnabled_whenChannelIsEmpty_thenReturnsTrue() {
let mock = ChatChannelController_Mock.mock()
mock.channel_mock = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ final class VoiceRecordingVC_Tests: XCTestCase {
client: .mock,
isChannelAlreadyCreated: true
)
mock.channel_mock = .mock(cid: .unique, config: .mock(commands: []), ownCapabilities: [.sendMessage])
mock.channel_mock = .mock(cid: .unique, config: .mock(commands: []), ownCapabilities: [.sendMessage, .uploadFile])
viewController.channelController = mock
viewController.messageComposerVC.channelController = mock
viewController.setUp()
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.
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 26f2138

Please sign in to comment.