parsing the space commands by checking for the size and last segment to find the space id to join/add to

This commit is contained in:
Adam Brown 2022-08-25 15:29:57 +01:00
parent da70d520bc
commit 493d9240c2
3 changed files with 16 additions and 4 deletions

1
changelog.d/6844.bugfix Normal file
View file

@ -0,0 +1 @@
Fixes /addToSpace and /joinSpace commands showing invalid syntax warnings

View file

@ -374,15 +374,15 @@ class CommandParser @Inject constructor() {
} }
} }
Command.ADD_TO_SPACE.matches(slashCommand) -> { Command.ADD_TO_SPACE.matches(slashCommand) -> {
if (messageParts.size == 1) { if (messageParts.size == 2) {
ParsedCommand.AddToSpace(spaceId = message) ParsedCommand.AddToSpace(spaceId = messageParts.last())
} else { } else {
ParsedCommand.ErrorSyntax(Command.ADD_TO_SPACE) ParsedCommand.ErrorSyntax(Command.ADD_TO_SPACE)
} }
} }
Command.JOIN_SPACE.matches(slashCommand) -> { Command.JOIN_SPACE.matches(slashCommand) -> {
if (messageParts.size == 1) { if (messageParts.size == 2) {
ParsedCommand.JoinSpace(spaceIdOrAlias = message) ParsedCommand.JoinSpace(spaceIdOrAlias = messageParts.last())
} else { } else {
ParsedCommand.ErrorSyntax(Command.JOIN_SPACE) ParsedCommand.ErrorSyntax(Command.JOIN_SPACE)
} }

View file

@ -19,6 +19,8 @@ package im.vector.app.features.command
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test import org.junit.Test
private const val A_SPACE_ID = "!my-space-id"
class CommandParserTest { class CommandParserTest {
@Test @Test
fun parseSlashCommandEmpty() { fun parseSlashCommandEmpty() {
@ -31,6 +33,15 @@ class CommandParserTest {
test("/unknown with param", ParsedCommand.ErrorUnknownSlashCommand("/unknown")) test("/unknown with param", ParsedCommand.ErrorUnknownSlashCommand("/unknown"))
} }
@Test
fun parseSlashAddToSpaceCommand() {
test("/addToSpace $A_SPACE_ID", ParsedCommand.AddToSpace(A_SPACE_ID))
}
@Test
fun parseSlashJoinSpaceCommand() {
test("/joinSpace $A_SPACE_ID", ParsedCommand.JoinSpace(A_SPACE_ID))
}
@Test @Test
fun parseSlashCommandNotACommand() { fun parseSlashCommandNotACommand() {
test("", ParsedCommand.ErrorNotACommand) test("", ParsedCommand.ErrorNotACommand)