Skip to content

Commit 1196ec3

Browse files
authored
Fix mute and umute commands shown in the composer when removed from Dashboard (#872)
* Fix mute and umute commands being added to the composer even if Dashboard does not include them * Update CHANGELOG.md
1 parent b073808 commit 1196ec3

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
- Fix tapping on invisible areas on iOS 26 [#868](https://github.com/GetStream/stream-chat-swiftui/pull/868)
1111
- Fix channel view tab bar not hidden on iOS 16.0 [#870](https://github.com/GetStream/stream-chat-swiftui/pull/870)
1212
- Fix message Actions overlay view not dismissed when opening thread [#873](https://github.com/GetStream/stream-chat-swiftui/pull/873)
13+
- Fix mute and unmute commands shown in the composer when removed from Dashboard [#872](https://github.com/GetStream/stream-chat-swiftui/pull/872)
14+
15+
### 🔄 Changed
16+
- Mute and unmute commands are not added by default in the composer [#872](https://github.com/GetStream/stream-chat-swiftui/pull/872)
1317

1418
# [4.80.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.80.0)
1519
_June 17, 2025_

Sources/StreamChatSwiftUI/ChatChannel/Composer/Suggestions/CommandsConfig.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,26 @@ public class DefaultCommandsConfig: CommandsConfig {
4444
var instantCommands = [CommandHandler]()
4545

4646
let channelConfig = channelController.channel?.config
47+
let availableCommands = channelConfig?.commands.map(\.name) ?? []
4748

48-
let giphyEnabled = channelConfig?.commands.first(where: { command in
49-
command.name == "giphy"
50-
}) != nil
51-
52-
if giphyEnabled {
49+
if availableCommands.contains("giphy") {
5350
let giphyCommand = GiphyCommandHandler(commandSymbol: "/giphy")
5451
instantCommands.append(giphyCommand)
5552
}
5653

57-
if channelConfig?.mutesEnabled == true {
54+
if availableCommands.contains("mute") {
5855
let muteCommand = MuteCommandHandler(
5956
channelController: channelController,
6057
commandSymbol: "/mute"
6158
)
59+
instantCommands.append(muteCommand)
60+
}
61+
62+
if availableCommands.contains("unmute") {
6263
let unmuteCommand = UnmuteCommandHandler(
6364
channelController: channelController,
6465
commandSymbol: "/unmute"
6566
)
66-
instantCommands.append(muteCommand)
6767
instantCommands.append(unmuteCommand)
6868
}
6969

StreamChatSwiftUITests/Tests/ChatChannel/Suggestions/CommandsHandler_Tests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@testable import StreamChat
66
@testable import StreamChatSwiftUI
7+
@testable import StreamChatTestTools
78
import XCTest
89

910
class CommandsHandler_Tests: StreamChatTestCase {
@@ -168,6 +169,39 @@ class CommandsHandler_Tests: StreamChatTestCase {
168169
XCTAssert(displayInfo == nil)
169170
}
170171

172+
func test_defaultCommandsConfig() {
173+
// Given
174+
let channelController = ChatChannelController_Mock.mock()
175+
channelController.channel_mock = .mock(
176+
cid: .unique,
177+
config: .mock(commands: [.init(name: "mute"), .init(name: "unmute"), .init(name: "giphy")])
178+
)
179+
let defaultCommandsHandler = DefaultCommandsConfig()
180+
let handler = defaultCommandsHandler.makeCommandsHandler(with: channelController)
181+
182+
XCTAssertNotNil(handler.canHandleCommand(in: "/mention @user", caretLocation: 10))
183+
XCTAssertNotNil(handler.canHandleCommand(in: "/mute", caretLocation: 0))
184+
XCTAssertNotNil(handler.canHandleCommand(in: "/unmute", caretLocation: 0))
185+
XCTAssertNotNil(handler.canHandleCommand(in: "/giphy", caretLocation: 0))
186+
}
187+
188+
func test_defaultCommandsConfig_whenWithoutMutesCommands() {
189+
// Given
190+
let channelController = ChatChannelController_Mock.mock()
191+
channelController.channel_mock = .mock(
192+
cid: .unique,
193+
config: .mock(commands: [.init(name: "giphy")])
194+
)
195+
let defaultCommandsHandler = DefaultCommandsConfig()
196+
let handler = defaultCommandsHandler.makeCommandsHandler(with: channelController)
197+
198+
XCTAssertNil(handler.canHandleCommand(in: "/mute", caretLocation: 0))
199+
XCTAssertNil(handler.canHandleCommand(in: "/unmute", caretLocation: 0))
200+
201+
XCTAssertNotNil(handler.canHandleCommand(in: "/mention @user", caretLocation: 10))
202+
XCTAssertNotNil(handler.canHandleCommand(in: "/giphy", caretLocation: 0))
203+
}
204+
171205
// MARK: - private
172206

173207
private func command(

0 commit comments

Comments
 (0)