diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt index a690f6e71b..817ff9ba0c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -13,8 +13,6 @@ import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import kotlinx.serialization.* -private val ResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass>() - fun CopyMessage( fromChatId: ChatIdentifier, toChatId: ChatIdentifier, @@ -60,8 +58,8 @@ data class CopyMessage internal constructor( override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null -): SimpleRequest>, - ReplyingMarkupSendMessageRequest>, +): SimpleRequest, + ReplyingMarkupSendMessageRequest, MessageAction, TextedOutput { override val chatId: ChatIdentifier @@ -72,8 +70,8 @@ data class CopyMessage internal constructor( override fun method(): String = "copyMessage" - override val resultDeserializer: DeserializationStrategy> - get() = ResultDeserializer + override val resultDeserializer: DeserializationStrategy + get() = MessageIdSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index 610a384682..a91ee59882 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -84,22 +84,23 @@ internal fun createTextPart(from: String, entities: RawMessageEntities): List.asRawMessageEntities(): List = mapNotNull { val source = it.source + val length = it.range.last - it.range.first + 1 when (source) { - is MentionTextSource -> RawMessageEntity("mention", it.range.first, it.range.last - it.range.first) - is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, it.range.last - it.range.first) - is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, it.range.last - it.range.first) - is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, it.range.last - it.range.first) - is URLTextSource -> RawMessageEntity("url", it.range.first, it.range.last - it.range.first) - is EMailTextSource -> RawMessageEntity("email", it.range.first, it.range.last - it.range.first) - is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, it.range.last - it.range.first) - is BoldTextSource -> RawMessageEntity("bold", it.range.first, it.range.last - it.range.first) - is ItalicTextSource -> RawMessageEntity("italic", it.range.first, it.range.last - it.range.first) - is CodeTextSource -> RawMessageEntity("code", it.range.first, it.range.last - it.range.first) - is PreTextSource -> RawMessageEntity("pre", it.range.first, it.range.last - it.range.first, language = source.language) - is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, it.range.last - it.range.first, source.url) - is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, it.range.last - it.range.first, user = source.user) - is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, it.range.last - it.range.first) - is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, it.range.last - it.range.first) + is MentionTextSource -> RawMessageEntity("mention", it.range.first, length) + is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, length) + is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, length) + is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, length) + is URLTextSource -> RawMessageEntity("url", it.range.first, length) + is EMailTextSource -> RawMessageEntity("email", it.range.first, length) + is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, length) + is BoldTextSource -> RawMessageEntity("bold", it.range.first, length) + is ItalicTextSource -> RawMessageEntity("italic", it.range.first, length) + is CodeTextSource -> RawMessageEntity("code", it.range.first, length) + is PreTextSource -> RawMessageEntity("pre", it.range.first, length, language = source.language) + is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, length, source.url) + is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, length, user = source.user) + is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, length) + is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, length) else -> null } } @@ -108,7 +109,7 @@ internal fun List.toRawMessageEntities(): List { var i = 0 return map { TextPart( - i until it.source.length, + i until (i + it.source.length), it ).also { i = it.range.last + 1 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt new file mode 100644 index 0000000000..d8c73228f7 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt @@ -0,0 +1,24 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.* + +object MessageIdSerializer : KSerializer { + override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor + + override fun deserialize(decoder: Decoder): MessageIdentifier = JsonObject.serializer().deserialize(decoder)[messageIdField]!!.jsonPrimitive.long + + override fun serialize(encoder: Encoder, value: MessageIdentifier) { + JsonObject.serializer().serialize( + encoder, + JsonObject( + mapOf( + messageIdField to JsonPrimitive(value) + ) + ) + ) + } +} 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 f9aa545c75..55504c97e8 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 @@ -22,6 +22,7 @@ import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.payments.SuccessfulPayment import dev.inmo.tgbotapi.types.polls.Poll import dev.inmo.tgbotapi.types.venue.Venue +import dev.inmo.tgbotapi.utils.fullListOfSubSource import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass @@ -91,11 +92,11 @@ internal data class RawMessage( ) { private val content: MessageContent? by lazy { val adaptedCaptionEntities = caption ?.let { - caption_entities ?.asTextParts(caption) + it.fullListOfSubSource(caption_entities ?.asTextParts(caption) ?: emptyList()) } ?: emptyList() when { - text != null -> TextContent(text, entities ?.asTextParts(text) ?: emptyList()) + text != null -> TextContent(text, text.fullListOfSubSource(entities ?.asTextParts(text) ?: emptyList())) audio != null -> AudioContent( audio, caption,