diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e0f3a3c9ab..0bd8e60f63f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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_ diff --git a/Sources/StreamChatUI/Composer/ComposerVC.swift b/Sources/StreamChatUI/Composer/ComposerVC.swift index f2ae1aab918..7037e3ddff3 100644 --- a/Sources/StreamChatUI/Composer/ComposerVC.swift +++ b/Sources/StreamChatUI/Composer/ComposerVC.swift @@ -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 @@ -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 @@ -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 diff --git a/Tests/StreamChatUITests/SnapshotTests/Composer/ComposerVC_Tests.swift b/Tests/StreamChatUITests/SnapshotTests/Composer/ComposerVC_Tests.swift index d4990783b2d..1642f225cc3 100644 --- a/Tests/StreamChatUITests/SnapshotTests/Composer/ComposerVC_Tests.swift +++ b/Tests/StreamChatUITests/SnapshotTests/Composer/ComposerVC_Tests.swift @@ -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() @@ -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 diff --git a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/VoiceRecordingVC_Tests.swift b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/VoiceRecordingVC_Tests.swift index f37007a52f0..deefd130da4 100644 --- a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/VoiceRecordingVC_Tests.swift +++ b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/VoiceRecordingVC_Tests.swift @@ -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() diff --git a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-dark.png b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-dark.png index fb8cf16a11e..0add6252eef 100644 Binary files a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-dark.png and b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-dark.png differ diff --git a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-light.png b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-light.png index 64542542f95..aaa9b5d8db9 100644 Binary files a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-light.png and b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_idle_viewIsConfiguredAsExpected.default-light.png differ diff --git a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-dark.png b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-dark.png index 53f42bff173..862769604cf 100644 Binary files a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-dark.png and b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-dark.png differ diff --git a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-light.png b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-light.png index f33b589cae2..d80bd8491c5 100644 Binary files a/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-light.png and b/Tests/StreamChatUITests/SnapshotTests/VoiceRecording/__Snapshots__/VoiceRecordingVC_Tests/test_updateContent_showingTip_viewIsConfiguredAsExpected.default-light.png differ