Skip to content

Commit 0b0025d

Browse files
committed
Avoid showing command-unavailable feedback when no command can match
1 parent 428d00d commit 0b0025d

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerController.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,8 @@ public class MessageComposerController(
12491249
if (!config.activeCommandEnabled) return false
12501250
val action = activeAction as? Edit ?: return false
12511251
if (!CommandText.isTrigger(messageText)) return false
1252+
val prefix = messageText.removePrefix("/")
1253+
if (commands.none { it.name.startsWith(prefix) }) return false
12521254
_state.update { it.copy(commandSuggestions = emptyList()) }
12531255
_events.tryEmit(MessageComposerViewEvent.CommandUnavailable(action))
12541256
return true

stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,35 @@ internal class MessageComposerControllerTest {
10501050
}
10511051
}
10521052

1053+
@Test
1054+
fun `Given edit mode When user types slash prefix that matches no command Then no event is emitted`() = runTest {
1055+
// Given
1056+
val command = randomCommand(name = "giphy")
1057+
val editedMessage = randomMessage(cid = CID, text = "")
1058+
val controller = Fixture()
1059+
.givenConfig(MessageComposerController.Config(activeCommandEnabled = true))
1060+
.givenAppSettings()
1061+
.givenAudioPlayer(mock())
1062+
.givenClientState(randomUser())
1063+
.givenGlobalState()
1064+
.givenChannelState(
1065+
configState = MutableStateFlow(Config(commands = listOf(command))),
1066+
)
1067+
.get()
1068+
controller.performMessageAction(Edit(editedMessage))
1069+
advanceUntilIdle()
1070+
1071+
// When / Then
1072+
controller.events.test {
1073+
controller.setMessageInput("/xyz")
1074+
advanceUntilIdle()
1075+
1076+
// Plain slash text, not a blocked command attempt → no snackbar.
1077+
expectNoEvents()
1078+
cancelAndIgnoreRemainingEvents()
1079+
}
1080+
}
1081+
10531082
@Test
10541083
fun `Given slash typed When action becomes Reply Then suggestions re-sort by availability`() = runTest {
10551084
// Given

0 commit comments

Comments
 (0)