Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c2eba4

Browse filesBrowse files
authored
Fix user mentions not working when commands are disabled (#826)
* Fix user mentions not working when commands are disabled * Update CHANGELOG.md * Revert "Fix user mentions not working when commands are disabled" This reverts commit f01b010. * Do the implementation in the view model only instead
1 parent 7f926e3 commit 1c2eba4
Copy full SHA for 1c2eba4

File tree

3 files changed

+108
-0
lines changed
Filter options

3 files changed

+108
-0
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
### 🐞 Fixed
99
- Fix swipe to reply enabled when quoting a message is disabled [#824](https://github.com/GetStream/stream-chat-swiftui/pull/824)
1010
- Fix mark unread action not removed when read events are disabled [#823](https://github.com/GetStream/stream-chat-swiftui/pull/823)
11+
- Fix user mentions not working when commands are disabled [#826](https://github.com/GetStream/stream-chat-swiftui/pull/826)
1112

1213
# [4.78.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.78.0)
1314
_April 24, 2025_

‎Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Copy file name to clipboardExpand all lines: Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@ open class MessageComposerViewModel: ObservableObject {
453453
}
454454

455455
public var showCommandsOverlay: Bool {
456+
// Mentions are really not commands, but at the moment this flag controls
457+
// if the mentions are displayed or not, so if the command is related to mentions
458+
// then we need to ignore if commands are available or not.
459+
let isMentionsSuggestions = composerCommand?.id == "mentions"
460+
if isMentionsSuggestions {
461+
return true
462+
}
456463
let commandAvailable = composerCommand != nil
457464
let configuredCommandsAvailable = channelController.channel?.config.commands.count ?? 0 > 0
458465
return commandAvailable && configuredCommandsAvailable

‎StreamChatSwiftUITests/Tests/ChatChannel/MessageComposerViewModel_Tests.swift

Copy file name to clipboardExpand all lines: StreamChatSwiftUITests/Tests/ChatChannel/MessageComposerViewModel_Tests.swift
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,106 @@ class MessageComposerViewModel_Tests: StreamChatTestCase {
659659
XCTAssertFalse(viewModel.canSendPoll)
660660
}
661661

662+
func test_showCommandsOverlay() {
663+
// Given
664+
let channelController = makeChannelController()
665+
let messageController = ChatMessageControllerSUI_Mock.mock(
666+
chatClient: chatClient,
667+
cid: .unique,
668+
messageId: .unique
669+
)
670+
let viewModel = MessageComposerViewModel(
671+
channelController: channelController,
672+
messageController: messageController
673+
)
674+
675+
// When
676+
let channelConfig = ChannelConfig(commands: [.init()])
677+
channelController.channel_mock = .mock(
678+
cid: .unique,
679+
config: channelConfig
680+
)
681+
viewModel.composerCommand = .init(id: "test", typingSuggestion: .empty, displayInfo: nil)
682+
683+
// Then
684+
XCTAssertTrue(viewModel.showCommandsOverlay)
685+
}
686+
687+
func test_showCommandsOverlay_whenComposerCommandIsNil_returnsFalse() {
688+
// Given
689+
let channelController = makeChannelController()
690+
let messageController = ChatMessageControllerSUI_Mock.mock(
691+
chatClient: chatClient,
692+
cid: .unique,
693+
messageId: .unique
694+
)
695+
let viewModel = MessageComposerViewModel(
696+
channelController: channelController,
697+
messageController: messageController
698+
)
699+
700+
// When
701+
let channelConfig = ChannelConfig(commands: [.init()])
702+
channelController.channel_mock = .mock(
703+
cid: .unique,
704+
config: channelConfig
705+
)
706+
viewModel.composerCommand = nil
707+
708+
// Then
709+
XCTAssertFalse(viewModel.showCommandsOverlay)
710+
}
711+
712+
func test_showCommandsOverlay_whenCommandsAreDisabled_returnsFalse() {
713+
// Given
714+
let channelController = makeChannelController()
715+
let messageController = ChatMessageControllerSUI_Mock.mock(
716+
chatClient: chatClient,
717+
cid: .unique,
718+
messageId: .unique
719+
)
720+
let viewModel = MessageComposerViewModel(
721+
channelController: channelController,
722+
messageController: messageController
723+
)
724+
725+
// When
726+
let channelConfig = ChannelConfig(commands: [])
727+
channelController.channel_mock = .mock(
728+
cid: .unique,
729+
config: channelConfig
730+
)
731+
viewModel.composerCommand = .init(id: "test", typingSuggestion: .empty, displayInfo: nil)
732+
733+
// Then
734+
XCTAssertFalse(viewModel.showCommandsOverlay)
735+
}
736+
737+
func test_showCommandsOverlay_whenCommandsAreDisabledButIsMentions_returnsTrue() {
738+
// Given
739+
let channelController = makeChannelController()
740+
let messageController = ChatMessageControllerSUI_Mock.mock(
741+
chatClient: chatClient,
742+
cid: .unique,
743+
messageId: .unique
744+
)
745+
let viewModel = MessageComposerViewModel(
746+
channelController: channelController,
747+
messageController: messageController
748+
)
749+
750+
// When
751+
let channelConfig = ChannelConfig(commands: [])
752+
channelController.channel_mock = .mock(
753+
cid: .unique,
754+
config: channelConfig
755+
)
756+
viewModel.composerCommand = .init(id: "mentions", typingSuggestion: .empty, displayInfo: nil)
757+
758+
// Then
759+
XCTAssertTrue(viewModel.showCommandsOverlay)
760+
}
761+
662762
func test_addedAsset_extraData() {
663763
// Given
664764
let image = UIImage(systemName: "person")!

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.