1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-16 13:49:26 +00:00

MessageId is value class now

This commit is contained in:
2024-03-16 19:45:23 +06:00
parent b559dbbe66
commit 4a1989fb79
12 changed files with 662 additions and 780 deletions

View File

@@ -27,25 +27,6 @@ fun ForwardMessages(
removeCaption = removeCaption
)
fun ForwardMessages(
toChatId: ChatIdentifier,
fromChatId: ChatIdentifier,
messageId: MessageId,
vararg messageIds: MessageId,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
) = ForwardMessages(
toChatId = toChatId,
fromChatId = fromChatId,
messageIds = (listOf(messageId) + messageIds.toList()),
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
@Serializable
data class ForwardMessages (
@SerialName(chatIdField)

View File

@@ -33,25 +33,6 @@ fun CopyMessages(
removeCaption = removeCaption
)
fun CopyMessages(
toChatId: ChatIdentifier,
fromChatId: ChatIdentifier,
messageId: MessageId,
vararg messageIds: MessageId,
threadId: MessageThreadId? = toChatId.threadId,
disableNotification: Boolean = false,
protectContent: Boolean = false,
removeCaption: Boolean = false
) = CopyMessages(
toChatId = toChatId,
fromChatId = fromChatId,
messageIds = (listOf(messageId) + messageIds.toList()),
threadId = threadId,
disableNotification = disableNotification,
protectContent = protectContent,
removeCaption = removeCaption
)
@Serializable
data class CopyMessages (
@SerialName(chatIdField)

View File

@@ -10,7 +10,6 @@ import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.JvmInline
typealias Identifier = Long
typealias MessageId = Long
typealias MessageThreadId = Long
typealias MessageIdentifier = MessageId
typealias InlineQueryIdentifier = String

View File

@@ -1,24 +1,34 @@
package dev.inmo.tgbotapi.types
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
import kotlin.jvm.JvmInline
object MessageIdSerializer : KSerializer<MessageId> {
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
override fun deserialize(decoder: Decoder): MessageId = JsonObject.serializer().deserialize(decoder)[messageIdField]!!.jsonPrimitive.long
override fun deserialize(decoder: Decoder): MessageId = JsonObject.serializer().deserialize(decoder)[messageIdField]!!.jsonPrimitive.long.asTelegramMessageId()
override fun serialize(encoder: Encoder, value: MessageId) {
JsonObject.serializer().serialize(
encoder,
JsonObject(
mapOf(
messageIdField to JsonPrimitive(value)
messageIdField to JsonPrimitive(value.long)
)
)
)
}
}
@Serializable
@JvmInline
value class MessageId(
val long: Long
)
fun Long.asTelegramMessageId() = MessageId(this)

View File

@@ -124,7 +124,7 @@ inline fun requestUsersOrBotsReplyButton(
inline fun requestUserOrBotReplyButton(
text: String,
requestId: RequestId
) = requestUserReplyButton(
) = requestUsersReplyButton(
text,
KeyboardButtonRequestUsers.Any(requestId)
)