Merge pull request #651 from vector-im/feature/markdown_off

Markdown off
This commit is contained in:
Benoit Marty 2019-11-04 10:23:21 +01:00 committed by GitHub
commit 7e467443ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 24 deletions

View File

@ -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 🐛:

View File

@ -44,12 +44,11 @@ object CommandParser {
return ParsedCommand.ErrorNotACommand
}
var messageParts: List<String>? = 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)
}

View File

@ -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)
}
/**

View File

@ -39,7 +39,7 @@
android:title="@string/settings_send_typing_notifs" />
<im.vector.riotx.core.preference.VectorSwitchPreference
android:defaultValue="true"
android:defaultValue="false"
android:key="SETTINGS_ENABLE_MARKDOWN_KEY"
android:summary="@string/settings_send_markdown_summary"
android:title="@string/settings_send_markdown" />