Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### 🐞 Fixed
- Fix swipe to reply enabled when quoting a message is disabled [#824](https://github.com/GetStream/stream-chat-swiftui/pull/824)
- Fix mark unread action not removed when read events are disabled [#823](https://github.com/GetStream/stream-chat-swiftui/pull/823)
- Fix user mentions not working when commands are disabled [#826](https://github.com/GetStream/stream-chat-swiftui/pull/826)

# [4.78.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.78.0)
_April 24, 2025_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ open class MessageComposerViewModel: ObservableObject {
}

public var showCommandsOverlay: Bool {
// Mentions are really not commands, but at the moment this flag controls
// if the mentions are displayed or not, so if the command is related to mentions
// then we need to ignore if commands are available or not.
let isMentionsSuggestions = composerCommand?.id == "mentions"
if isMentionsSuggestions {
return true
}
let commandAvailable = composerCommand != nil
let configuredCommandsAvailable = channelController.channel?.config.commands.count ?? 0 > 0
return commandAvailable && configuredCommandsAvailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,106 @@ class MessageComposerViewModel_Tests: StreamChatTestCase {
XCTAssertFalse(viewModel.canSendPoll)
}

func test_showCommandsOverlay() {
// Given
let channelController = makeChannelController()
let messageController = ChatMessageControllerSUI_Mock.mock(
chatClient: chatClient,
cid: .unique,
messageId: .unique
)
let viewModel = MessageComposerViewModel(
channelController: channelController,
messageController: messageController
)

// When
let channelConfig = ChannelConfig(commands: [.init()])
channelController.channel_mock = .mock(
cid: .unique,
config: channelConfig
)
viewModel.composerCommand = .init(id: "test", typingSuggestion: .empty, displayInfo: nil)

// Then
XCTAssertTrue(viewModel.showCommandsOverlay)
}

func test_showCommandsOverlay_whenComposerCommandIsNil_returnsFalse() {
// Given
let channelController = makeChannelController()
let messageController = ChatMessageControllerSUI_Mock.mock(
chatClient: chatClient,
cid: .unique,
messageId: .unique
)
let viewModel = MessageComposerViewModel(
channelController: channelController,
messageController: messageController
)

// When
let channelConfig = ChannelConfig(commands: [.init()])
channelController.channel_mock = .mock(
cid: .unique,
config: channelConfig
)
viewModel.composerCommand = nil

// Then
XCTAssertFalse(viewModel.showCommandsOverlay)
}

func test_showCommandsOverlay_whenCommandsAreDisabled_returnsFalse() {
// Given
let channelController = makeChannelController()
let messageController = ChatMessageControllerSUI_Mock.mock(
chatClient: chatClient,
cid: .unique,
messageId: .unique
)
let viewModel = MessageComposerViewModel(
channelController: channelController,
messageController: messageController
)

// When
let channelConfig = ChannelConfig(commands: [])
channelController.channel_mock = .mock(
cid: .unique,
config: channelConfig
)
viewModel.composerCommand = .init(id: "test", typingSuggestion: .empty, displayInfo: nil)

// Then
XCTAssertFalse(viewModel.showCommandsOverlay)
}

func test_showCommandsOverlay_whenCommandsAreDisabledButIsMentions_returnsTrue() {
// Given
let channelController = makeChannelController()
let messageController = ChatMessageControllerSUI_Mock.mock(
chatClient: chatClient,
cid: .unique,
messageId: .unique
)
let viewModel = MessageComposerViewModel(
channelController: channelController,
messageController: messageController
)

// When
let channelConfig = ChannelConfig(commands: [])
channelController.channel_mock = .mock(
cid: .unique,
config: channelConfig
)
viewModel.composerCommand = .init(id: "mentions", typingSuggestion: .empty, displayInfo: nil)

// Then
XCTAssertTrue(viewModel.showCommandsOverlay)
}

func test_addedAsset_extraData() {
// Given
let image = UIImage(systemName: "person")!
Expand Down
Loading