From 86885e7698523db753c2f915b6dd8f5425c13b10 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 2 Jan 2022 01:49:14 +0600 Subject: [PATCH] updates in CommonMessage implementers and removing of deprecations --- CHANGELOG.md | 19 +++++- .../message/ChannelContentMessageImpl.kt | 18 +----- .../types/message/ChannelMediaGroupMessage.kt | 17 +----- .../types/message/CommonMediaGroupMessage.kt | 18 +----- .../tgbotapi/types/message/GroupMessages.kt | 60 +++---------------- ...geImpl.kt => PrivateContentMessageImpl.kt} | 18 +----- .../inmo/tgbotapi/types/message/RawMessage.kt | 16 ++--- .../types/message/abstracts/ContentMessage.kt | 6 +- 8 files changed, 44 insertions(+), 128 deletions(-) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/{PrivateMessageImpl.kt => PrivateContentMessageImpl.kt} (60%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6acce49db2..f13da02baa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ # TelegramBotAPI changelog - ## 0.38.0 +_This update contains [Telegram Bot API 5.6](https://core.telegram.org/bots/api-changelog#december-30-2021) implementation_ + +_This update contains migration onto Kotlin 1.6_ + +_This update has changed constructors of all `CommonMessage` implementations_ + + * `Common`: * `Version`: * `Kotlin`: `1.5.31` -> `1.6.10` @@ -15,6 +21,17 @@ * Add `SpoilerTextSource` (as part of `Telegram Bot API 5.6` update) * Add support of `protect_content` as a field `protectContent` in all send message requests and parameter in all functions related to that requests (as part of `Telegram Bot API 5.6` update) + * **ALL IMPLEMENTERS OF `CommonMessage` HAS CHANGED THEIR CONSTRUCTOR: NOW THEY GET `hasProtectedContent` instead of + `forwardable` (inversed) field** + * `ChannelContentMessageImpl` + * `ChannelMediaGroupMessage` + * `CommonMediaGroupMessage` + * `GroupContentMessage` implementers + * `ConnectedFromChannelGroupContentMessageImpl` + * `UnconnectedFromChannelGroupContentMessageImpl` + * `AnonymousGroupContentMessageImpl` + * `CommonGroupContentMessageImpl` + * `PrivateContentMessageImpl` ## 0.37.4 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 64f01f45bd..5156037aad 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 @@ -13,24 +13,10 @@ data class ChannelContentMessageImpl( override val content: T, override val date: DateTime, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, override val authorSignature: AuthorSignature? -) : ChannelContentMessage { - @Deprecated("Use the constructor with forwardable field") - constructor( - messageId: MessageIdentifier, - chat: ChannelChat, - content: T, - date: DateTime, - editDate: DateTime?, - forwardInfo: ForwardInfo?, - replyTo: Message?, - replyMarkup: InlineKeyboardMarkup?, - senderBot: CommonBot?, - authorSignature: AuthorSignature? - ) : this(messageId, chat, content, date, editDate, true, forwardInfo, replyTo, replyMarkup, senderBot, authorSignature) -} +) : ChannelContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt index 2bcad5e3ac..36e9a1bfb5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt @@ -16,21 +16,8 @@ data class ChannelMediaGroupMessage( override val mediaGroupId: MediaGroupIdentifier, override val content: T, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup? -) : MediaGroupMessage { - @Deprecated("Use the constructor with forwardable field") - constructor( - messageId: MessageIdentifier, - chat: Chat, - date: DateTime, - mediaGroupId: MediaGroupIdentifier, - content: T, - editDate: DateTime?, - forwardInfo: ForwardInfo?, - replyTo: Message?, - replyMarkup: InlineKeyboardMarkup? - ) : this(messageId, chat, date, mediaGroupId, content, editDate, true, forwardInfo, replyTo, replyMarkup) -} +) : MediaGroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt index af08de46f1..cdaa34a5a5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt @@ -15,22 +15,8 @@ data class CommonMediaGroupMessage( override val mediaGroupId: MediaGroupIdentifier, override val content: T, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup? -) : MediaGroupMessage, FromUserMessage { - @Deprecated("Use the constructor with forwardable field") - constructor( - messageId: MessageIdentifier, - from: User, - chat: Chat, - date: DateTime, - mediaGroupId: MediaGroupIdentifier, - content: T, - editDate: DateTime?, - forwardInfo: ForwardInfo?, - replyTo: Message?, - replyMarkup: InlineKeyboardMarkup? - ) : this(messageId, from, chat, date, mediaGroupId, content, editDate, true, forwardInfo, replyTo, replyMarkup) -} +) : MediaGroupMessage, FromUserMessage 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 15439bb763..a558cef304 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 @@ -15,31 +15,13 @@ data class ConnectedFromChannelGroupContentMessageImpl( override val date: DateTime, override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, override val authorSignature: AuthorSignature? -) : ConnectedFromChannelGroupContentMessage { - @Deprecated("Use the constructor with forwardable field") - constructor( - chat: GroupChat, - channel: ChannelChat, - messageId: MessageIdentifier, - date: DateTime, - forwardInfo: ForwardInfo?, - editDate: DateTime?, - replyTo: Message?, - replyMarkup: InlineKeyboardMarkup?, - content: T, - senderBot: CommonBot?, - authorSignature: AuthorSignature? - ) : this(chat, channel, messageId, date, forwardInfo, editDate, true, replyTo, replyMarkup, content, senderBot, authorSignature) -} - -@Deprecated("Renamed", ReplaceWith("ConnectedFromChannelGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.ConnectedFromChannelGroupContentMessageImpl")) -typealias FromChannelGroupContentMessageImpl = ConnectedFromChannelGroupContentMessageImpl +) : ConnectedFromChannelGroupContentMessage data class UnconnectedFromChannelGroupContentMessageImpl( override val chat: GroupChat, @@ -48,7 +30,7 @@ data class UnconnectedFromChannelGroupContentMessageImpl( override val date: DateTime, override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, @@ -62,27 +44,13 @@ data class AnonymousGroupContentMessageImpl( override val date: DateTime, override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot?, override val authorSignature: AuthorSignature? -) : AnonymousGroupContentMessage { - @Deprecated("Use the constructor with forwardable field") - constructor( - chat: GroupChat, - messageId: MessageIdentifier, - date: DateTime, - forwardInfo: ForwardInfo?, - editDate: DateTime?, - replyTo: Message?, - replyMarkup: InlineKeyboardMarkup?, - content: T, - senderBot: CommonBot?, - authorSignature: AuthorSignature? - ) : this(chat, messageId, date, forwardInfo, editDate, true, replyTo, replyMarkup, content, senderBot, authorSignature) -} +) : AnonymousGroupContentMessage data class CommonGroupContentMessageImpl( override val chat: GroupChat, @@ -91,23 +59,9 @@ data class CommonGroupContentMessageImpl( override val date: DateTime, override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val content: T, override val senderBot: CommonBot? -) : CommonGroupContentMessage { - @Deprecated("Use the constructor with forwardable field") - constructor( - chat: GroupChat, - messageId: MessageIdentifier, - from: User, - date: DateTime, - forwardInfo: ForwardInfo?, - editDate: DateTime?, - replyTo: Message?, - replyMarkup: InlineKeyboardMarkup?, - content: T, - senderBot: CommonBot? - ) : this(chat, messageId, from, date, forwardInfo, editDate, true, replyTo, replyMarkup, content, senderBot) -} +) : CommonGroupContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt similarity index 60% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt index 00699bcfc9..c53a8d2857 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateContentMessageImpl.kt @@ -15,23 +15,9 @@ data class PrivateContentMessageImpl( override val content: T, override val date: DateTime, override val editDate: DateTime?, - override val forwardable: Boolean, + override val hasProtectedContent: Boolean, override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot? -) : PrivateContentMessage { - @Deprecated("Use the constructor with forwardable field") - constructor( - messageId: MessageIdentifier, - from: User, - chat: Chat, - content: T, - date: DateTime, - editDate: DateTime?, - forwardInfo: ForwardInfo?, - replyTo: Message?, - replyMarkup: InlineKeyboardMarkup?, - senderBot: CommonBot? - ) : this(messageId, from, chat, content, date, editDate, true, forwardInfo, replyTo, replyMarkup, senderBot) -} +) : PrivateContentMessage 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 c0fcc5334b..e823db8cc2 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 @@ -254,7 +254,7 @@ internal data class RawMessage( it, checkedContent, edit_date?.asDate, - has_protected_content != true, + has_protected_content == true, forwarded, reply_to_message?.asMessage, reply_markup @@ -267,7 +267,7 @@ internal data class RawMessage( it, checkedContent, edit_date?.asDate, - has_protected_content != true, + has_protected_content == true, forwarded, reply_to_message?.asMessage, reply_markup @@ -281,7 +281,7 @@ internal data class RawMessage( content, date.asDate, edit_date?.asDate, - has_protected_content != true, + has_protected_content == true, forwarded, reply_to_message?.asMessage, reply_markup, @@ -297,7 +297,7 @@ internal data class RawMessage( date.asDate, forwarded, edit_date ?.asDate, - has_protected_content != true, + has_protected_content == true, reply_to_message ?.asMessage, reply_markup, content, @@ -312,7 +312,7 @@ internal data class RawMessage( date.asDate, forwarded, edit_date ?.asDate, - has_protected_content != true, + has_protected_content == true, reply_to_message ?.asMessage, reply_markup, content, @@ -326,7 +326,7 @@ internal data class RawMessage( date.asDate, forwarded, edit_date ?.asDate, - has_protected_content != true, + has_protected_content == true, reply_to_message ?.asMessage, reply_markup, content, @@ -340,7 +340,7 @@ internal data class RawMessage( date.asDate, forwarded, edit_date ?.asDate, - has_protected_content != true, + has_protected_content == true, reply_to_message ?.asMessage, reply_markup, content, @@ -357,7 +357,7 @@ internal data class RawMessage( content, date.asDate, edit_date?.asDate, - has_protected_content != true, + has_protected_content == true, forwarded, reply_to_message?.asMessage, reply_markup, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt index b27e7ab9ef..b155bad5ec 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ContentMessage.kt @@ -3,9 +3,9 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent interface ContentMessage: Message { - val forwardable: Boolean + val hasProtectedContent: Boolean val content: T - val hasProtectedContent: Boolean - get() = !forwardable + val forwardable: Boolean + get() = !hasProtectedContent }