1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

AbleToBe -> Possibly and ForwardedMessage -> ForwardInfo

This commit is contained in:
InsanusMokrassar 2020-01-15 12:52:52 +06:00
parent e3117f3679
commit 3fe7bd1382
17 changed files with 103 additions and 57 deletions

View File

@ -4,6 +4,16 @@
* **`KtorCallFactory` must return `HttpStatement` instead of `HttpClientCall`** * **`KtorCallFactory` must return `HttpStatement` instead of `HttpClientCall`**
* `SendMessage` was renamed to `SendTextMessage` and previous `SendMessage` is deprecated * `SendMessage` was renamed to `SendTextMessage` and previous `SendMessage` is deprecated
* All `AbleToBe*` interfaces was renamed to `Possibly*`
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
* `AbleToBeForwardedMessage` -> `PossiblyForwardedMessage`
* `AbleToBeMarkedUp` -> `PossiblyMarkedUp`
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
* `ForwardedMessage` type was renamed to `ForwardInfo`
* `AnonymousForwardedMessage` -> `AnonymousForwardInfo`
* `UserForwardedMessage` -> `UserForwardInfo`
* `ForwardedFromChannelMessage` -> `ForwardFromChannelInfo`
* `PossiblyForwardedMessage#forwarded` field now renamed to `forwardInfo`
* Most part of requests have changed return type. They are listed below: * Most part of requests have changed return type. They are listed below:
<details> <details>

View File

@ -3,12 +3,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardedMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.* import kotlinx.serialization.*
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<AbleToBeForwardedMessage>() private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<PossiblyForwardedMessage>()
@Serializable @Serializable
data class ForwardMessage( data class ForwardMessage(
@ -20,13 +18,13 @@ data class ForwardMessage(
override val messageId: MessageIdentifier, override val messageId: MessageIdentifier,
@SerialName(disableNotificationField) @SerialName(disableNotificationField)
val disableNotification: Boolean = false val disableNotification: Boolean = false
): SimpleRequest<AbleToBeForwardedMessage>, MessageAction { ): SimpleRequest<PossiblyForwardedMessage>, MessageAction {
override val chatId: ChatIdentifier override val chatId: ChatIdentifier
get() = fromChatId get() = fromChatId
override fun method(): String = "forwardMessage" override fun method(): String = "forwardMessage"
override val resultDeserializer: DeserializationStrategy<AbleToBeForwardedMessage> override val resultDeserializer: DeserializationStrategy<PossiblyForwardedMessage>
get() = AbleToBeForwardedMessageDeserializer get() = AbleToBeForwardedMessageDeserializer
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>
get() = serializer() get() = serializer()

View File

@ -16,7 +16,7 @@ data class ChannelMediaGroupMessage(
override val mediaGroupId: MediaGroupIdentifier, override val mediaGroupId: MediaGroupIdentifier,
override val content: MediaGroupContent, override val content: MediaGroupContent,
override val editDate: DateTime?, override val editDate: DateTime?,
override val forwarded: ForwardedMessage?, override val forwardInfo: ForwardInfo?,
override val replyTo: Message?, override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup? override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage ) : MediaGroupMessage

View File

@ -15,7 +15,7 @@ data class ChannelMessage<T: MessageContent>(
override val content: T, override val content: T,
override val date: DateTime, override val date: DateTime,
override val editDate: DateTime?, override val editDate: DateTime?,
override val forwarded: ForwardedMessage?, override val forwardInfo: ForwardInfo?,
override val replyTo: Message?, override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
val authorSignature: AuthorSignature? val authorSignature: AuthorSignature?

View File

@ -15,7 +15,7 @@ data class CommonMediaGroupMessage(
override val mediaGroupId: MediaGroupIdentifier, override val mediaGroupId: MediaGroupIdentifier,
override val content: MediaGroupContent, override val content: MediaGroupContent,
override val editDate: DateTime?, override val editDate: DateTime?,
override val forwarded: ForwardedMessage?, override val forwardInfo: ForwardInfo?,
override val replyTo: Message?, override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup? override val replyMarkup: InlineKeyboardMarkup?
) : MediaGroupMessage, FromUserMessage ) : MediaGroupMessage, FromUserMessage

View File

@ -16,7 +16,7 @@ data class CommonMessageImpl<T: MessageContent>(
override val content: T, override val content: T,
override val date: DateTime, override val date: DateTime,
override val editDate: DateTime?, override val editDate: DateTime?,
override val forwarded: ForwardedMessage?, override val forwardInfo: ForwardInfo?,
override val replyTo: Message?, override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?, override val replyMarkup: InlineKeyboardMarkup?,
val paymentInfo: PaymentInfo? val paymentInfo: PaymentInfo?

View File

@ -0,0 +1,57 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
@Deprecated(
"Renamed",
ReplaceWith(
"ForwardInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo"
)
)
typealias ForwardedMessage = ForwardInfo
sealed class ForwardInfo {
abstract val dateOfOriginal: TelegramDate
}
@Deprecated(
"Renamed",
ReplaceWith(
"AnonymousForwardInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.AnonymousForwardInfo"
)
)
typealias AnonymousForwardedMessage = AnonymousForwardInfo
data class AnonymousForwardInfo(
override val dateOfOriginal: TelegramDate,
val senderName: String
) : ForwardInfo()
@Deprecated(
"Renamed",
ReplaceWith(
"UserForwardInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.UserForwardInfo"
)
)
typealias UserForwardedMessage = UserForwardInfo
data class UserForwardInfo(
override val dateOfOriginal: TelegramDate,
val from: User
) : ForwardInfo()
@Deprecated(
"Renamed",
ReplaceWith(
"ForwardFromChannelInfo",
"com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardFromChannelInfo"
)
)
typealias ForwardedFromChannelMessage = ForwardFromChannelInfo
data class ForwardFromChannelInfo(
override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier,
val channelChat: Chat,
val signature: String? = null
) : ForwardInfo()

View File

@ -1,25 +0,0 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
sealed class ForwardedMessage {
abstract val dateOfOriginal: TelegramDate
}
data class AnonymousForwardedMessage(
override val dateOfOriginal: TelegramDate,
val senderName: String
) : ForwardedMessage()
data class UserForwardedMessage(
override val dateOfOriginal: TelegramDate,
val from: User
) : ForwardedMessage()
data class ForwardedFromChannelMessage(
override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier,
val channelChat: Chat,
val signature: String? = null
) : ForwardedMessage()

View File

@ -134,20 +134,20 @@ internal data class RawMessage(
} }
@Transient @Transient
private val forwarded: ForwardedMessage? by lazy { private val forwarded: ForwardInfo? by lazy {
forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field
when { when {
forward_sender_name != null -> AnonymousForwardedMessage( forward_sender_name != null -> AnonymousForwardInfo(
forward_date, forward_date,
forward_sender_name forward_sender_name
) )
forward_from_chat != null -> ForwardedFromChannelMessage( forward_from_chat != null -> ForwardFromChannelInfo(
forward_date, forward_date,
forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"), forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"),
forward_from_chat, forward_from_chat,
forward_signature forward_signature
) )
forward_from != null -> UserForwardedMessage( forward_from != null -> UserForwardInfo(
forward_date, forward_date,
forward_from forward_from
) )

View File

@ -1,7 +0,0 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardedMessage
interface AbleToBeForwardedMessage : Message {
val forwarded: ForwardedMessage?
}

View File

@ -3,8 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
interface CommonMessage<T: MessageContent> : Message, interface CommonMessage<T: MessageContent> : Message,
AbleToBeForwardedMessage, PossiblyForwardedMessage,
AbleToBeEditedMessage, PossiblyEditedMessage,
AbleToReplyMessage, PossiblyReplyMessage,
AbleToBeMarkedUp, PossiblyMarkedUp,
ContentMessage<T> ContentMessage<T>

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
interface AbleToBeEditedMessage : Message { interface PossiblyEditedMessage : Message {
val editDate: DateTime? val editDate: DateTime?
} }

View File

@ -0,0 +1,13 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo
interface PossiblyForwardedMessage : Message {
val forwardInfo: ForwardInfo?
@Deprecated(
"Renamed",
ReplaceWith("forwardInfo")
)
val forwarded: ForwardInfo?
get() = forwardInfo
}

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
interface AbleToBeMarkedUp { interface PossiblyMarkedUp {
val replyMarkup: InlineKeyboardMarkup? val replyMarkup: InlineKeyboardMarkup?
} }

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo
interface AbleToBePaymentedMessage : Message { interface PossiblyPaymentMessage : Message {
val paymentInfo: PaymentInfo? val paymentInfo: PaymentInfo?
} }

View File

@ -1,5 +1,5 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
interface AbleToReplyMessage { interface PossiblyReplyMessage {
val replyTo: Message? val replyTo: Message?
} }

View File

@ -2,18 +2,18 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardedMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
val List<BaseMessageUpdate>.forwarded: ForwardedMessage? val List<BaseMessageUpdate>.forwarded: ForwardInfo?
get() = first().let { get() = first().let {
(it as? AbleToBeForwardedMessage) ?.forwarded (it as? PossiblyForwardedMessage) ?.forwardInfo
} }
val List<BaseMessageUpdate>.replyTo: Message? val List<BaseMessageUpdate>.replyTo: Message?
get() = first().let { get() = first().let {
(it as? AbleToReplyMessage) ?.replyTo (it as? PossiblyReplyMessage) ?.replyTo
} }
val List<BaseMessageUpdate>.chat: Chat? val List<BaseMessageUpdate>.chat: Chat?