mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-07-03 16:46:06 +00:00
Rework ChatJoinRequestQueryResult + EditChatMessageText nullable text
- ChatJoinRequestQueryResult: enum -> sealed interface (Approve/Decline/ Queue objects + Unknown) with a companion KSerializer using a PrimitiveKind.STRING descriptor (encodeString/decodeString), not String.serializer() - EditChatMessageText: text is now nullable per API; add EditChatMessageRichText factory for rich edits; widen EditTextChatMessage.text to String? Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -6,34 +6,68 @@ import dev.inmo.tgbotapi.types.chatJoinRequestQueryIdField
|
||||
import dev.inmo.tgbotapi.types.resultField
|
||||
import dev.inmo.tgbotapi.utils.serializers.UnitFromBooleanSerializer
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
/**
|
||||
* Result of an [AnswerChatJoinRequestQuery].
|
||||
* Result of an [AnswerChatJoinRequestQuery]. Serialized as a plain string.
|
||||
*
|
||||
* @see <a href="https://core.telegram.org/bots/api#answerchatjoinrequestquery">answerChatJoinRequestQuery</a>
|
||||
*/
|
||||
@Serializable
|
||||
enum class ChatJoinRequestQueryResult {
|
||||
@Serializable(ChatJoinRequestQueryResult.Companion::class)
|
||||
sealed interface ChatJoinRequestQueryResult {
|
||||
val name: String
|
||||
|
||||
/**
|
||||
* Allow the user to join the chat.
|
||||
*/
|
||||
@SerialName("approve")
|
||||
Approve,
|
||||
object Approve : ChatJoinRequestQueryResult {
|
||||
override val name: String = "approve"
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallow the user to join the chat.
|
||||
*/
|
||||
@SerialName("decline")
|
||||
Decline,
|
||||
object Decline : ChatJoinRequestQueryResult {
|
||||
override val name: String = "decline"
|
||||
}
|
||||
|
||||
/**
|
||||
* Leave the decision to other administrators.
|
||||
*/
|
||||
@SerialName("queue")
|
||||
Queue
|
||||
object Queue : ChatJoinRequestQueryResult {
|
||||
override val name: String = "queue"
|
||||
}
|
||||
|
||||
/**
|
||||
* Any other result which is currently unknown to this library.
|
||||
*/
|
||||
data class Unknown(override val name: String) : ChatJoinRequestQueryResult
|
||||
|
||||
companion object : KSerializer<ChatJoinRequestQueryResult> {
|
||||
override val descriptor: SerialDescriptor =
|
||||
PrimitiveSerialDescriptor("dev.inmo.tgbotapi.requests.chat.invite_links.ChatJoinRequestQueryResult", PrimitiveKind.STRING)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatJoinRequestQueryResult) {
|
||||
encoder.encodeString(value.name)
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): ChatJoinRequestQueryResult {
|
||||
return when (val name = decoder.decodeString()) {
|
||||
Approve.name -> Approve
|
||||
Decline.name -> Decline
|
||||
Queue.name -> Queue
|
||||
else -> Unknown(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,5 +3,5 @@ package dev.inmo.tgbotapi.requests.edit.abstracts
|
||||
import dev.inmo.tgbotapi.abstracts.TextedOutput
|
||||
|
||||
interface EditTextChatMessage : TextedOutput {
|
||||
override val text: String
|
||||
override val text: String?
|
||||
}
|
||||
|
||||
@@ -56,6 +56,24 @@ fun EditChatMessageText(
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun EditChatMessageRichText(
|
||||
chatId: ChatIdentifier,
|
||||
messageId: MessageId,
|
||||
richMessage: InputRichMessage,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
replyMarkup: InlineKeyboardMarkup? = null
|
||||
) = EditChatMessageText(
|
||||
chatId = chatId,
|
||||
messageId = messageId,
|
||||
text = null,
|
||||
parseMode = null,
|
||||
rawEntities = null,
|
||||
businessConnectionId = businessConnectionId,
|
||||
linkPreviewOptions = null,
|
||||
replyMarkup = replyMarkup,
|
||||
richMessage = richMessage
|
||||
)
|
||||
|
||||
@ConsistentCopyVisibility
|
||||
@Serializable
|
||||
data class EditChatMessageText internal constructor(
|
||||
@@ -64,7 +82,7 @@ data class EditChatMessageText internal constructor(
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageId,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
override val text: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(entitiesField)
|
||||
@@ -79,7 +97,7 @@ data class EditChatMessageText internal constructor(
|
||||
val richMessage: InputRichMessage? = null
|
||||
) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditLinkPreviewOptionsContainer {
|
||||
override val textSources: TextSourcesList? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
text ?.let { rawEntities ?.asTextSources(it) }
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageTextMethod
|
||||
|
||||
Reference in New Issue
Block a user