Lazy load notSupportedThreadsCommands to improve performance

This commit is contained in:
ariskotsomitopoulos 2022-01-31 13:08:15 +02:00
parent 3253a252fb
commit cb3501ea17

View file

@ -64,12 +64,7 @@ class CommandParser @Inject constructor() {
val message = textMessage.substring(slashCommand.length).trim()
if (isInThreadTimeline) {
val notSupportedCommandsInThreads = Command.values().filter {
!it.isThreadCommand
}.map {
it.command
}
if (notSupportedCommandsInThreads.contains(slashCommand)) {
if (notSupportedThreadsCommands.contains(slashCommand)) {
return ParsedCommand.ErrorCommandNotSupportedInThreads(slashCommand)
}
}
@ -411,6 +406,14 @@ class CommandParser @Inject constructor() {
}
}
val notSupportedThreadsCommands: List<String> by lazy {
Command.values().filter {
!it.isThreadCommand
}.map {
it.command
}
}
private fun trimParts(message: CharSequence, messageParts: List<String>): String? {
val partsSize = messageParts.sumOf { it.length }
val gapsNumber = messageParts.size - 1