Add support for `/plain` command (#12)

This commit is contained in:
Benoit Marty 2020-03-01 09:59:00 +01:00
parent 41b4f412c4
commit b7ff546f66
6 changed files with 19 additions and 2 deletions

View File

@ -5,7 +5,7 @@ Features ✨:
- -
Improvements 🙌: Improvements 🙌:
- - Add support for `/plain` command (#12)
Bugfix 🐛: Bugfix 🐛:
- Fix crash on attachment preview screen (#1088) - Fix crash on attachment preview screen (#1088)

View File

@ -43,6 +43,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler), SPOILER("/spoiler", "<message>", R.string.command_description_spoiler),
POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll), POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll),
SHRUG("/shrug", "<message>", R.string.command_description_shrug), SHRUG("/shrug", "<message>", R.string.command_description_shrug),
PLAIN("/plain", "<message>", R.string.command_description_plain),
// TODO temporary command // TODO temporary command
VERIFY_USER("/verify", "<user-id>", R.string.command_description_verify); VERIFY_USER("/verify", "<user-id>", R.string.command_description_verify);

View File

@ -57,6 +57,15 @@ object CommandParser {
} }
return when (val slashCommand = messageParts.first()) { return when (val slashCommand = messageParts.first()) {
Command.PLAIN.command -> {
val text = textMessage.substring(Command.PLAIN.command.length).trim()
if (text.isNotEmpty()) {
ParsedCommand.SendPlainText(text)
} else {
ParsedCommand.ErrorSyntax(Command.PLAIN)
}
}
Command.CHANGE_DISPLAY_NAME.command -> { Command.CHANGE_DISPLAY_NAME.command -> {
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim() val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim()

View File

@ -33,6 +33,7 @@ sealed class ParsedCommand {
// Valid commands: // Valid commands:
class SendPlainText(val message: CharSequence) : ParsedCommand()
class SendEmote(val message: CharSequence) : ParsedCommand() class SendEmote(val message: CharSequence) : ParsedCommand()
class SendRainbow(val message: CharSequence) : ParsedCommand() class SendRainbow(val message: CharSequence) : ParsedCommand()
class SendRainbowEmote(val message: CharSequence) : ParsedCommand() class SendRainbowEmote(val message: CharSequence) : ParsedCommand()

View File

@ -340,6 +340,12 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
is ParsedCommand.ErrorUnknownSlashCommand -> { is ParsedCommand.ErrorUnknownSlashCommand -> {
_viewEvents.post(RoomDetailViewEvents.SlashCommandUnknown(slashCommandResult.slashCommand)) _viewEvents.post(RoomDetailViewEvents.SlashCommandUnknown(slashCommandResult.slashCommand))
} }
is ParsedCommand.SendPlainText -> {
// Send the text message to the room, without markdown
room.sendTextMessage(slashCommandResult.message, autoMarkdown = false)
_viewEvents.post(RoomDetailViewEvents.MessageSent)
popDraft()
}
is ParsedCommand.Invite -> { is ParsedCommand.Invite -> {
handleInviteSlashCommand(slashCommandResult) handleInviteSlashCommand(slashCommandResult)
popDraft() popDraft()

View File

@ -26,7 +26,7 @@
<!-- BEGIN Strings added by Others --> <!-- BEGIN Strings added by Others -->
<string name="command_description_plain">Sends a message as plain text, without interpreting it as markdown</string>
<!-- END Strings added by Others --> <!-- END Strings added by Others -->
</resources> </resources>