From a882a212c23cebd865f7d6624db201c8741318af Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 9 Jan 2021 21:24:13 +0600 Subject: [PATCH] remove different internal strings things --- .../BaseMessageUpdateToMediaGroupUpdate.kt | 55 ------------------- .../internal/CaptionAndTextSourcesToText.kt | 12 ---- .../MultilevelTextSourceFormatting.kt | 5 -- .../utils/internal/StringFormatting.kt | 10 ---- 4 files changed, 82 deletions(-) delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt deleted file mode 100644 index 5e4cc86d4f..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt +++ /dev/null @@ -1,55 +0,0 @@ -package dev.inmo.tgbotapi.utils.internal - -import dev.inmo.tgbotapi.types.MediaGroupIdentifier -import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.update.* -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* -import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate -import dev.inmo.tgbotapi.types.update.abstracts.Update - -private inline val Pair.message - get() = first - -internal fun List.convertWithMediaGroupUpdates(): List { - val resultUpdates = mutableListOf() - val mediaGroups = mutableMapOf>() - for (update in this) { - val asEditMediaGroupMessage = update.toEditMediaGroupUpdate() - if (asEditMediaGroupMessage != null) { - resultUpdates.add(asEditMediaGroupMessage) - } else { - val data = update.data - if (data is MediaGroupMessage) { - (mediaGroups[data.mediaGroupId] ?: mutableListOf().also { mediaGroups[data.mediaGroupId] = it }).add(update) - } else { - resultUpdates.add(update) - } - } - } - mediaGroups.values.map { - it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate -> - resultUpdates.add(mediaGroupUpdate) - } - } - return resultUpdates.sortedBy { it.updateId } -} - -internal fun List.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let { - if (isEmpty()) { - return@let null - } - val resultList = sortedBy { it.updateId } - when (first()) { - is MessageUpdate -> MessageMediaGroupUpdate(resultList) - is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList) - else -> null - } -} - -internal fun BaseMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate? = (this as? EditMediaGroupUpdate) ?: let { - when (this) { - is EditMessageUpdate -> EditMessageMediaGroupUpdate(this) - is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this) - else -> null - } -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt index 3b4265f008..143dd51d53 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt @@ -57,12 +57,6 @@ internal fun TextSourcesList.toMarkdownTexts(): List = createMarkdownTex ) internal fun TextContent.toMarkdownTexts(): List = textSources.toMarkdownTexts() -internal fun TextSourcesList.toMarkdownExplanations(): List = createMarkdownText( - this, - explanationLimit.last -) -internal fun ExplainedInput.toMarkdownExplanations(): List = textSources.toMarkdownTexts() - internal fun createMarkdownV2Text( entities: TextSourcesList, @@ -81,12 +75,6 @@ internal fun TextSourcesList.toMarkdownV2Texts(): List = createMarkdownV ) internal fun TextContent.toMarkdownV2Texts(): List = textSources.toMarkdownV2Texts() -internal fun TextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( - this, - explanationLimit.last -) -internal fun ExplainedInput.toMarkdownV2Explanations(): List = textSources.toMarkdownV2Texts() - internal fun createHtmlText( entities: TextSourcesList, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index ec8cf5ab7c..bac1e06c41 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -148,8 +148,3 @@ internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2() internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml() - - -internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + subsources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + subsources.joinSubSourcesHtml() - diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt index 2c3b8e8076..dce43d2d63 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt @@ -99,12 +99,10 @@ private inline fun String.hashTag(adapt: String.() -> String): String = if (star } internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link) -internal fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) internal fun String.mentionMarkdown(): String = mention(String::toMarkdown) internal fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown) -internal fun String.hashTagHTML(): String = hashTag(String::toHtml) internal fun String.phoneMarkdown(): String = toMarkdown() @@ -136,14 +134,6 @@ internal infix fun Pair.link(parseMode: ParseMode): String = whe is MarkdownV2 -> first.linkMarkdownV2(second) } - -internal infix fun String.command(parseMode: ParseMode): String = when (parseMode) { - is HTML -> commandHTML() - is Markdown -> commandMarkdown() - is MarkdownV2 -> commandMarkdownV2() -} - - internal infix fun String.underline(parseMode: ParseMode): String = when (parseMode) { is HTML -> underlineHTML() is Markdown -> underlineMarkdown()