diff --git a/CHANGES.md b/CHANGES.md index cdc9250841..309b72215e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Improvements 🙌: - Handle code tags (#567) Other changes: + - Markdown set to off by default (#412) - Accessibility improvements to the attachment file type chooser Bugfix 🐛: diff --git a/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt b/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt index ac79ed8b40..9cf6510fdb 100644 --- a/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt +++ b/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt @@ -44,12 +44,11 @@ object CommandParser { return ParsedCommand.ErrorNotACommand } - var messageParts: List? = null - - try { - messageParts = textMessage.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() } + val messageParts = try { + textMessage.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() } } catch (e: Exception) { Timber.e(e, "## manageSplashCommand() : split failed") + null } // test if the string cut fails @@ -57,10 +56,8 @@ object CommandParser { return ParsedCommand.ErrorEmptySlashCommand } - val slashCommand = messageParts[0] - - when (slashCommand) { - Command.CHANGE_DISPLAY_NAME.command -> { + when (val slashCommand = messageParts.first()) { + Command.CHANGE_DISPLAY_NAME.command -> { val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim() return if (newDisplayName.isNotEmpty()) { @@ -69,7 +66,7 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME) } } - Command.TOPIC.command -> { + Command.TOPIC.command -> { val newTopic = textMessage.substring(Command.TOPIC.command.length).trim() return if (newTopic.isNotEmpty()) { @@ -78,12 +75,12 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.TOPIC) } } - Command.EMOTE.command -> { + Command.EMOTE.command -> { val message = textMessage.substring(Command.EMOTE.command.length).trim() return ParsedCommand.SendEmote(message) } - Command.JOIN_ROOM.command -> { + Command.JOIN_ROOM.command -> { val roomAlias = textMessage.substring(Command.JOIN_ROOM.command.length).trim() return if (roomAlias.isNotEmpty()) { @@ -92,7 +89,7 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.JOIN_ROOM) } } - Command.PART.command -> { + Command.PART.command -> { val roomAlias = textMessage.substring(Command.PART.command.length).trim() return if (roomAlias.isNotEmpty()) { @@ -101,7 +98,7 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.PART) } } - Command.INVITE.command -> { + Command.INVITE.command -> { return if (messageParts.size == 2) { val userId = messageParts[1] @@ -114,7 +111,7 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.INVITE) } } - Command.KICK_USER.command -> { + Command.KICK_USER.command -> { return if (messageParts.size >= 2) { val userId = messageParts[1] if (MatrixPatterns.isUserId(userId)) { @@ -130,7 +127,7 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.KICK_USER) } } - Command.BAN_USER.command -> { + Command.BAN_USER.command -> { return if (messageParts.size >= 2) { val userId = messageParts[1] if (MatrixPatterns.isUserId(userId)) { @@ -146,7 +143,7 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.BAN_USER) } } - Command.UNBAN_USER.command -> { + Command.UNBAN_USER.command -> { return if (messageParts.size == 2) { val userId = messageParts[1] @@ -159,7 +156,7 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.UNBAN_USER) } } - Command.SET_USER_POWER_LEVEL.command -> { + Command.SET_USER_POWER_LEVEL.command -> { return if (messageParts.size == 3) { val userId = messageParts[1] if (MatrixPatterns.isUserId(userId)) { @@ -192,25 +189,25 @@ object CommandParser { ParsedCommand.ErrorSyntax(Command.SET_USER_POWER_LEVEL) } } - Command.MARKDOWN.command -> { + Command.MARKDOWN.command -> { return if (messageParts.size == 2) { when { - "on".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(true) + "on".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(true) "off".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(false) - else -> ParsedCommand.ErrorSyntax(Command.MARKDOWN) + else -> ParsedCommand.ErrorSyntax(Command.MARKDOWN) } } else { ParsedCommand.ErrorSyntax(Command.MARKDOWN) } } - Command.CLEAR_SCALAR_TOKEN.command -> { + Command.CLEAR_SCALAR_TOKEN.command -> { return if (messageParts.size == 1) { ParsedCommand.ClearScalarToken } else { ParsedCommand.ErrorSyntax(Command.CLEAR_SCALAR_TOKEN) } } - else -> { + else -> { // Unknown command return ParsedCommand.ErrorUnknownSlashCommand(slashCommand) } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt index f9601265d3..a593bb6e96 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -576,7 +576,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { * @return true if the markdown is enabled */ fun isMarkdownEnabled(): Boolean { - return defaultPrefs.getBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, true) + return defaultPrefs.getBoolean(SETTINGS_ENABLE_MARKDOWN_KEY, false) } /** diff --git a/vector/src/main/res/xml/vector_settings_preferences.xml b/vector/src/main/res/xml/vector_settings_preferences.xml index 11209b5345..96471cfebe 100644 --- a/vector/src/main/res/xml/vector_settings_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_preferences.xml @@ -39,7 +39,7 @@ android:title="@string/settings_send_typing_notifs" />