Enhance SlashCommandNotSupportedInThreads

This commit is contained in:
ariskotsomitopoulos 2022-01-31 13:42:20 +02:00
parent cb3501ea17
commit d91f3d2de6
5 changed files with 25 additions and 11 deletions

View file

@ -63,10 +63,9 @@ class CommandParser @Inject constructor() {
val slashCommand = messageParts.first()
val message = textMessage.substring(slashCommand.length).trim()
if (isInThreadTimeline) {
if (notSupportedThreadsCommands.contains(slashCommand)) {
return ParsedCommand.ErrorCommandNotSupportedInThreads(slashCommand)
}
getNotSupportedByThreads(isInThreadTimeline, slashCommand)?.let {
return ParsedCommand.ErrorCommandNotSupportedInThreads(it)
}
when {
@ -406,14 +405,29 @@ class CommandParser @Inject constructor() {
}
}
val notSupportedThreadsCommands: List<String> by lazy {
private val notSupportedThreadsCommands: List<Command> by lazy {
Command.values().filter {
!it.isThreadCommand
}.map {
it.command
}
}
/**
* Checks whether or not the current command is not supported by threads
* @param slashCommand the slash command that will be checked
* @param isInThreadTimeline if its true we are in a thread timeline
* @return The command that is not supported
*/
private fun getNotSupportedByThreads(isInThreadTimeline: Boolean, slashCommand: String): Command? {
if (isInThreadTimeline) {
notSupportedThreadsCommands.firstOrNull {
it.command == slashCommand
}?.let {
return it
}
}
return null
}
private fun trimParts(message: CharSequence, messageParts: List<String>): String? {
val partsSize = messageParts.sumOf { it.length }
val gapsNumber = messageParts.size - 1

View file

@ -28,7 +28,7 @@ sealed interface ParsedCommand {
object ErrorEmptySlashCommand : ParsedCommand
class ErrorCommandNotSupportedInThreads(val slashCommand: String) : ParsedCommand
class ErrorCommandNotSupportedInThreads(val command: Command) : ParsedCommand
// Unknown/Unsupported slash command
data class ErrorUnknownSlashCommand(val slashCommand: String) : ParsedCommand

View file

@ -1664,7 +1664,7 @@ class TimelineFragment @Inject constructor(
displayCommandError(getString(R.string.not_implemented))
}
is MessageComposerViewEvents.SlashCommandNotSupportedInThreads -> {
displayCommandError(getString(R.string.command_not_supported_in_threads, sendMessageResult.command))
displayCommandError(getString(R.string.command_not_supported_in_threads, sendMessageResult.command.command))
}
} // .exhaustive

View file

@ -32,7 +32,7 @@ sealed class MessageComposerViewEvents : VectorViewEvents {
data class JoinRoomCommandSuccess(val roomId: String) : SendMessageResult()
class SlashCommandError(val command: Command) : SendMessageResult()
class SlashCommandUnknown(val command: String) : SendMessageResult()
class SlashCommandNotSupportedInThreads(val command: String) : SendMessageResult()
class SlashCommandNotSupportedInThreads(val command: Command) : SendMessageResult()
data class SlashCommandHandled(@StringRes val messageRes: Int? = null) : SendMessageResult()
object SlashCommandLoading : SendMessageResult()
data class SlashCommandResultOk(@StringRes val messageRes: Int? = null) : SendMessageResult()

View file

@ -217,7 +217,7 @@ class MessageComposerViewModel @AssistedInject constructor(
_viewEvents.post(MessageComposerViewEvents.SlashCommandUnknown(slashCommandResult.slashCommand))
}
is ParsedCommand.ErrorCommandNotSupportedInThreads -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandNotSupportedInThreads(slashCommandResult.slashCommand))
_viewEvents.post(MessageComposerViewEvents.SlashCommandNotSupportedInThreads(slashCommandResult.command))
}
is ParsedCommand.SendPlainText -> {
// Send the text message to the room, without markdown