From f3b05bbffd59f7c7c5f037065cdf459e2bdab52a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 7 Jan 2024 19:38:22 +0600 Subject: [PATCH] add support of external_reply in RawMessage --- .../kotlin/dev/inmo/tgbotapi/types/Contact.kt | 2 +- .../inmo/tgbotapi/types/ExternalReplyInfo.kt | 166 ----------------- .../dev/inmo/tgbotapi/types/ReplyInfo.kt | 175 ++++++++++++++++++ .../dev/inmo/tgbotapi/types/dice/Dice.kt | 2 +- .../tgbotapi/types/files/AnimationFile.kt | 2 +- .../inmo/tgbotapi/types/files/AudioFile.kt | 2 +- .../inmo/tgbotapi/types/files/DocumentFile.kt | 2 +- .../inmo/tgbotapi/types/files/PhotoSize.kt | 2 +- .../dev/inmo/tgbotapi/types/files/Sticker.kt | 2 +- .../inmo/tgbotapi/types/files/VideoFile.kt | 2 +- .../tgbotapi/types/files/VideoNoteFile.kt | 2 +- .../inmo/tgbotapi/types/files/VoiceFile.kt | 2 +- .../dev/inmo/tgbotapi/types/games/Game.kt | 4 +- .../types/giveaway/GiveawayPublicResults.kt | 2 +- .../types/giveaway/ScheduledGiveaway.kt | 2 +- .../inmo/tgbotapi/types/location/Location.kt | 2 +- .../message/ChannelContentMessageImpl.kt | 2 +- .../tgbotapi/types/message/GroupMessages.kt | 14 +- .../message/PrivateContentMessageImpl.kt | 2 +- .../inmo/tgbotapi/types/message/RawMessage.kt | 37 ++-- .../message/abstracts/PossiblyReplyMessage.kt | 4 + .../inmo/tgbotapi/types/payments/Invoice.kt | 2 +- .../dev/inmo/tgbotapi/types/polls/Poll.kt | 2 +- .../dev/inmo/tgbotapi/types/stories/Story.kt | 4 +- .../dev/inmo/tgbotapi/types/venue/Venue.kt | 2 +- .../MediaGroupContentMessageCreator.kt | 18 +- .../utils/extensions/raw/Message.kt | 2 +- 27 files changed, 241 insertions(+), 219 deletions(-) delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ExternalReplyInfo.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Contact.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Contact.kt index b84d4ed72a..8eaf9dfb84 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Contact.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Contact.kt @@ -16,4 +16,4 @@ data class Contact( val userId: UserId? = null, @SerialName(vcardField) override val vcard: String? = null -) : CommonContactData, ExternalReplyInfo.ContentVariant +) : CommonContactData, ReplyInfo.External.ContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ExternalReplyInfo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ExternalReplyInfo.kt deleted file mode 100644 index 7bf46b0d48..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ExternalReplyInfo.kt +++ /dev/null @@ -1,166 +0,0 @@ -package dev.inmo.tgbotapi.types - -import dev.inmo.tgbotapi.abstracts.SpoilerableData -import dev.inmo.tgbotapi.types.chat.SuperPublicChat -import dev.inmo.tgbotapi.types.dice.Dice -import dev.inmo.tgbotapi.types.files.* -import dev.inmo.tgbotapi.types.games.Game -import dev.inmo.tgbotapi.types.games.RawGame -import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults -import dev.inmo.tgbotapi.types.giveaway.ScheduledGiveaway -import dev.inmo.tgbotapi.types.location.Location -import dev.inmo.tgbotapi.types.message.MessageOrigin -import dev.inmo.tgbotapi.types.message.abstracts.Message -import dev.inmo.tgbotapi.types.payments.Invoice -import dev.inmo.tgbotapi.types.polls.Poll -import dev.inmo.tgbotapi.types.stories.Story -import dev.inmo.tgbotapi.types.venue.Venue -import dev.inmo.tgbotapi.utils.RiskFeature -import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded -import kotlinx.serialization.KSerializer -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder - -@Serializable(ExternalReplyInfo.Companion::class) -@ClassCastsIncluded -sealed interface ExternalReplyInfo { - val origin: MessageOrigin - val chat: SuperPublicChat? - val messageMeta: Message.MetaInfo? - - interface ContentVariant - - @Serializable - data class Text( - override val origin: MessageOrigin, - override val chat: SuperPublicChat?, - override val messageMeta: Message.MetaInfo?, - val linkPreviewOptions: LinkPreviewOptions? - ) : ExternalReplyInfo - - @Serializable(ExternalReplyInfo.Companion::class) - sealed interface Content : ExternalReplyInfo { - val content: ContentVariant - - - @Serializable - data class Simple( - override val origin: MessageOrigin, - override val chat: SuperPublicChat?, - override val messageMeta: Message.MetaInfo?, - override val content: ContentVariant - ) : Content - - @Serializable - data class Media( - override val origin: MessageOrigin, - override val chat: SuperPublicChat?, - override val messageMeta: Message.MetaInfo?, - override val spoilered: Boolean, - override val content: T - ) : Content, SpoilerableData where T: ContentVariant, T : TelegramMediaFile - } - - @Serializable - private data class Surrogate( - val origin: MessageOrigin, - val chat: SuperPublicChat? = null, - val message_id: MessageId? = null, - val link_preview_options: LinkPreviewOptions? = null, - val has_media_spoiler: Boolean? = null, - private val story: Story? = null, - private val audio: AudioFile? = null, - private val document: DocumentFile? = null, - private val animation: AnimationFile? = null, - private val game: RawGame? = null, - @Serializable(PhotoSerializer::class) - private val photo: Photo? = null, - private val sticker: Sticker? = null, - private val video: VideoFile? = null, - private val voice: VoiceFile? = null, - private val video_note: VideoNoteFile? = null, - private val contact: Contact? = null, - private val location: Location? = null, - private val venue: Venue? = null, - private val poll: Poll? = null, - private val invoice: Invoice? = null, - private val dice: Dice? = null, - private val giveaway: ScheduledGiveaway? = null, - private val giveaway_winners: GiveawayPublicResults? = null, - ) { - val asExternalReplyInfo: ExternalReplyInfo - get() { - val messageMeta = chat ?.let { - message_id ?.let { - Message.MetaInfo( - chat.id, - message_id - ) - } - } - val content: ContentVariant? = when { - story != null -> story - audio != null -> audio - video != null -> video - video_note != null -> video_note - animation != null -> animation - document != null -> document - voice != null -> voice - photo != null -> photo - sticker != null -> sticker - dice != null -> dice - game != null -> game.asGame - contact != null -> contact - location != null -> location - venue != null -> venue - poll != null -> poll - invoice != null -> invoice - giveaway != null -> giveaway - giveaway_winners != null -> giveaway_winners - else -> null - } - - return content ?.let { - when (it) { - is TelegramMediaFile -> { - Content.Media( - origin, - chat, - messageMeta, - has_media_spoiler == true, - it - ) - } - else -> Content.Simple( - origin, - chat, - messageMeta, - it - ) - } - } ?: Text( - origin, - chat, - messageMeta, - link_preview_options - ) - } - } - - @RiskFeature("This serializer currently support only deserialization, but not serialization") - companion object : KSerializer { - override val descriptor: SerialDescriptor - get() = Surrogate.serializer().descriptor - - override fun deserialize(decoder: Decoder): ExternalReplyInfo { - return Surrogate.serializer().deserialize(decoder).asExternalReplyInfo - } - - override fun serialize(encoder: Encoder, value: ExternalReplyInfo) { - - } - } -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt new file mode 100644 index 0000000000..4045b5117a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyInfo.kt @@ -0,0 +1,175 @@ +package dev.inmo.tgbotapi.types + +import dev.inmo.tgbotapi.abstracts.SpoilerableData +import dev.inmo.tgbotapi.types.chat.SuperPublicChat +import dev.inmo.tgbotapi.types.dice.Dice +import dev.inmo.tgbotapi.types.files.* +import dev.inmo.tgbotapi.types.games.RawGame +import dev.inmo.tgbotapi.types.giveaway.GiveawayPublicResults +import dev.inmo.tgbotapi.types.giveaway.ScheduledGiveaway +import dev.inmo.tgbotapi.types.location.Location +import dev.inmo.tgbotapi.types.message.MessageOrigin +import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.payments.Invoice +import dev.inmo.tgbotapi.types.polls.Poll +import dev.inmo.tgbotapi.types.stories.Story +import dev.inmo.tgbotapi.types.venue.Venue +import dev.inmo.tgbotapi.utils.RiskFeature +import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@ClassCastsIncluded +sealed interface ReplyInfo { + val messageMeta: Message.MetaInfo? + + data class Internal( + val message: AccessibleMessage + ): ReplyInfo { + override val messageMeta: Message.MetaInfo + get() = message.metaInfo + } + + @Serializable(External.Companion::class) + sealed interface External : ReplyInfo { + val origin: MessageOrigin + val chat: SuperPublicChat? + + interface ContentVariant + + @Serializable + data class Text( + override val origin: MessageOrigin, + override val chat: SuperPublicChat?, + override val messageMeta: Message.MetaInfo?, + val linkPreviewOptions: LinkPreviewOptions? + ) : External + + @Serializable(External.Companion::class) + sealed interface Content : External { + val content: ContentVariant + + + @Serializable + data class Simple( + override val origin: MessageOrigin, + override val chat: SuperPublicChat?, + override val messageMeta: Message.MetaInfo?, + override val content: ContentVariant + ) : Content + + @Serializable + data class Media( + override val origin: MessageOrigin, + override val chat: SuperPublicChat?, + override val messageMeta: Message.MetaInfo?, + override val spoilered: Boolean, + override val content: T + ) : Content, SpoilerableData where T: ContentVariant, T : TelegramMediaFile + } + + @Serializable + private data class Surrogate( + val origin: MessageOrigin, + val chat: SuperPublicChat? = null, + val message_id: MessageId? = null, + val link_preview_options: LinkPreviewOptions? = null, + val has_media_spoiler: Boolean? = null, + private val story: Story? = null, + private val audio: AudioFile? = null, + private val document: DocumentFile? = null, + private val animation: AnimationFile? = null, + private val game: RawGame? = null, + @Serializable(PhotoSerializer::class) + private val photo: Photo? = null, + private val sticker: Sticker? = null, + private val video: VideoFile? = null, + private val voice: VoiceFile? = null, + private val video_note: VideoNoteFile? = null, + private val contact: Contact? = null, + private val location: Location? = null, + private val venue: Venue? = null, + private val poll: Poll? = null, + private val invoice: Invoice? = null, + private val dice: Dice? = null, + private val giveaway: ScheduledGiveaway? = null, + private val giveaway_winners: GiveawayPublicResults? = null, + ) { + val asExternalReplyInfo: External + get() { + val messageMeta = chat ?.let { + message_id ?.let { + Message.MetaInfo( + chat.id, + message_id + ) + } + } + val content: ContentVariant? = when { + story != null -> story + audio != null -> audio + video != null -> video + video_note != null -> video_note + animation != null -> animation + document != null -> document + voice != null -> voice + photo != null -> photo + sticker != null -> sticker + dice != null -> dice + game != null -> game.asGame + contact != null -> contact + location != null -> location + venue != null -> venue + poll != null -> poll + invoice != null -> invoice + giveaway != null -> giveaway + giveaway_winners != null -> giveaway_winners + else -> null + } + + return content ?.let { + when (it) { + is TelegramMediaFile -> { + Content.Media( + origin, + chat, + messageMeta, + has_media_spoiler == true, + it + ) + } + else -> Content.Simple( + origin, + chat, + messageMeta, + it + ) + } + } ?: Text( + origin, + chat, + messageMeta, + link_preview_options + ) + } + } + + @RiskFeature("This serializer currently support only deserialization, but not serialization") + companion object : KSerializer { + override val descriptor: SerialDescriptor + get() = Surrogate.serializer().descriptor + + override fun deserialize(decoder: Decoder): External { + return Surrogate.serializer().deserialize(decoder).asExternalReplyInfo + } + + override fun serialize(encoder: Encoder, value: External) { + + } + } + } +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/Dice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/Dice.kt index c5a70ff3f3..719e7a3337 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/Dice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/Dice.kt @@ -10,4 +10,4 @@ data class Dice( val value: DiceResult, @SerialName(emojiField) val animationType: DiceAnimationType -) : ExternalReplyInfo.ContentVariant +) : ReplyInfo.External.ContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt index d09fbcbe79..cff7534719 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AnimationFile.kt @@ -24,4 +24,4 @@ data class AnimationFile( @SerialName(fileSizeField) override val fileSize: Long? = null ) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, CustomNamedMediaFile, SizedMediaFile, - ExternalReplyInfo.ContentVariant + ReplyInfo.External.ContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt index c83351dc25..5996f41bb3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt @@ -28,6 +28,6 @@ data class AudioFile( @SerialName(thumbnailField) override val thumbnail: PhotoSize? = null ) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, - Performerable, ExternalReplyInfo.ContentVariant + Performerable, ReplyInfo.External.ContentVariant fun AudioFile.asVoiceFile() = VoiceFile(fileId, fileUniqueId, duration, mimeType, fileSize) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt index 73df323628..a5a0676543 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/DocumentFile.kt @@ -20,7 +20,7 @@ data class DocumentFile( override val mimeType: MimeType? = null, @SerialName(fileNameField) override val fileName: String? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile, ExternalReplyInfo.ContentVariant +) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile, ReplyInfo.External.ContentVariant @Suppress("NOTHING_TO_INLINE") inline fun TelegramMediaFile.asDocumentFile() = if (this is DocumentFile) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt index 39bd5c42cf..fdac2d0e5f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/PhotoSize.kt @@ -12,7 +12,7 @@ import kotlin.jvm.JvmInline @JvmInline value class Photo( val photos: List -) : List by photos, ExternalReplyInfo.ContentVariant +) : List by photos, ReplyInfo.External.ContentVariant fun Photo.biggest(): PhotoSize? = maxByOrNull { it.resolution diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt index 4355de3241..199bae6c9b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt @@ -34,7 +34,7 @@ data class StickerSurrogate( // TODO:: Serializer @Serializable(StickerSerializer::class) -sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile, ExternalReplyInfo.ContentVariant { +sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile, ReplyInfo.External.ContentVariant { val emoji: String? val stickerSetName: StickerSetName? val stickerFormat: StickerFormat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index 5eec4d48a7..5ab993cb56 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -30,7 +30,7 @@ data class VideoFile( @SerialName(fileSizeField) override val fileSize: Long? = null ) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, - ExternalReplyInfo.ContentVariant + ReplyInfo.External.ContentVariant @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toTelegramMediaVideo( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt index 49b5ec8889..f93debfb83 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoNoteFile.kt @@ -18,7 +18,7 @@ data class VideoNoteFile( override val thumbnail: PhotoSize? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, ExternalReplyInfo.ContentVariant { +) : TelegramMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile, ReplyInfo.External.ContentVariant { override val height: Int get() = width } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt index 725a52a0ed..b26631c800 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt @@ -19,7 +19,7 @@ data class VoiceFile( override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile, ExternalReplyInfo.ContentVariant +) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile, ReplyInfo.External.ContentVariant fun VoiceFile.asAudioFile( performer: String? = null, 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 60027bc169..c2e9d15275 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 @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.games import dev.inmo.tgbotapi.abstracts.TextedInput import dev.inmo.tgbotapi.abstracts.Titled -import dev.inmo.tgbotapi.types.ExternalReplyInfo +import dev.inmo.tgbotapi.types.ReplyInfo import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.Photo @@ -16,4 +16,4 @@ data class Game( override val text: String? = null, override val textSources: TextSourcesList = emptyList(), val animation: AnimationFile? = null -) : Titled, TextedInput, ExternalReplyInfo.ContentVariant +) : Titled, TextedInput, ReplyInfo.External.ContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPublicResults.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPublicResults.kt index 83fe74fa2f..192e2521b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPublicResults.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/GiveawayPublicResults.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.encoding.Encoder @Serializable(GiveawayPublicResults.Companion::class) sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPreviewChatAndMessageId, - ExternalReplyInfo.ContentVariant { + ReplyInfo.External.ContentVariant { val count: Int val winners: List val additionalChats: Int diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/ScheduledGiveaway.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/ScheduledGiveaway.kt index 317a83287e..ce7c3430bd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/ScheduledGiveaway.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/giveaway/ScheduledGiveaway.kt @@ -30,4 +30,4 @@ data class ScheduledGiveaway( val countries: List? = null, @SerialName(premiumSubscriptionMonthCountField) override val premiumMonths: Int? = null -) : GiveawayInfo, ExternalReplyInfo.ContentVariant \ No newline at end of file +) : GiveawayInfo, ReplyInfo.External.ContentVariant \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt index 149f04c533..37fed8e9a6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt @@ -20,7 +20,7 @@ import kotlinx.serialization.json.JsonObject */ @Serializable(LocationSerializer::class) @ClassCastsIncluded -sealed interface Location : Locationed, HorizontallyAccured, ExternalReplyInfo.ContentVariant +sealed interface Location : Locationed, HorizontallyAccured, ReplyInfo.External.ContentVariant @Serializable data class StaticLocation( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt index bfe6234525..f76af91f66 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelContentMessageImpl.kt @@ -16,7 +16,7 @@ data class ChannelContentMessageImpl( override val editDate: DateTime?, override val hasProtectedContent: Boolean, override val forwardOrigin: MessageOrigin?, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, override val authorSignature: AuthorSignature?, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt index bfa54b8c1f..967f87d4df 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -17,7 +17,7 @@ data class ConnectedFromChannelGroupContentMessageImpl( override val forwardOrigin: MessageOrigin?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -52,7 +52,7 @@ data class UnconnectedFromChannelGroupContentMessageImpl( override val forwardOrigin: MessageOrigin?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -85,7 +85,7 @@ data class AnonymousGroupContentMessageImpl( override val forwardOrigin: MessageOrigin?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -118,7 +118,7 @@ data class CommonGroupContentMessageImpl( override val forwardOrigin: MessageOrigin?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -151,7 +151,7 @@ data class FromChannelForumContentMessageImpl( override val forwardOrigin: MessageOrigin?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -186,7 +186,7 @@ data class AnonymousForumContentMessageImpl( override val forwardOrigin: MessageOrigin?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, @@ -221,7 +221,7 @@ data class CommonForumContentMessageImpl( override val forwardOrigin: MessageOrigin?, override val editDate: DateTime?, override val hasProtectedContent: Boolean, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt index 21438aea84..a2482308df 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt @@ -19,7 +19,7 @@ data class PrivateContentMessageImpl( override val editDate: DateTime?, override val hasProtectedContent: Boolean, override val forwardOrigin: MessageOrigin?, - override val replyTo: AccessibleMessage?, + override val replyInfo: ReplyInfo?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, override val mediaGroupId: MediaGroupIdentifier?, 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 087df83da7..dd05df6535 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 @@ -54,6 +54,7 @@ internal data class RawMessage( private val is_topic_message: Boolean? = null, private val is_automatic_forward: Boolean? = null, private val reply_to_message: RawMessage? = null, + private val external_reply: ReplyInfo.External? = null, private val via_bot: CommonBot? = null, private val edit_date: TelegramDate? = null, private val has_protected_content: Boolean? = null, @@ -282,7 +283,15 @@ internal data class RawMessage( ) else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)") } - } ?: content?.let { content -> when (chat) { + } ?: content?.let { content -> + val replyInfo: ReplyInfo? = when { + reply_to_message != null -> ReplyInfo.Internal( + reply_to_message.asMessage + ) + external_reply != null -> external_reply + else -> null + } + when (chat) { is PreviewPublicChat -> when (chat) { is PreviewChannelChat -> ChannelContentMessageImpl( messageId, @@ -292,7 +301,7 @@ internal data class RawMessage( edit_date?.asDate, has_protected_content == true, forward_origin, - reply_to_message?.asMessage, + replyInfo, reply_markup, via_bot, author_signature, @@ -316,7 +325,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -331,7 +340,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -347,7 +356,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -365,7 +374,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -381,7 +390,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -396,7 +405,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -411,7 +420,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -429,7 +438,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -445,7 +454,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -460,7 +469,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -475,7 +484,7 @@ internal data class RawMessage( forward_origin, edit_date ?.asDate, has_protected_content == true, - reply_to_message ?.asMessage, + replyInfo, reply_markup, content, via_bot, @@ -492,7 +501,7 @@ internal data class RawMessage( edit_date?.asDate, has_protected_content == true, forward_origin, - reply_to_message?.asMessage, + replyInfo, reply_markup, via_bot, media_group_id diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt index d796c09520..7a59546392 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PossiblyReplyMessage.kt @@ -1,5 +1,9 @@ package dev.inmo.tgbotapi.types.message.abstracts +import dev.inmo.tgbotapi.types.ReplyInfo + interface PossiblyReplyMessage { + val replyInfo: ReplyInfo? val replyTo: AccessibleMessage? + get() = (replyInfo as? ReplyInfo.Internal) ?.message } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/Invoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/Invoice.kt index cd10c9f0f1..3d1e848337 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/Invoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/Invoice.kt @@ -17,4 +17,4 @@ data class Invoice( override val currency: Currency, @SerialName(totalAmountField) override val amount: Long -) : Amounted, Currencied, ExternalReplyInfo.ContentVariant +) : Amounted, Currencied, ReplyInfo.External.ContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt index 183a65abdc..182e379dd9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt @@ -49,7 +49,7 @@ val LongSeconds.asExactScheduledCloseInfo @Serializable(PollSerializer::class) @ClassCastsIncluded -sealed interface Poll : ExternalReplyInfo.ContentVariant { +sealed interface Poll : ReplyInfo.External.ContentVariant { val id: PollIdentifier val question: String val options: List diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt index c17452cf3a..35154fd101 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stories/Story.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types.stories -import dev.inmo.tgbotapi.types.ExternalReplyInfo +import dev.inmo.tgbotapi.types.ReplyInfo import kotlinx.serialization.Serializable @Serializable -class Story : ExternalReplyInfo.ContentVariant +class Story : ReplyInfo.External.ContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt index 5dc5b71a3e..0a109e51a4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt @@ -23,4 +23,4 @@ data class Venue( override val googlePlaceId: GooglePlaceId? = null, @SerialName(googlePlaceTypeField) override val googlePlaceType: GooglePlaceType? = null -) : CommonVenueData, Locationed by location, ExternalReplyInfo.ContentVariant +) : CommonVenueData, Locationed by location, ReplyInfo.External.ContentVariant diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt index 5ed0e6f3af..f8764c212f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/MediaGroupContentMessageCreator.kt @@ -40,7 +40,7 @@ fun List>.asMedia sourceMessage.editDate, sourceMessage.hasProtectedContent, sourceMessage.forwardOrigin, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, sourceMessage.senderBot, sourceMessage.authorSignature, @@ -55,7 +55,7 @@ fun List>.asMedia sourceMessage.editDate, sourceMessage.hasProtectedContent, sourceMessage.forwardOrigin, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, sourceMessage.senderBot, sourceMessage.mediaGroupId @@ -67,7 +67,7 @@ fun List>.asMedia sourceMessage.forwardOrigin, sourceMessage.editDate, sourceMessage.hasProtectedContent, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, content, sourceMessage.senderBot, @@ -82,7 +82,7 @@ fun List>.asMedia sourceMessage.forwardOrigin, sourceMessage.editDate, sourceMessage.hasProtectedContent, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, content, sourceMessage.senderBot, @@ -96,7 +96,7 @@ fun List>.asMedia sourceMessage.forwardOrigin, sourceMessage.editDate, sourceMessage.hasProtectedContent, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, content, sourceMessage.senderBot, @@ -111,7 +111,7 @@ fun List>.asMedia sourceMessage.forwardOrigin, sourceMessage.editDate, sourceMessage.hasProtectedContent, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, content, sourceMessage.senderBot, @@ -126,7 +126,7 @@ fun List>.asMedia sourceMessage.forwardOrigin, sourceMessage.editDate, sourceMessage.hasProtectedContent, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, content, sourceMessage.senderBot, @@ -142,7 +142,7 @@ fun List>.asMedia sourceMessage.forwardOrigin, sourceMessage.editDate, sourceMessage.hasProtectedContent, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, content, sourceMessage.senderBot, @@ -157,7 +157,7 @@ fun List>.asMedia sourceMessage.forwardOrigin, sourceMessage.editDate, sourceMessage.hasProtectedContent, - sourceMessage.replyTo, + sourceMessage.replyInfo, sourceMessage.replyMarkup, content, sourceMessage.senderBot, diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt index 9b65ae7a90..0874d13255 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt @@ -51,7 +51,7 @@ inline val AccessibleMessage.is_automatic_forward: Boolean? get() = this is ConnectedFromChannelGroupContentMessage<*> @RiskFeature(RawFieldsUsageWarning) inline val AccessibleMessage.reply_to_message: AccessibleMessage? - get() = asPossiblyReplyMessage() ?.replyTo + get() = asPossiblyReplyMessage() ?.replyInfo @RiskFeature(RawFieldsUsageWarning) inline val AccessibleMessage.via_bot: CommonBot? get() = asPossiblySentViaBotCommonMessage() ?.senderBot