From 617b8091db1bafe7e912f0ca81516c88bda18ceb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 14 Jan 2023 23:42:16 +0600 Subject: [PATCH] small refactor --- .../src/commonMain/kotlin/MessagesResender.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/resender/src/commonMain/kotlin/MessagesResender.kt b/resender/src/commonMain/kotlin/MessagesResender.kt index 27c6444..63d8893 100644 --- a/resender/src/commonMain/kotlin/MessagesResender.kt +++ b/resender/src/commonMain/kotlin/MessagesResender.kt @@ -18,19 +18,19 @@ class MessagesResender( targetChatId: IdChatIdentifier, messagesInfo: List ): List> { - val orders = messagesInfo.mapIndexed { i, messageInfo -> messageInfo to i }.toMap() - val sortedMessagesContents = messagesInfo.groupBy { it.group }.flatMap { (group, list) -> + val messagesWithOrders = messagesInfo.mapIndexed { i, messageInfo -> messageInfo to i }.toMap() + val ordersWithMessagesGroups = messagesInfo.groupBy { it.group }.flatMap { (group, list) -> if (group == null) { list.map { - orders.getValue(it) to listOf(it) + messagesWithOrders.getValue(it) to listOf(it) } } else { - listOf(orders.getValue(list.first()) to list) + listOf(messagesWithOrders.getValue(list.first()) to list) } }.sortedBy { it.first } - return sortedMessagesContents.flatMap { (_, contents) -> - val result = mutableListOf>() + return ordersWithMessagesGroups.flatMap { (_, contents) -> + val sourceMessagesToSentMessages = mutableListOf>() when { contents.size == 1 -> { @@ -88,7 +88,7 @@ class MessagesResender( it as ContentMessage } src to (forwardedMessageAsMediaPartMessage ?: null.also { _ -> - result.add( + sourceMessagesToSentMessages.add( src to MessageMetaInfo( targetChatId, bot.execute( @@ -104,7 +104,7 @@ class MessagesResender( } resultContents.singleOrNull() ?.also { (src, it) -> - result.add( + sourceMessagesToSentMessages.add( src to MessageMetaInfo( targetChatId, bot.execute( @@ -124,7 +124,7 @@ class MessagesResender( ) ).content.group.mapIndexed { i, partWrapper -> it.getOrNull(i) ?.let { - result.add( + sourceMessagesToSentMessages.add( it.first to MessageMetaInfo( partWrapper.sourceMessage.chat.id, partWrapper.sourceMessage.messageId, @@ -137,7 +137,7 @@ class MessagesResender( } } - result.toList() + sourceMessagesToSentMessages.toList() } }