From eb3f180cc6cd91f757c5cc41254cbbf1daa9461d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 27 Apr 2021 16:08:36 +0600 Subject: [PATCH] textSources now is main property --- CHANGELOG.md | 2 ++ .../inmo/tgbotapi/CommonAbstracts/Captioned.kt | 7 ------- .../dev/inmo/tgbotapi/CommonAbstracts/Texted.kt | 17 ++++++++--------- .../dev/inmo/tgbotapi/types/games/Game.kt | 2 +- .../dev/inmo/tgbotapi/types/games/RawGame.kt | 3 ++- .../inmo/tgbotapi/types/message/RawMessage.kt | 5 +++-- .../types/message/content/TextContent.kt | 2 +- .../message/content/media/AnimationContent.kt | 2 +- .../types/message/content/media/AudioContent.kt | 5 ++--- .../message/content/media/DocumentContent.kt | 4 ++-- .../types/message/content/media/PhotoContent.kt | 5 ++--- .../types/message/content/media/VideoContent.kt | 5 ++--- .../types/message/content/media/VoiceContent.kt | 2 +- 13 files changed, 27 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f7b08b50..1ac97f9341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * `SendInvoice#startParameter` becomes optional and replaced in `SendInvoice` constructor * Fields `SendInvoice#maxTipAmount` and `SendInvoice#suggestedTipAmounts` have been added * New type `InputInvoiceMessageContent` has been added + * `textSources` become main field in `TextedInput` + * `textEntities` become are calculable property in `TextedInput` ## 0.33.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index 1e3bfc3a08..7d5b10c30e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -20,10 +20,3 @@ interface CaptionedInput : Captioned, TextedInput { val captionEntities: List get() = textEntities } - -/** - * @see CaptionedInput.captionEntities - * @see justTextSources - */ -val CaptionedInput.textSources - get() = captionEntities.justTextSources() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt index 0b556444e5..1518631721 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.types.ParseMode.ParseMode interface Texted { @@ -17,19 +18,17 @@ interface EntitiesOutput : Texted { interface TextedOutput : ParsableOutput, EntitiesOutput interface TextedInput : Texted { + /** + * Full list of [TextSource] built from source[TextedInput.textEntities] + * + * @see justTextSources + */ + val textSources: List /** * Here must be full list of entities. This list must contains [TextPart]s with * [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] in case if source text contains parts of * regular text */ val textEntities: List + get() = textSources.toTextParts() } - -/** - * Full list of [TextSource] built from source[TextedInput.textEntities] - * - * @see TextedInput.textEntities - * @see justTextSources - */ -val TextedInput.textSources - get() = textEntities.justTextSources() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt index 104411f5f1..63c3c00241 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/Game.kt @@ -9,6 +9,6 @@ data class Game( val description: String, val photo: Photo, override val text: String? = null, - override val textEntities: List = emptyList(), + override val textSources: TextSourcesList = emptyList(), val animation: AnimationFile? = null ) : Titled, CaptionedInput, TextedInput diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt index 7861092005..cf2225cd3a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/games/RawGame.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.games +import dev.inmo.tgbotapi.CommonAbstracts.justTextSources import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntities import dev.inmo.tgbotapi.types.MessageEntity.asTextParts @@ -28,7 +29,7 @@ internal data class RawGame( description, photo, text, - text ?.let { _ -> textEntities.asTextParts(text) } ?: emptyList(), + text ?.let { _ -> textEntities.asTextParts(text).justTextSources() } ?: emptyList(), animation ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 4209fa119d..4c93700cd7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.message +import dev.inmo.tgbotapi.CommonAbstracts.justTextSources import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntities import dev.inmo.tgbotapi.types.MessageEntity.asTextParts @@ -102,11 +103,11 @@ internal data class RawMessage( ) { private val content: MessageContent? by lazy { val adaptedCaptionEntities = caption ?.let { - (caption_entities ?: emptyList()).asTextParts(caption) + (caption_entities ?: emptyList()).asTextParts(caption).justTextSources() } ?: emptyList() when { - text != null -> TextContent(text, (entities ?: emptyList()).asTextParts(text)) + text != null -> TextContent(text, (entities ?: emptyList()).asTextParts(text).justTextSources()) audio != null -> AudioContent( audio, caption, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index abc204e63e..d83ddd701b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -13,7 +13,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent data class TextContent( override val text: String, - override val textEntities: List = emptyList() + override val textSources: TextSourcesList = emptyList(), ) : MessageContent, TextedInput { override fun createResend( chatId: ChatIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index 411446772e..e1863bf213 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -16,7 +16,7 @@ data class AnimationContent( override val media: AnimationFile, val includedDocument: DocumentFile?, override val text: String?, - override val textEntities: List + override val textSources: TextSourcesList = emptyList() ) : MediaContent, CaptionedInput, TextedInput { override fun createResend( chatId: ChatIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index f72f68b065..83c17f8591 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextPart -import dev.inmo.tgbotapi.CommonAbstracts.textSources +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendAudio import dev.inmo.tgbotapi.types.ChatIdentifier @@ -16,7 +15,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent data class AudioContent( override val media: AudioFile, override val text: String? = null, - override val textEntities: List = emptyList() + override val textSources: TextSourcesList = emptyList() ) : AudioMediaGroupContent { override fun createResend( chatId: ChatIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index 9a9be3d0cb..9c4f3a7581 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -17,7 +17,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent data class DocumentContent( override val media: DocumentFile, override val text: String? = null, - override val textEntities: List = emptyList() + override val textSources: TextSourcesList = emptyList() ) : DocumentMediaGroupContent { override fun createResend( chatId: ChatIdentifier, @@ -46,7 +46,7 @@ inline fun MediaContent.asDocumentContent() = when (this) { is TextedInput -> DocumentContent( media.asDocumentFile(), text, - textEntities + textSources ) else -> DocumentContent( media.asDocumentFile() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index 95ee54ddd4..707ebcf29c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextPart -import dev.inmo.tgbotapi.CommonAbstracts.textSources +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendPhoto import dev.inmo.tgbotapi.types.ChatIdentifier @@ -17,7 +16,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent data class PhotoContent( override val mediaCollection: Photo, override val text: String? = null, - override val textEntities: List = emptyList() + override val textSources: TextSourcesList = emptyList() ) : MediaCollectionContent, VisualMediaGroupContent { override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index 86d794e3b4..717c5c01a1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.content.media -import dev.inmo.tgbotapi.CommonAbstracts.TextPart -import dev.inmo.tgbotapi.CommonAbstracts.textSources +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendVideo import dev.inmo.tgbotapi.types.ChatIdentifier @@ -16,7 +15,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent data class VideoContent( override val media: VideoFile, override val text: String? = null, - override val textEntities: List = emptyList() + override val textSources: TextSourcesList = emptyList() ) : VisualMediaGroupContent { override fun createResend( chatId: ChatIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 0c682a34a2..95e6340edf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -14,7 +14,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent data class VoiceContent( override val media: VoiceFile, override val text: String? = null, - override val textEntities: List = emptyList() + override val textSources: TextSourcesList = emptyList() ) : MediaContent, CaptionedInput, TextedInput { override fun createResend( chatId: ChatIdentifier,