Merge pull request #1093 from vector-im/feature/plain_text

Add support for `/plain` command (#12)
This commit is contained in:
Benoit Marty 2020-03-02 19:37:05 +01:00 committed by GitHub
commit 5ff670b184
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 2 deletions

View file

@ -5,7 +5,7 @@ Features ✨:
-
Improvements 🙌:
-
- Add support for `/plain` command (#12)
Bugfix 🐛:
- 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),
POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll),
SHRUG("/shrug", "<message>", R.string.command_description_shrug),
PLAIN("/plain", "<message>", R.string.command_description_plain),
// TODO temporary command
VERIFY_USER("/verify", "<user-id>", R.string.command_description_verify);

View file

@ -57,6 +57,15 @@ object CommandParser {
}
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 -> {
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim()

View file

@ -33,6 +33,7 @@ sealed class ParsedCommand {
// Valid commands:
class SendPlainText(val message: CharSequence) : ParsedCommand()
class SendEmote(val message: CharSequence) : ParsedCommand()
class SendRainbow(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 -> {
_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 -> {
handleInviteSlashCommand(slashCommandResult)
popDraft()

View file

@ -26,7 +26,7 @@
<!-- 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 -->
</resources>