Skip to content

Commit

Permalink
Merge pull request #4268 from vector-im/feature/bma/improve_part
Browse files Browse the repository at this point in the history
A few changes on the slash command
  • Loading branch information
bmarty authored Oct 19, 2021
2 parents ab0e707 + 4626199 commit 86b7fe6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 63 deletions.
1 change: 1 addition & 0 deletions changelog.d/2909.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement /part command, with or without parameter
1 change: 1 addition & 0 deletions changelog.d/4261.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash on slash commands Exceptions
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
RESET_USER_POWER_LEVEL("/deop", "<user-id>", R.string.command_description_deop_user, false),
ROOM_NAME("/roomname", "<name>", R.string.command_description_room_name, false),
INVITE("/invite", "<user-id> [reason]", R.string.command_description_invite_user, false),
JOIN_ROOM("/join", "<room-alias> [reason]", R.string.command_description_join_room, false),
PART("/part", "<room-alias> [reason]", R.string.command_description_part_room, false),
JOIN_ROOM("/join", "<room-address> [reason]", R.string.command_description_join_room, false),
PART("/part", "[<room-address>]", R.string.command_description_part_room, false),
TOPIC("/topic", "<topic>", R.string.command_description_topic, false),
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user, false),
CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,10 @@ object CommandParser {
}
}
Command.PART.command -> {
if (messageParts.size >= 2) {
val roomAlias = messageParts[1]

if (roomAlias.isNotEmpty()) {
ParsedCommand.PartRoom(
roomAlias,
textMessage.substring(Command.PART.length + roomAlias.length)
.trim()
.takeIf { it.isNotBlank() }
)
} else {
ParsedCommand.ErrorSyntax(Command.PART)
}
} else {
ParsedCommand.ErrorSyntax(Command.PART)
when (messageParts.size) {
1 -> ParsedCommand.PartRoom(null)
2 -> ParsedCommand.PartRoom(messageParts[1])
else -> ParsedCommand.ErrorSyntax(Command.PART)
}
}
Command.ROOM_NAME.command -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sealed class ParsedCommand {
class Invite(val userId: String, val reason: String?) : ParsedCommand()
class Invite3Pid(val threePid: ThreePid) : ParsedCommand()
class JoinRoom(val roomAlias: String, val reason: String?) : ParsedCommand()
class PartRoom(val roomAlias: String, val reason: String?) : ParsedCommand()
class PartRoom(val roomAlias: String?) : ParsedCommand()
class ChangeTopic(val topic: String) : ParsedCommand()
class KickUser(val userId: String, val reason: String?) : ParsedCommand()
class ChangeDisplayName(val displayName: String) : ParsedCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1451,8 +1451,8 @@ class RoomDetailFragment @Inject constructor(

private fun renderSendMessageResult(sendMessageResult: TextComposerViewEvents.SendMessageResult) {
when (sendMessageResult) {
is TextComposerViewEvents.SlashCommandHandled -> {
sendMessageResult.messageRes?.let { showSnackWithMessage(getString(it)) }
is TextComposerViewEvents.SlashCommandLoading -> {
showLoading(null)
}
is TextComposerViewEvents.SlashCommandError -> {
displayCommandError(getString(R.string.command_problem_with_parameters, sendMessageResult.command.command))
Expand All @@ -1461,9 +1461,12 @@ class RoomDetailFragment @Inject constructor(
displayCommandError(getString(R.string.unrecognized_command, sendMessageResult.command))
}
is TextComposerViewEvents.SlashCommandResultOk -> {
dismissLoadingDialog()
views.composerLayout.setTextIfDifferent("")
sendMessageResult.messageRes?.let { showSnackWithMessage(getString(it)) }
}
is TextComposerViewEvents.SlashCommandResultError -> {
dismissLoadingDialog()
displayCommandError(errorFormatter.toHumanReadable(sendMessageResult.throwable))
}
is TextComposerViewEvents.SlashCommandNotImplemented -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ sealed class TextComposerViewEvents : VectorViewEvents {
data class JoinRoomCommandSuccess(val roomId: String) : SendMessageResult()
class SlashCommandError(val command: Command) : SendMessageResult()
class SlashCommandUnknown(val command: String) : SendMessageResult()
data class SlashCommandHandled(@StringRes val messageRes: Int? = null) : SendMessageResult()
object SlashCommandResultOk : SendMessageResult()
object SlashCommandLoading : SendMessageResult()
data class SlashCommandResultOk(@StringRes val messageRes: Int? = null) : SendMessageResult()
class SlashCommandResultError(val throwable: Throwable) : SendMessageResult()

data class OpenRoomMemberProfile(val userId: String) : TextComposerViewEvents()
Expand Down
Loading

0 comments on commit 86b7fe6

Please sign in to comment.