mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
implementation of sender_chat and author_signature
This commit is contained in:
parent
ec806dfd83
commit
ff34b23777
15
CHANGELOG.md
15
CHANGELOG.md
@ -2,6 +2,8 @@
|
||||
|
||||
## 0.30.0 Bot API 5.0
|
||||
|
||||
**THIS UPDATE CONTAINS A LOT OF BREAKING CHANGES. PLEASE, BE CAREFUL ON UPGRADING OF YOUR PROJECT**
|
||||
|
||||
* `Core`:
|
||||
* Support of `logOut` method (`LogOut` object as a `Request`)
|
||||
* Support of `close` method (`Close` object as a `Request`)
|
||||
@ -43,6 +45,19 @@
|
||||
* Property `pollQuestionTextLength` now have maximum up to `300`
|
||||
* Anonymous Admins:
|
||||
* New field `AdministratorChatMember#isAnonymous`
|
||||
* Several new interfaces of messages:
|
||||
* `SignedMessage` - any message which possibly have `authorSignature`
|
||||
* `WithSenderChatMessage` - any message which have `senderChat`. Property `senderChat` is not-nullable due to
|
||||
separation of implementators
|
||||
* `PublicMessage` - all channel messages have property `val chat: PublicChat` instead of common `val chat: Chat`
|
||||
* `ChannelMessage` - all channel messages have property `val chat: ChannelChat` instead of common `val chat: Chat`
|
||||
* Old `ChannelMessage` was safely renamed to `ChannelMessageImpl` (old name was set as typealias and deprecated)
|
||||
* `GroupMessage` - all group messages have property `val chat: GroupChat` instead of common `val chat: Chat`
|
||||
* `FromChannelGroupMessage` - instances should have property `val channel: ChannelChat`
|
||||
* `AnonymousGroupMessage` - instances may have setup property `authorSignature`
|
||||
* `CommonGroupMessage` - just common message
|
||||
* `PrivateMessage` - works like previous `CommonMessageImpl`
|
||||
* Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl`
|
||||
* `API`:
|
||||
* Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat`
|
||||
* New extensions `TelegramBot#unpinAllChatMessages`
|
||||
|
@ -7,10 +7,12 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage
|
||||
|
||||
data class ChannelMessage<T: MessageContent>(
|
||||
data class ChannelMessageImpl<T: MessageContent>(
|
||||
override val messageId: MessageIdentifier,
|
||||
override val chat: Chat,
|
||||
override val chat: ChannelChat,
|
||||
override val content: T,
|
||||
override val date: DateTime,
|
||||
override val editDate: DateTime?,
|
||||
@ -18,5 +20,8 @@ data class ChannelMessage<T: MessageContent>(
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val senderBot: CommonBot?,
|
||||
val authorSignature: AuthorSignature?
|
||||
) : PossiblySentViaBotCommonMessage<T>
|
||||
override val authorSignature: AuthorSignature?
|
||||
) : ChannelMessage<T>
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("ChannelMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelMessageImpl"))
|
||||
typealias ChannelMessage<T> = ChannelMessageImpl<T>
|
@ -0,0 +1,49 @@
|
||||
package dev.inmo.tgbotapi.types.message
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
|
||||
data class FromChannelGroupMessageImpl<T : MessageContent>(
|
||||
override val chat: GroupChat,
|
||||
override val channel: ChannelChat,
|
||||
override val messageId: MessageIdentifier,
|
||||
override val date: DateTime,
|
||||
override val forwardInfo: ForwardInfo?,
|
||||
override val editDate: DateTime?,
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val content: T,
|
||||
override val senderBot: CommonBot?,
|
||||
override val authorSignature: AuthorSignature?
|
||||
) : FromChannelGroupMessage<T>
|
||||
|
||||
data class AnonymousGroupMessageImpl<T : MessageContent>(
|
||||
override val chat: GroupChat,
|
||||
override val messageId: MessageIdentifier,
|
||||
override val date: DateTime,
|
||||
override val forwardInfo: ForwardInfo?,
|
||||
override val editDate: DateTime?,
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val content: T,
|
||||
override val senderBot: CommonBot?,
|
||||
override val authorSignature: AuthorSignature?
|
||||
) : AnonymousGroupMessage<T>
|
||||
|
||||
data class CommonGroupMessageImpl<T : MessageContent>(
|
||||
override val chat: GroupChat,
|
||||
override val messageId: MessageIdentifier,
|
||||
override val date: DateTime,
|
||||
override val forwardInfo: ForwardInfo?,
|
||||
override val editDate: DateTime?,
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val content: T,
|
||||
override val senderBot: CommonBot?
|
||||
) : CommonGroupMessage<T>
|
@ -3,14 +3,13 @@ package dev.inmo.tgbotapi.types.message
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
|
||||
data class CommonMessageImpl<T: MessageContent>(
|
||||
data class PrivateMessageImpl<T: MessageContent>(
|
||||
override val messageId: MessageIdentifier,
|
||||
override val user: User,
|
||||
override val chat: Chat,
|
||||
@ -22,4 +21,7 @@ data class CommonMessageImpl<T: MessageContent>(
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val senderBot: CommonBot?,
|
||||
val paymentInfo: SuccessfulPaymentInfo?
|
||||
) : PossiblySentViaBotCommonMessage<T>, FromUserMessage
|
||||
) : PrivateMessage<T>
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("PrivateMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateMessageImpl"))
|
||||
typealias CommonMessageImpl<T> = PrivateMessageImpl<T>
|
@ -10,7 +10,6 @@ import dev.inmo.tgbotapi.types.files.*
|
||||
import dev.inmo.tgbotapi.types.games.RawGame
|
||||
import dev.inmo.tgbotapi.types.location.Location
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered
|
||||
import dev.inmo.tgbotapi.types.location.StaticLocation
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
@ -31,14 +30,11 @@ import kotlin.reflect.KClass
|
||||
// TODO:: add PassportData type
|
||||
@Serializable
|
||||
internal data class RawMessage(
|
||||
@SerialName(messageIdField)
|
||||
val messageId: MessageIdentifier,
|
||||
@SerialName(dateField)
|
||||
val date: TelegramDate,
|
||||
@SerialName(chatField)
|
||||
private val chat: Chat,
|
||||
@SerialName(fromField)
|
||||
private val from: User? = null,
|
||||
private val sender_chat: PublicChat? = null,
|
||||
private val forward_from: User? = null,
|
||||
private val forward_from_chat: Chat? = null,
|
||||
private val forward_from_message_id: MessageIdentifier? = null,
|
||||
@ -258,19 +254,61 @@ internal data class RawMessage(
|
||||
)
|
||||
}
|
||||
} ?: when (chat) {
|
||||
is ChannelChat -> ChannelMessage(
|
||||
messageId,
|
||||
chat,
|
||||
content,
|
||||
date.asDate,
|
||||
edit_date?.asDate,
|
||||
forwarded,
|
||||
reply_to_message?.asMessage,
|
||||
reply_markup,
|
||||
via_bot,
|
||||
author_signature
|
||||
)
|
||||
else -> CommonMessageImpl(
|
||||
is PublicChat -> when (chat) {
|
||||
is ChannelChat -> ChannelMessageImpl(
|
||||
messageId,
|
||||
chat,
|
||||
content,
|
||||
date.asDate,
|
||||
edit_date?.asDate,
|
||||
forwarded,
|
||||
reply_to_message?.asMessage,
|
||||
reply_markup,
|
||||
via_bot,
|
||||
author_signature
|
||||
)
|
||||
is GroupChat -> when (sender_chat) {
|
||||
is ChannelChat -> FromChannelGroupMessageImpl(
|
||||
chat,
|
||||
sender_chat,
|
||||
messageId,
|
||||
date.asDate,
|
||||
forwarded,
|
||||
edit_date ?.asDate,
|
||||
reply_to_message ?.asMessage,
|
||||
reply_markup,
|
||||
content,
|
||||
via_bot,
|
||||
author_signature
|
||||
)
|
||||
is GroupChat -> AnonymousGroupMessageImpl(
|
||||
chat,
|
||||
messageId,
|
||||
date.asDate,
|
||||
forwarded,
|
||||
edit_date ?.asDate,
|
||||
reply_to_message ?.asMessage,
|
||||
reply_markup,
|
||||
content,
|
||||
via_bot,
|
||||
author_signature
|
||||
)
|
||||
null -> CommonGroupMessageImpl(
|
||||
chat,
|
||||
messageId,
|
||||
date.asDate,
|
||||
forwarded,
|
||||
edit_date ?.asDate,
|
||||
reply_to_message ?.asMessage,
|
||||
reply_markup,
|
||||
content,
|
||||
via_bot
|
||||
)
|
||||
else -> error("Currently in groups supported only fields \"sender_chat\" with channel, group or null, but was $sender_chat")
|
||||
}
|
||||
else -> error("Unknown type of public chat: $chat")
|
||||
}
|
||||
is PrivateChat -> PrivateMessageImpl(
|
||||
messageId,
|
||||
from ?: error("Was detected common message, but owner (sender) of the message was not found"),
|
||||
chat,
|
||||
@ -283,6 +321,7 @@ internal data class RawMessage(
|
||||
via_bot,
|
||||
paymentInfo
|
||||
)
|
||||
else -> error("Unknown type of chat: $chat")
|
||||
}
|
||||
} ?: error("Was not found supported type of data")
|
||||
} catch (e: Exception) {
|
||||
|
@ -0,0 +1,12 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
|
||||
interface ChannelMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||
override val chat: ChannelChat
|
||||
override val senderChat: ChannelChat
|
||||
get() = chat
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
|
||||
interface GroupMessage<T : MessageContent> : PublicMessage<T> {
|
||||
override val chat: GroupChat
|
||||
}
|
||||
|
||||
interface FromChannelGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||
val channel: ChannelChat
|
||||
override val senderChat: ChannelChat
|
||||
get() = channel
|
||||
}
|
||||
interface AnonymousGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||
override val senderChat: GroupChat
|
||||
get() = chat
|
||||
}
|
||||
interface CommonGroupMessage<T : MessageContent> : GroupMessage<T>
|
@ -0,0 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
|
||||
interface PrivateMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, FromUserMessage
|
@ -0,0 +1,9 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
|
||||
interface PublicMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
|
||||
override val chat: PublicChat
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.AuthorSignature
|
||||
|
||||
interface SignedMessage : Message {
|
||||
val authorSignature: AuthorSignature?
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||
|
||||
interface WithSenderChatMessage {
|
||||
val senderChat: Chat
|
||||
}
|
Loading…
Reference in New Issue
Block a user