From b336b17eef57b5f513e429b932faf63837e16360 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 25 Apr 2020 09:57:59 +0600 Subject: [PATCH] FullTextSourcesList --- CHANGELOG.md | 3 +++ .../CommonAbstracts/Captioned.kt | 2 +- .../CommonAbstracts/Explained.kt | 2 +- .../CommonAbstracts/TextSource.kt | 3 +++ .../types/message/content/TextContent.kt | 3 ++- .../utils/CaptionAndTextSourcesToText.kt | 26 +++++++++---------- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1a8097910..6dc4b330fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,9 @@ * `explanationLimit` range was added as future replacement of `quizPollExplanationLimit` * `quizPollExplanationLimit` now is deprecated * Extensions `toMarkdownExplanations`, `toMarkdownV2Explanations` and `toHtmlExplanations` was added + * Typealias `FullTextSourcesList` was added + * All extensions `fullEntitiesList` now return `FullTextSourcesList` + * All extensions of `List` now are extensions for `FullTextSourcesList` * `TelegramBotAPI-extensions-api`: * `sendQuizPoll` now is using `explanation` parameter instead of `caption` diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Captioned.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Captioned.kt index b7755a370f..8111d0e9d1 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Captioned.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Captioned.kt @@ -15,4 +15,4 @@ interface CaptionedInput : Captioned { val captionEntities: List } -fun CaptionedInput.fullEntitiesList() = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList() +fun CaptionedInput.fullEntitiesList(): FullTextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList() diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Explained.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Explained.kt index 611fde6457..941b21e1f0 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Explained.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/Explained.kt @@ -15,4 +15,4 @@ interface ExplainedInput : Explained { val explanationEntities: List } -fun ExplainedInput.fullEntitiesList() = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList() +fun ExplainedInput.fullEntitiesList(): FullTextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList() diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt index 372f80a2fb..828c494c7b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt @@ -1,5 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts +typealias FullTextSourcesList = List +typealias FullTextPartsList = List + interface TextSource { val asMarkdownSource: String val asMarkdownV2Source: String diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/TextContent.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/TextContent.kt index 613f61a6e1..9ddd37b480 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/TextContent.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/TextContent.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.FullTextSourcesList import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendTextMessage @@ -66,4 +67,4 @@ data class TextContent( } } -fun TextContent.fullEntitiesList() = text.fullListOfSubSource(entities).map { it.source } +fun TextContent.fullEntitiesList(): FullTextSourcesList = text.fullListOfSubSource(entities).map { it.source } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt index 76d3d65e9e..4a2a9c2def 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextCont import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList fun createFormattedText( - entities: List, + entities: FullTextSourcesList, partLength: Int = 4096, mode: ParseMode = MarkdownParseMode ): List { @@ -48,23 +48,23 @@ fun createFormattedText( fun createMarkdownText( - entities: List, + entities: FullTextSourcesList, partLength: Int = 4096 ): List = createFormattedText(entities, partLength, MarkdownParseMode) -fun List.toMarkdownCaptions(): List = createMarkdownText( +fun FullTextSourcesList.toMarkdownCaptions(): List = createMarkdownText( this, captionLength.last + 1 ) fun CaptionedInput.toMarkdownCaptions(): List = fullEntitiesList().toMarkdownCaptions() -fun List.toMarkdownTexts(): List = createMarkdownText( +fun FullTextSourcesList.toMarkdownTexts(): List = createMarkdownText( this, textLength.last + 1 ) fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() -fun List.toMarkdownExplanations(): List = createMarkdownText( +fun FullTextSourcesList.toMarkdownExplanations(): List = createMarkdownText( this, explanationLimit.last + 1 ) @@ -72,23 +72,23 @@ fun ExplainedInput.toMarkdownExplanations(): List = fullEntitiesList().t fun createMarkdownV2Text( - entities: List, + entities: FullTextSourcesList, partLength: Int = 4096 ): List = createFormattedText(entities, partLength, MarkdownV2ParseMode) -fun List.toMarkdownV2Captions(): List = createMarkdownV2Text( +fun FullTextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( this, captionLength.last + 1 ) fun CaptionedInput.toMarkdownV2Captions(): List = fullEntitiesList().toMarkdownV2Captions() -fun List.toMarkdownV2Texts(): List = createMarkdownV2Text( +fun FullTextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( this, textLength.last + 1 ) fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() -fun List.toMarkdownV2Explanations(): List = createMarkdownV2Text( +fun FullTextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( this, explanationLimit.last + 1 ) @@ -96,23 +96,23 @@ fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntitiesList() fun createHtmlText( - entities: List, + entities: FullTextSourcesList, partLength: Int = 4096 ): List = createFormattedText(entities, partLength, HTMLParseMode) -fun List.toHtmlCaptions(): List = createHtmlText( +fun FullTextSourcesList.toHtmlCaptions(): List = createHtmlText( this, captionLength.last + 1 ) fun CaptionedInput.toHtmlCaptions(): List = fullEntitiesList().toHtmlCaptions() -fun List.toHtmlTexts(): List = createHtmlText( +fun FullTextSourcesList.toHtmlTexts(): List = createHtmlText( this, textLength.last + 1 ) fun TextContent.toHtmlTexts(): List = fullEntitiesList().toHtmlTexts() -fun List.toHtmlExplanations(): List = createHtmlText( +fun FullTextSourcesList.toHtmlExplanations(): List = createHtmlText( this, explanationLimit.last + 1 )