1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +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`**
* `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:
<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.requests.abstracts.SimpleRequest
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.TelegramBotAPIMessageDeserializationStrategy
import kotlinx.serialization.*
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<AbleToBeForwardedMessage>()
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<PossiblyForwardedMessage>()
@Serializable
data class ForwardMessage(
@ -20,13 +18,13 @@ data class ForwardMessage(
override val messageId: MessageIdentifier,
@SerialName(disableNotificationField)
val disableNotification: Boolean = false
): SimpleRequest<AbleToBeForwardedMessage>, MessageAction {
): SimpleRequest<PossiblyForwardedMessage>, MessageAction {
override val chatId: ChatIdentifier
get() = fromChatId
override fun method(): String = "forwardMessage"
override val resultDeserializer: DeserializationStrategy<AbleToBeForwardedMessage>
override val resultDeserializer: DeserializationStrategy<PossiblyForwardedMessage>
get() = AbleToBeForwardedMessageDeserializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ data class CommonMessageImpl<T: MessageContent>(
override val content: T,
override val date: DateTime,
override val editDate: DateTime?,
override val forwarded: ForwardedMessage?,
override val forwardInfo: ForwardInfo?,
override val replyTo: Message?,
override val replyMarkup: InlineKeyboardMarkup?,
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
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
when {
forward_sender_name != null -> AnonymousForwardedMessage(
forward_sender_name != null -> AnonymousForwardInfo(
forward_date,
forward_sender_name
)
forward_from_chat != null -> ForwardedFromChannelMessage(
forward_from_chat != null -> ForwardFromChannelInfo(
forward_date,
forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"),
forward_from_chat,
forward_signature
)
forward_from != null -> UserForwardedMessage(
forward_from != null -> UserForwardInfo(
forward_date,
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
interface CommonMessage<T: MessageContent> : Message,
AbleToBeForwardedMessage,
AbleToBeEditedMessage,
AbleToReplyMessage,
AbleToBeMarkedUp,
PossiblyForwardedMessage,
PossiblyEditedMessage,
PossiblyReplyMessage,
PossiblyMarkedUp,
ContentMessage<T>

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.soywiz.klock.DateTime
interface AbleToBeEditedMessage : Message {
interface PossiblyEditedMessage : Message {
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
interface AbleToBeMarkedUp {
interface PossiblyMarkedUp {
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
interface AbleToBePaymentedMessage : Message {
interface PossiblyPaymentMessage : Message {
val paymentInfo: PaymentInfo?
}

View File

@ -1,5 +1,5 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
interface AbleToReplyMessage {
interface PossiblyReplyMessage {
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.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.update.abstracts.BaseMessageUpdate
val List<BaseMessageUpdate>.forwarded: ForwardedMessage?
val List<BaseMessageUpdate>.forwarded: ForwardInfo?
get() = first().let {
(it as? AbleToBeForwardedMessage) ?.forwarded
(it as? PossiblyForwardedMessage) ?.forwardInfo
}
val List<BaseMessageUpdate>.replyTo: Message?
get() = first().let {
(it as? AbleToReplyMessage) ?.replyTo
(it as? PossiblyReplyMessage) ?.replyTo
}
val List<BaseMessageUpdate>.chat: Chat?