mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-15 05:09:30 +00:00
add new type of chats ids
This commit is contained in:
@@ -2,9 +2,8 @@ package dev.inmo.tgbotapi.requests.chat.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
|
||||
interface ChatSenderRequest : ChatRequest, SimpleRequest<Boolean> {
|
||||
val senderChatId: ChatId
|
||||
val senderChatId: IdChatIdentifier
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.requests.chat.get
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.types.ChatRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.ChatIdWithThreadId
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer
|
||||
import dev.inmo.tgbotapi.types.chat.ExtendedChat
|
||||
@@ -14,8 +15,12 @@ data class GetChat(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<ExtendedChat> {
|
||||
override fun method(): String = "getChat"
|
||||
override val resultDeserializer: DeserializationStrategy<ExtendedChat>
|
||||
get() = ExtendedChatSerializer
|
||||
@Transient
|
||||
override val resultDeserializer: DeserializationStrategy<ExtendedChat> = if (chatId is ChatIdWithThreadId) {
|
||||
ExtendedChatSerializer.BasedOnForumThread(chatId.threadId)
|
||||
} else {
|
||||
ExtendedChatSerializer
|
||||
}
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ data class BanChatSenderChat(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(senderChatIdField)
|
||||
override val senderChatId: ChatId
|
||||
override val senderChatId: IdChatIdentifier
|
||||
) : ChatSenderRequest {
|
||||
override fun method(): String = "banChatSenderChat"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
@@ -13,7 +13,7 @@ data class UnbanChatSenderChat(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(senderChatIdField)
|
||||
override val senderChatId: ChatId
|
||||
override val senderChatId: IdChatIdentifier
|
||||
) : ChatSenderRequest {
|
||||
override fun method(): String = "unbanChatSenderChat"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
@@ -10,7 +10,7 @@ data class GetGameHighScoresByChat (
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
override val chatId: IdChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageId
|
||||
) : GetGameHighScores, MessageAction {
|
||||
|
@@ -12,7 +12,7 @@ data class SetGameScoreByChatId (
|
||||
@SerialName(scoreField)
|
||||
override val score: Long,
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
override val chatId: IdChatIdentifier,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageId,
|
||||
@SerialName(forceField)
|
||||
|
@@ -22,7 +22,7 @@ private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<Inv
|
||||
@Serializable
|
||||
data class SendInvoice(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
override val chatId: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(descriptionField)
|
||||
@@ -59,7 +59,7 @@ data class SendInvoice(
|
||||
@SerialName(priceDependOnShipAddressField)
|
||||
override val priceDependOnShipAddress: Boolean = false,
|
||||
@SerialName(messageThreadIdField)
|
||||
override val threadId: MessageThreadId? = null,
|
||||
override val threadId: MessageThreadId? = chatId.threadId,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(protectContentField)
|
||||
|
@@ -10,19 +10,44 @@ import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.longOrNull
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
const val internalLinkBeginning = "https://t.me"
|
||||
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
sealed class ChatIdentifier
|
||||
sealed interface ChatIdentifier
|
||||
|
||||
/**
|
||||
* Also used as User Identifier
|
||||
*/
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
data class ChatId(
|
||||
val chatId: Identifier
|
||||
) : ChatIdentifier()
|
||||
sealed interface IdChatIdentifier : ChatIdentifier {
|
||||
abstract val chatId: Identifier
|
||||
val threadId: MessageThreadId?
|
||||
get() = null
|
||||
|
||||
companion object {
|
||||
operator fun invoke(chatId: Identifier) = ChatId(chatId)
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
@JvmInline
|
||||
value class ChatId(override val chatId: Identifier) : IdChatIdentifier
|
||||
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
@JvmInline
|
||||
value class ChatIdWithThreadId(val chatIdWithThreadId: Pair<Identifier, MessageThreadId>) : IdChatIdentifier {
|
||||
override val chatId: Identifier
|
||||
get() = chatIdWithThreadId.first
|
||||
override val threadId: MessageThreadId
|
||||
get() = chatIdWithThreadId.second
|
||||
|
||||
constructor(chatId: Identifier, threadId: MessageThreadId): this(chatId to threadId)
|
||||
}
|
||||
|
||||
val ChatIdentifier.threadId: MessageThreadId?
|
||||
get() = (this as? IdChatIdentifier) ?.threadId
|
||||
|
||||
/**
|
||||
* https://core.telegram.org/bots/api#formatting-options
|
||||
@@ -39,16 +64,16 @@ val UserId.userLink: String
|
||||
val User.link: String
|
||||
get() = id.userLink
|
||||
|
||||
typealias UserId = ChatId
|
||||
typealias UserId = IdChatIdentifier
|
||||
|
||||
fun Identifier.toChatId(): ChatId = ChatId(this)
|
||||
fun Int.toChatId(): ChatId = toLong().toChatId()
|
||||
fun Byte.toChatId(): ChatId = toLong().toChatId()
|
||||
fun Identifier.toChatId(): IdChatIdentifier = ChatId(this)
|
||||
fun Int.toChatId(): IdChatIdentifier = toLong().toChatId()
|
||||
fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId()
|
||||
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
data class Username(
|
||||
val username: String
|
||||
) : ChatIdentifier() {
|
||||
) : ChatIdentifier {
|
||||
val usernameWithoutAt
|
||||
get() = username.dropWhile { it == '@' }
|
||||
|
||||
@@ -80,7 +105,7 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatIdentifier) {
|
||||
when (value) {
|
||||
is ChatId -> encoder.encodeLong(value.chatId)
|
||||
is IdChatIdentifier -> encoder.encodeLong(value.chatId)
|
||||
is Username -> encoder.encodeString(value.username)
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ data class RetryAfterError(
|
||||
}
|
||||
|
||||
data class MigrateChatId(
|
||||
val newChatId: ChatId
|
||||
val newChatId: IdChatIdentifier
|
||||
) : RequestError()
|
||||
|
||||
|
||||
|
@@ -6,7 +6,7 @@ import kotlinx.serialization.*
|
||||
@Serializable
|
||||
data class ResponseParametersRaw(
|
||||
@SerialName("migrate_to_chat_id")
|
||||
private val migrateToChatId: ChatId? = null,
|
||||
private val migrateToChatId: IdChatIdentifier? = null,
|
||||
@SerialName("retry_after")
|
||||
private val retryAfter: Seconds? = null
|
||||
) {
|
||||
|
@@ -49,5 +49,5 @@ sealed interface AbleToAddInAttachmentMenuChat : Chat {
|
||||
@Serializable(PreviewChatSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface Chat {
|
||||
val id: ChatId
|
||||
val id: IdChatIdentifier
|
||||
}
|
||||
|
@@ -93,9 +93,9 @@ object PreviewChatSerializer : KSerializer<Chat> {
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
object ExtendedChatSerializer : KSerializer<ExtendedChat> {
|
||||
sealed class ExtendedChatSerializer : KSerializer<ExtendedChat> {
|
||||
@OptIn(InternalSerializationApi::class)
|
||||
override val descriptor: SerialDescriptor = buildSerialDescriptor("PreviewChatSerializer", PolymorphicKind.OPEN)
|
||||
override val descriptor: SerialDescriptor = buildSerialDescriptor("ExtendedChatSerializer", PolymorphicKind.OPEN)
|
||||
|
||||
override fun deserialize(decoder: Decoder): ExtendedChat {
|
||||
val decodedJson = JsonObject.serializer().deserialize(decoder)
|
||||
@@ -131,6 +131,22 @@ object ExtendedChatSerializer : KSerializer<ExtendedChat> {
|
||||
is UnknownExtendedChat -> JsonObject.serializer().serialize(encoder, value.rawJson)
|
||||
}
|
||||
}
|
||||
|
||||
class BasedOnForumThread(private val threadId: MessageThreadId) : ExtendedChatSerializer() {
|
||||
override fun deserialize(decoder: Decoder): ExtendedChat {
|
||||
return super.deserialize(decoder).let {
|
||||
if (it is ExtendedForumChatImpl) {
|
||||
it.copy(
|
||||
id = (it.id as? ChatIdWithThreadId) ?: ChatIdWithThreadId(it.id.chatId, threadId)
|
||||
)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object : ExtendedChatSerializer()
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
|
@@ -10,7 +10,7 @@ import kotlinx.serialization.json.JsonObject
|
||||
@Serializable
|
||||
data class ExtendedChannelChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
@@ -27,13 +27,13 @@ data class ExtendedChannelChatImpl(
|
||||
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
|
||||
override val pinnedMessage: Message? = null,
|
||||
@SerialName(linkedChatIdField)
|
||||
override val linkedGroupChatId: ChatId? = null
|
||||
override val linkedGroupChatId: IdChatIdentifier? = null
|
||||
) : ExtendedChannelChat
|
||||
|
||||
@Serializable
|
||||
data class ExtendedGroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(photoField)
|
||||
@@ -52,7 +52,7 @@ data class ExtendedGroupChatImpl(
|
||||
@Serializable
|
||||
data class ExtendedPrivateChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(photoField)
|
||||
override val chatPhoto: ChatPhoto? = null,
|
||||
@SerialName(usernameField)
|
||||
@@ -78,7 +78,7 @@ typealias ExtendedUser = ExtendedPrivateChatImpl
|
||||
@Serializable
|
||||
data class ExtendedSupergroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
@@ -103,7 +103,7 @@ data class ExtendedSupergroupChatImpl(
|
||||
@SerialName(canSetStickerSetField)
|
||||
override val canSetStickerSet: Boolean = false,
|
||||
@SerialName(linkedChatIdField)
|
||||
override val linkedChannelChatId: ChatId? = null,
|
||||
override val linkedChannelChatId: IdChatIdentifier? = null,
|
||||
@SerialName(locationField)
|
||||
override val location: ChatLocation? = null,
|
||||
@SerialName(joinToSendMessagesField)
|
||||
@@ -115,7 +115,7 @@ data class ExtendedSupergroupChatImpl(
|
||||
@Serializable
|
||||
data class ExtendedForumChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
@@ -140,7 +140,7 @@ data class ExtendedForumChatImpl(
|
||||
@SerialName(canSetStickerSetField)
|
||||
override val canSetStickerSet: Boolean = false,
|
||||
@SerialName(linkedChatIdField)
|
||||
override val linkedChannelChatId: ChatId? = null,
|
||||
override val linkedChannelChatId: IdChatIdentifier? = null,
|
||||
@SerialName(locationField)
|
||||
override val location: ChatLocation? = null,
|
||||
@SerialName(joinToSendMessagesField)
|
||||
@@ -170,7 +170,7 @@ data class ExtendedBot(
|
||||
}
|
||||
|
||||
data class UnknownExtendedChat(
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
val raw: String,
|
||||
val rawJson: JsonObject
|
||||
) : ExtendedChat {
|
||||
|
@@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ExtendedChatSerializer::class)
|
||||
sealed interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat, ExtendedChatWithUsername {
|
||||
val linkedGroupChatId: ChatId?
|
||||
val linkedGroupChatId: IdChatIdentifier?
|
||||
}
|
||||
|
||||
@Serializable(ExtendedChatSerializer::class)
|
||||
@@ -38,7 +38,7 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext
|
||||
val slowModeDelay: Long?
|
||||
val stickerSetName: StickerSetName?
|
||||
val canSetStickerSet: Boolean
|
||||
val linkedChannelChatId: ChatId?
|
||||
val linkedChannelChatId: IdChatIdentifier?
|
||||
val location: ChatLocation?
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext
|
||||
}
|
||||
|
||||
@Serializable(ExtendedChatSerializer::class)
|
||||
sealed interface ExtendedForumChat : ExtendedSupergroupChat
|
||||
sealed interface ExtendedForumChat : ExtendedSupergroupChat, ForumChat
|
||||
|
||||
@Serializable(ExtendedChatSerializer::class)
|
||||
sealed interface ExtendedChat : Chat {
|
||||
|
@@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
data class GroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String
|
||||
) : GroupChat
|
||||
@@ -18,7 +18,7 @@ data class GroupChatImpl(
|
||||
@Serializable
|
||||
data class PrivateChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(usernameField)
|
||||
override val username: Username? = null,
|
||||
@SerialName(firstNameField)
|
||||
@@ -30,7 +30,7 @@ data class PrivateChatImpl(
|
||||
@Serializable
|
||||
data class SupergroupChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
@@ -40,7 +40,7 @@ data class SupergroupChatImpl(
|
||||
@Serializable
|
||||
data class ForumChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
@@ -50,7 +50,7 @@ data class ForumChatImpl(
|
||||
@Serializable
|
||||
data class ChannelChatImpl(
|
||||
@SerialName(idField)
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(usernameField)
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package dev.inmo.tgbotapi.types.chat
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
data class UnknownChatType(
|
||||
override val id: ChatId,
|
||||
override val id: IdChatIdentifier,
|
||||
val raw: String,
|
||||
val rawJson: JsonObject
|
||||
) : Chat
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
|
||||
|
||||
class GroupChatCreated(
|
||||
val migratedTo: ChatId?
|
||||
val migratedTo: IdChatIdentifier?
|
||||
): GroupEvent
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent
|
||||
|
||||
/**
|
||||
* This event is sent when a group is converted to a supergroup.
|
||||
*/
|
||||
data class MigratedToSupergroup(
|
||||
val migratedFrom: ChatId
|
||||
val migratedFrom: IdChatIdentifier
|
||||
): SupergroupEvent
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent
|
||||
|
||||
class SupergroupChatCreated(
|
||||
val migratedFrom: ChatId?
|
||||
val migratedFrom: IdChatIdentifier?
|
||||
): SupergroupEvent
|
||||
|
@@ -81,8 +81,8 @@ internal data class RawMessage(
|
||||
private val group_chat_created: Boolean = false,
|
||||
private val supergroup_chat_created: Boolean = false,
|
||||
private val channel_chat_created: Boolean = false,
|
||||
private val migrate_to_chat_id: ChatId? = null,
|
||||
private val migrate_from_chat_id: ChatId? = null,
|
||||
private val migrate_to_chat_id: IdChatIdentifier? = null,
|
||||
private val migrate_from_chat_id: IdChatIdentifier? = null,
|
||||
private val pinned_message: RawMessage? = null,
|
||||
private val invoice: Invoice? = null,
|
||||
private val dice: Dice? = null,
|
||||
@@ -286,9 +286,17 @@ internal data class RawMessage(
|
||||
media_group_id
|
||||
)
|
||||
is ForumChat -> if (messageThreadId != null) {
|
||||
val chatId = ChatIdWithThreadId(
|
||||
chat.id.chatId,
|
||||
messageThreadId
|
||||
)
|
||||
val actualForumChat = when (chat) {
|
||||
is ExtendedForumChatImpl -> chat.copy(id = chatId)
|
||||
is ForumChatImpl -> chat.copy(id = chatId)
|
||||
}
|
||||
when (sender_chat) {
|
||||
is ChannelChat -> FromChannelForumContentMessageImpl(
|
||||
chat,
|
||||
actualForumChat,
|
||||
sender_chat,
|
||||
messageId,
|
||||
messageThreadId,
|
||||
@@ -304,7 +312,7 @@ internal data class RawMessage(
|
||||
media_group_id
|
||||
)
|
||||
is GroupChat -> AnonymousForumContentMessageImpl(
|
||||
chat,
|
||||
actualForumChat,
|
||||
messageId,
|
||||
messageThreadId,
|
||||
date.asDate,
|
||||
@@ -319,7 +327,7 @@ internal data class RawMessage(
|
||||
media_group_id
|
||||
)
|
||||
null -> CommonForumContentMessageImpl(
|
||||
chat,
|
||||
actualForumChat,
|
||||
messageId,
|
||||
messageThreadId,
|
||||
from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"),
|
||||
|
@@ -1,19 +1,18 @@
|
||||
package dev.inmo.tgbotapi.utils.extensions
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.utils.extensions.ChatIdWithThreadId.ByPair
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.Pair
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
/**
|
||||
* Union to keep both [ChatId] and optionally [MessageThreadId] as an identifier of target for messages sending and
|
||||
* Union to keep both [IdChatIdentifier] and optionally [MessageThreadId] as an identifier of target for messages sending and
|
||||
* other information
|
||||
*/
|
||||
sealed interface ChatIdWithThreadId {
|
||||
val chatId: ChatId
|
||||
val chatId: IdChatIdentifier
|
||||
val threadId: MessageThreadId?
|
||||
|
||||
/**
|
||||
@@ -23,14 +22,14 @@ sealed interface ChatIdWithThreadId {
|
||||
value class ByMessage(
|
||||
val sourceMessage: Message
|
||||
) : ChatIdWithThreadId {
|
||||
override val chatId: ChatId
|
||||
override val chatId: IdChatIdentifier
|
||||
get() = sourceMessage.chat.id
|
||||
override val threadId: MessageThreadId?
|
||||
get() = sourceMessage.threadIdOrNull
|
||||
}
|
||||
|
||||
/**
|
||||
* [Serializable] variant of [ChatIdWithThreadId] based on [Pair] of target [ChatId] and [MessageThreadId]
|
||||
* [Serializable] variant of [ChatIdWithThreadId] based on [Pair] of target [IdChatIdentifier] and [MessageThreadId]
|
||||
*
|
||||
* @see invoke
|
||||
* @see serializable
|
||||
@@ -38,9 +37,9 @@ sealed interface ChatIdWithThreadId {
|
||||
@Serializable
|
||||
@JvmInline
|
||||
value class ByPair(
|
||||
val pair: Pair<ChatId, MessageThreadId?>
|
||||
val pair: Pair<IdChatIdentifier, MessageThreadId?>
|
||||
) : ChatIdWithThreadId {
|
||||
override val chatId: ChatId
|
||||
override val chatId: IdChatIdentifier
|
||||
get() = pair.first
|
||||
override val threadId: MessageThreadId?
|
||||
get() = pair.second
|
||||
@@ -61,7 +60,7 @@ sealed interface ChatIdWithThreadId {
|
||||
/**
|
||||
* Creates [ByPair] variant of [ChatIdWithThreadId] using incoming [pair]
|
||||
*/
|
||||
inline fun serializable(pair: Pair<ChatId, MessageThreadId?>) = ByPair(pair)
|
||||
inline fun serializable(pair: Pair<IdChatIdentifier, MessageThreadId?>) = ByPair(pair)
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@@ -3,13 +3,11 @@ package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
import dev.inmo.tgbotapi.TestsJsonFormat
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMigratedToSupergroup
|
||||
import dev.inmo.tgbotapi.extensions.utils.asSupergroupChatCreated
|
||||
import dev.inmo.tgbotapi.extensions.utils.asSupergroupEventMessage
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertIs
|
||||
import kotlin.test.fail
|
||||
|
||||
|
||||
@@ -47,6 +45,6 @@ class MigratedToSupergroupTest {
|
||||
val data = message.data.asSupergroupEventMessage() ?: fail("message should be of SupergroupEventMessage subtype")
|
||||
val event = data.chatEvent.asMigratedToSupergroup() ?: fail("event should be of SupergroupChatCreated subtype")
|
||||
|
||||
assertEquals(ChatId(57005), event.migratedFrom)
|
||||
assertEquals(IdChatIdentifier(57005), event.migratedFrom)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user