diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendQuizPoll.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendQuizPoll.kt index bf808cef80..b427e33d5f 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendQuizPoll.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendQuizPoll.kt @@ -24,6 +24,10 @@ public suspend fun TelegramBot.sendQuizPoll( explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -47,6 +51,10 @@ public suspend fun TelegramBot.sendQuizPoll( explanationParseMode = explanationParseMode, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -71,6 +79,10 @@ public suspend fun TelegramBot.sendQuizPoll( explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -93,6 +105,10 @@ public suspend fun TelegramBot.sendQuizPoll( explanationParseMode = explanationParseMode, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -113,10 +129,13 @@ public suspend fun TelegramBot.sendQuizPoll( question: String, options: List, correctOptionIds: List, - explanationTextSources: List? = null, questionParseMode: ParseMode? = null, + explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -139,6 +158,9 @@ public suspend fun TelegramBot.sendQuizPoll( explanationTextSources = explanationTextSources, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + descriptionTextSources = descriptionTextSources, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -154,7 +176,6 @@ public suspend fun TelegramBot.sendQuizPoll( ) ) - public suspend fun TelegramBot.sendQuizPoll( chatId: ChatIdentifier, questionEntities: List, @@ -163,6 +184,9 @@ public suspend fun TelegramBot.sendQuizPoll( explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -184,6 +208,9 @@ public suspend fun TelegramBot.sendQuizPoll( explanationTextSources = explanationTextSources, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + descriptionTextSources = descriptionTextSources, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -205,11 +232,15 @@ public suspend fun TelegramBot.sendQuizPoll( options: List, correctOptionIds: List, closeInfo: ScheduledCloseInfo?, - questionParseMode: ParseMode? = null, explanation: String?, + questionParseMode: ParseMode? = null, explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -232,6 +263,10 @@ public suspend fun TelegramBot.sendQuizPoll( explanationParseMode = explanationParseMode, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, @@ -255,6 +290,10 @@ public suspend fun TelegramBot.sendQuizPoll( explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -276,6 +315,10 @@ public suspend fun TelegramBot.sendQuizPoll( explanationParseMode = explanationParseMode, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, @@ -299,6 +342,9 @@ public suspend fun TelegramBot.sendQuizPoll( explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -320,6 +366,9 @@ public suspend fun TelegramBot.sendQuizPoll( explanationTextSources = explanationTextSources, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + descriptionTextSources = descriptionTextSources, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, @@ -342,6 +391,9 @@ public suspend fun TelegramBot.sendQuizPoll( explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -362,6 +414,9 @@ public suspend fun TelegramBot.sendQuizPoll( explanationTextSources = explanationTextSources, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + descriptionTextSources = descriptionTextSources, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendRegularPoll.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendRegularPoll.kt index 6043d361d4..bc44222ba7 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendRegularPoll.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendRegularPoll.kt @@ -22,6 +22,12 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -43,6 +49,12 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -51,10 +63,10 @@ public suspend fun TelegramBot.sendRegularPoll( disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, - effectId = effectId, - suggestedPostParameters = suggestedPostParameters, - replyParameters = replyParameters, - replyMarkup = replyMarkup + effectId = effectId, + suggestedPostParameters = suggestedPostParameters, + replyParameters = replyParameters, + replyMarkup = replyMarkup ) ) @@ -65,6 +77,12 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -85,6 +103,12 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -93,10 +117,10 @@ public suspend fun TelegramBot.sendRegularPoll( disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, - effectId = effectId, - suggestedPostParameters = suggestedPostParameters, - replyParameters = replyParameters, - replyMarkup = replyMarkup + effectId = effectId, + suggestedPostParameters = suggestedPostParameters, + replyParameters = replyParameters, + replyMarkup = replyMarkup ) ) @@ -109,6 +133,12 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -129,16 +159,22 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, - effectId = effectId, - suggestedPostParameters = suggestedPostParameters, - replyParameters = replyParameters, - replyMarkup = replyMarkup + effectId = effectId, + suggestedPostParameters = suggestedPostParameters, + replyParameters = replyParameters, + replyMarkup = replyMarkup ) ) @@ -150,6 +186,12 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -169,15 +211,21 @@ public suspend fun TelegramBot.sendRegularPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, disableNotification = disableNotification, protectContent = protectContent, allowPaidBroadcast = allowPaidBroadcast, - effectId = effectId, - suggestedPostParameters = suggestedPostParameters, - replyParameters = replyParameters, - replyMarkup = replyMarkup + effectId = effectId, + suggestedPostParameters = suggestedPostParameters, + replyParameters = replyParameters, + replyMarkup = replyMarkup ) ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index a4c1e33502..c201adbf6a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -49,6 +49,12 @@ fun SendPoll( questionParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -59,14 +65,20 @@ fun SendPoll( replyParameters: ReplyParameters? = null, replyMarkup: KeyboardMarkup? = null ) = SendRegularPoll( - chatId, - question, - options, - null, - questionParseMode, - isAnonymous, - isClosed, - false, + chatId = chatId, + question = question, + options = options, + closeInfo = null, + questionParseMode = questionParseMode, + isAnonymous = isAnonymous, + isClosed = isClosed, + allowMultipleAnswers = false, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, @@ -84,6 +96,12 @@ fun SendPoll( options: List, isAnonymous: Boolean = true, isClosed: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -101,6 +119,12 @@ fun SendPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = false, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, @@ -149,7 +173,7 @@ fun Poll.createRequest( replyParameters = replyParameters, replyMarkup = replyMarkup ) - is QuizPoll -> correctOptionIds ?.let { correctOptionIds -> + is QuizPoll -> correctOptionIds?.let { correctOptionIds -> SendQuizPoll( chatId = chatId, questionEntities = textSources, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendQuizPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendQuizPoll.kt index 2b22f81c6d..575780dc5e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendQuizPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendQuizPoll.kt @@ -39,12 +39,22 @@ class SendQuizPoll internal constructor( override val isAnonymous: Boolean = true, @SerialName(isClosedField) override val isClosed: Boolean = false, + @SerialName(shuffleOptionsField) + val shuffleOptions: Boolean = false, + @SerialName(hideResultsUntilClosesField) + val hideResultsUntilCloses: Boolean = false, @SerialName(explanationField) val explanation: String? = null, @SerialName(explanationParseModeField) val explanationParseMode: ParseMode? = null, @SerialName(explanationEntitiesField) private val rawExplanationEntities: List? = null, + @SerialName(descriptionField) + val description: String? = null, + @SerialName(descriptionParseModeField) + val descriptionParseMode: ParseMode? = null, + @SerialName(descriptionEntitiesField) + private val rawDescriptionEntities: List? = null, @SerialName(openPeriodField) override val openPeriod: LongSeconds? = null, @SerialName(closeDateField) @@ -80,7 +90,10 @@ class SendQuizPoll internal constructor( override val textSources: List get() = rawQuestionEntities.asTextSources(question) val explanationTextEntities: List? by lazy { - rawExplanationEntities ?.asTextSources(text ?: return@lazy null) + rawExplanationEntities?.asTextSources(text ?: return@lazy null) + } + val descriptionTextSources: List? by lazy { + rawDescriptionEntities?.asTextSources(description ?: return@lazy null) } constructor( @@ -93,6 +106,10 @@ class SendQuizPoll internal constructor( explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -114,9 +131,14 @@ class SendQuizPoll internal constructor( rawQuestionEntities = emptyList(), isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, explanation = explanation, explanationParseMode = explanationParseMode, rawExplanationEntities = emptyList(), + description = description, + descriptionParseMode = descriptionParseMode, + rawDescriptionEntities = null, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -140,6 +162,10 @@ class SendQuizPoll internal constructor( explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -161,9 +187,14 @@ class SendQuizPoll internal constructor( rawQuestionEntities = questionEntities.toRawMessageEntities(), isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, explanation = explanation, explanationParseMode = explanationParseMode, rawExplanationEntities = emptyList(), + description = description, + descriptionParseMode = descriptionParseMode, + rawDescriptionEntities = null, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -187,6 +218,9 @@ class SendQuizPoll internal constructor( explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -208,9 +242,14 @@ class SendQuizPoll internal constructor( rawQuestionEntities = emptyList(), isAnonymous = isAnonymous, isClosed = isClosed, - explanation = explanationTextSources ?.makeSourceString(), + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + explanation = explanationTextSources?.makeSourceString(), explanationParseMode = null, - rawExplanationEntities = explanationTextSources ?.toRawMessageEntities(), + rawExplanationEntities = explanationTextSources?.toRawMessageEntities(), + description = descriptionTextSources?.makeSourceString(), + descriptionParseMode = null, + rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(), openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -233,6 +272,9 @@ class SendQuizPoll internal constructor( explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, @@ -254,9 +296,14 @@ class SendQuizPoll internal constructor( rawQuestionEntities = questionEntities.toRawMessageEntities(), isAnonymous = isAnonymous, isClosed = isClosed, - explanation = explanationTextSources ?.makeSourceString(), + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + explanation = explanationTextSources?.makeSourceString(), explanationParseMode = null, - rawExplanationEntities = explanationTextSources ?.toRawMessageEntities(), + rawExplanationEntities = explanationTextSources?.toRawMessageEntities(), + description = descriptionTextSources?.makeSourceString(), + descriptionParseMode = null, + rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(), openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -273,7 +320,7 @@ class SendQuizPoll internal constructor( init { checkPollInfo(question, options) - closeInfo ?.checkSendData() + closeInfo?.checkSendData() val correctOptionIdsRange = 0 until options.size correctOptionIds?.forEach { id -> if (id !in correctOptionIdsRange) { @@ -299,6 +346,10 @@ fun SendQuizPoll( explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -319,6 +370,10 @@ fun SendQuizPoll( explanationParseMode = explanationParseMode, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod, closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate, threadId = threadId, @@ -343,6 +398,10 @@ fun SendQuizPoll( explanationParseMode: ParseMode? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -362,6 +421,10 @@ fun SendQuizPoll( explanationParseMode = explanationParseMode, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod, closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate, threadId = threadId, @@ -386,6 +449,9 @@ fun SendQuizPoll( explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -405,6 +471,9 @@ fun SendQuizPoll( explanationTextSources = explanationTextSources, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + descriptionTextSources = descriptionTextSources, openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod, closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate, threadId = threadId, @@ -428,6 +497,9 @@ fun SendQuizPoll( explanationTextSources: List? = null, isAnonymous: Boolean = true, isClosed: Boolean = false, + shuffleOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -446,6 +518,9 @@ fun SendQuizPoll( explanationTextSources = explanationTextSources, isAnonymous = isAnonymous, isClosed = isClosed, + shuffleOptions = shuffleOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + descriptionTextSources = descriptionTextSources, openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod, closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate, threadId = threadId, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendRegularPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendRegularPoll.kt index 3011d3a487..b250f86e78 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendRegularPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendRegularPoll.kt @@ -40,8 +40,22 @@ class SendRegularPoll constructor( override val isClosed: Boolean = false, @SerialName(allowsMultipleAnswersField) val allowMultipleAnswers: Boolean = false, + @SerialName(allowsRevotingField) + val allowsRevoting: Boolean = true, + @SerialName(shuffleOptionsField) + val shuffleOptions: Boolean = false, + @SerialName(allowAddingOptionsField) + val allowAddingOptions: Boolean = false, + @SerialName(hideResultsUntilClosesField) + val hideResultsUntilCloses: Boolean = false, + @SerialName(descriptionField) + val description: String? = null, + @SerialName(descriptionParseModeField) + val descriptionParseMode: ParseMode? = null, + @SerialName(descriptionEntitiesField) + private val rawDescriptionEntities: List? = null, @SerialName(openPeriodField) - override val openPeriod: LongSeconds?= null, + override val openPeriod: LongSeconds? = null, @SerialName(closeDateField) override val closeDate: LongSeconds? = null, @OptIn(ExperimentalSerializationApi::class) @@ -71,6 +85,9 @@ class SendRegularPoll constructor( ) : SendPoll() { override val textSources: List get() = rawQuestionEntities.asTextSources(text) + val descriptionTextSources: List? by lazy { + rawDescriptionEntities?.asTextSources(description ?: return@lazy null) + } constructor( chatId: ChatIdentifier, @@ -79,7 +96,13 @@ class SendRegularPoll constructor( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, - openPeriod: LongSeconds?= null, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, + openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, @@ -100,6 +123,13 @@ class SendRegularPoll constructor( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, + rawDescriptionEntities = null, openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -122,7 +152,13 @@ class SendRegularPoll constructor( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, - openPeriod: LongSeconds?= null, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, + openPeriod: LongSeconds? = null, closeDate: LongSeconds? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, @@ -143,6 +179,122 @@ class SendRegularPoll constructor( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, + rawDescriptionEntities = null, + openPeriod = openPeriod, + closeDate = closeDate, + threadId = threadId, + directMessageThreadId = directMessageThreadId, + businessConnectionId = businessConnectionId, + disableNotification = disableNotification, + protectContent = protectContent, + allowPaidBroadcast = allowPaidBroadcast, + effectId = effectId, + suggestedPostParameters = suggestedPostParameters, + replyParameters = replyParameters, + replyMarkup = replyMarkup + ) + + constructor( + chatId: ChatIdentifier, + question: String, + options: List, + questionParseMode: ParseMode? = null, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, + openPeriod: LongSeconds? = null, + closeDate: LongSeconds? = null, + threadId: MessageThreadId? = chatId.threadId, + directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, + businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, + disableNotification: Boolean = false, + protectContent: Boolean = false, + allowPaidBroadcast: Boolean = false, + effectId: EffectId? = null, + suggestedPostParameters: SuggestedPostParameters? = null, + replyParameters: ReplyParameters? = null, + replyMarkup: KeyboardMarkup? = null + ) : this( + chatId = chatId, + question = question, + options = options, + questionParseMode = questionParseMode, + rawQuestionEntities = emptyList(), + isAnonymous = isAnonymous, + isClosed = isClosed, + allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = descriptionTextSources?.makeSourceString(), + descriptionParseMode = null, + rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(), + openPeriod = openPeriod, + closeDate = closeDate, + threadId = threadId, + directMessageThreadId = directMessageThreadId, + businessConnectionId = businessConnectionId, + disableNotification = disableNotification, + protectContent = protectContent, + allowPaidBroadcast = allowPaidBroadcast, + effectId = effectId, + suggestedPostParameters = suggestedPostParameters, + replyParameters = replyParameters, + replyMarkup = replyMarkup + ) + + constructor( + chatId: ChatIdentifier, + questionEntities: List, + options: List, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + descriptionTextSources: List? = null, + openPeriod: LongSeconds? = null, + closeDate: LongSeconds? = null, + threadId: MessageThreadId? = chatId.threadId, + directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, + businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, + disableNotification: Boolean = false, + protectContent: Boolean = false, + allowPaidBroadcast: Boolean = false, + effectId: EffectId? = null, + suggestedPostParameters: SuggestedPostParameters? = null, + replyParameters: ReplyParameters? = null, + replyMarkup: KeyboardMarkup? = null + ) : this( + chatId = chatId, + question = questionEntities.makeSourceString(), + options = options, + questionParseMode = null, + rawQuestionEntities = questionEntities.toRawMessageEntities(), + isAnonymous = isAnonymous, + isClosed = isClosed, + allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = descriptionTextSources?.makeSourceString(), + descriptionParseMode = null, + rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(), openPeriod = openPeriod, closeDate = closeDate, threadId = threadId, @@ -163,7 +315,7 @@ class SendRegularPoll constructor( init { checkPollInfo(question, options) - closeInfo ?.checkSendData() + closeInfo?.checkSendData() } } @@ -176,6 +328,12 @@ fun SendRegularPoll( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -194,8 +352,14 @@ fun SendRegularPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, - openPeriod = (closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod, - closeDate = (closeInfo as? ExactScheduledCloseInfo) ?.closeDate, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, + openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod, + closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, @@ -216,6 +380,12 @@ fun SendRegularPoll( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -233,8 +403,14 @@ fun SendRegularPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, - openPeriod = (closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod, - closeDate = (closeInfo as? ExactScheduledCloseInfo) ?.closeDate, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, + openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod, + closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, @@ -254,6 +430,12 @@ fun SendRegularPoll( isAnonymous: Boolean = true, isClosed: Boolean = false, allowMultipleAnswers: Boolean = false, + allowsRevoting: Boolean = true, + shuffleOptions: Boolean = false, + allowAddingOptions: Boolean = false, + hideResultsUntilCloses: Boolean = false, + description: String? = null, + descriptionParseMode: ParseMode? = null, threadId: MessageThreadId? = chatId.threadId, directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId, businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId, @@ -273,6 +455,12 @@ fun SendRegularPoll( isAnonymous = isAnonymous, isClosed = isClosed, allowMultipleAnswers = allowMultipleAnswers, + allowsRevoting = allowsRevoting, + shuffleOptions = shuffleOptions, + allowAddingOptions = allowAddingOptions, + hideResultsUntilCloses = hideResultsUntilCloses, + description = description, + descriptionParseMode = descriptionParseMode, threadId = threadId, directMessageThreadId = directMessageThreadId, businessConnectionId = businessConnectionId, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 72950380fc..622b66715d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -100,7 +100,7 @@ val mediaCountInMediaGroup: IntRange = 2 .. 10 val explanationLimit = 0 .. 200 -val openPeriodPollSecondsLimit = 5 .. 600 +val openPeriodPollSecondsLimit = 5 .. 2628000 val membersLimit = 1 .. 99999 @@ -278,11 +278,19 @@ const val lastErrorDateField = "last_error_date" const val lastSynchronizationErrorDateField = "last_synchronization_error_date" const val lastErrorMessageField = "last_error_message" const val votesCountField = "voter_count" +const val addedByUserField = "added_by_user" +const val addedByChatField = "added_by_chat" +const val additionDateField = "addition_date" +const val persistentIdField = "persistent_id" const val isClosedField = "is_closed" const val totalVoterCountField = "total_voter_count" const val correctOptionIdField = "correct_option_id" const val correctOptionIdsField = "correct_option_ids" const val allowsMultipleAnswersField = "allows_multiple_answers" +const val allowsRevotingField = "allows_revoting" +const val shuffleOptionsField = "shuffle_options" +const val allowAddingOptionsField = "allow_adding_options" +const val hideResultsUntilClosesField = "hide_results_until_closes" const val isAnonymousField = "is_anonymous" const val canManageTopicsField = "can_manage_topics" const val canEditTagField = "can_edit_tag" @@ -598,6 +606,8 @@ const val chatTypeField = "chat_type" const val explanationEntitiesField = "explanation_entities" const val explanationParseModeField = "explanation_parse_mode" +const val descriptionParseModeField = "description_parse_mode" +const val descriptionEntitiesField = "description_entities" const val openPeriodField = "open_period" const val closeDateField = "close_date" const val openingMinuteField = "opening_minute" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollOption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollOption.kt index 6ca674a90b..ea318dfae8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollOption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/PollOption.kt @@ -1,13 +1,13 @@ package dev.inmo.tgbotapi.types.polls import dev.inmo.tgbotapi.abstracts.TextedInput +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.Chat +import dev.inmo.tgbotapi.types.chat.User import dev.inmo.tgbotapi.types.message.RawMessageEntity import dev.inmo.tgbotapi.types.message.asTextSources import dev.inmo.tgbotapi.types.message.textsources.TextSource import dev.inmo.tgbotapi.types.message.toRawMessageEntities -import dev.inmo.tgbotapi.types.textEntitiesField -import dev.inmo.tgbotapi.types.textField -import dev.inmo.tgbotapi.types.votesCountField import dev.inmo.tgbotapi.utils.EntitiesBuilder import dev.inmo.tgbotapi.utils.EntitiesBuilderBody import dev.inmo.tgbotapi.utils.RiskFeature @@ -17,75 +17,220 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -@Serializable(PollOptionSerializer::class) -sealed class PollOption : TextedInput { - abstract val votes: Int +@Serializable +private data class PollOptionSurrogate( + @SerialName(persistentIdField) + val id: PollOptionPersistentId, + @SerialName(textField) + val text: String, + @SerialName(textEntitiesField) + val textEntities: List = emptyList(), + @SerialName(votesCountField) + val votes: Int = 0, + @SerialName(addedByUserField) + val addedByUser: User? = null, + @SerialName(addedByChatField) + val addedByChat: Chat? = null, + @Serializable(TelegramDateSerializer::class) + @SerialName(additionDateField) + val additionDate: TelegramDate? = null +) - abstract fun asInput(): InputPollOption +@Serializable(PollOption.Companion::class) +sealed interface PollOption : TextedInput { + val id: PollOptionPersistentId + val votes: Int + + fun asInput(): InputPollOption + + @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(PollOption.Companion::class) + data class Simple( + @SerialName(persistentIdField) + override val id: PollOptionPersistentId, + @SerialName(textField) + override val text: String, + @SerialName(textEntitiesField) + override val textSources: List = emptyList(), + @SerialName(votesCountField) + override val votes: Int = 0 + ) : PollOption { + override fun asInput(): InputPollOption = InputPollOption(text, null, textSources) + } + + @Serializable(PollOption.LatelyAdded.Companion::class) + sealed interface LatelyAdded : PollOption { + val additionDate: TelegramDate? + + @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(PollOption.LatelyAdded.Companion::class) + data class AddedByUser( + @SerialName(persistentIdField) + override val id: PollOptionPersistentId, + @SerialName(textField) + override val text: String, + @SerialName(textEntitiesField) + override val textSources: List = emptyList(), + @SerialName(votesCountField) + override val votes: Int = 0, + @SerialName(addedByUserField) + val addedByUser: User, + @Serializable(TelegramDateSerializer::class) + @SerialName(additionDateField) + override val additionDate: TelegramDate? = null + ) : LatelyAdded { + override fun asInput(): InputPollOption = InputPollOption(text, null, textSources) + } + + @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(PollOption.LatelyAdded.Companion::class) + data class AddedByChat( + @SerialName(persistentIdField) + override val id: PollOptionPersistentId, + @SerialName(textField) + override val text: String, + @SerialName(textEntitiesField) + override val textSources: List = emptyList(), + @SerialName(votesCountField) + override val votes: Int = 0, + @SerialName(addedByChatField) + val addedByChat: Chat, + @Serializable(TelegramDateSerializer::class) + @SerialName(additionDateField) + override val additionDate: TelegramDate? = null + ) : LatelyAdded { + override fun asInput(): InputPollOption = InputPollOption(text, null, textSources) + } + + @RiskFeature + companion object : KSerializer { + override val descriptor: SerialDescriptor = PollOptionSurrogate.serializer().descriptor + + override fun deserialize(decoder: Decoder): LatelyAdded { + val surrogate = PollOptionSurrogate.serializer().deserialize(decoder) + val textSources = surrogate.textEntities.asTextSources(surrogate.text) + return when { + surrogate.addedByUser != null -> AddedByUser( + surrogate.id, surrogate.text, textSources, surrogate.votes, + surrogate.addedByUser, surrogate.additionDate + ) + surrogate.addedByChat != null -> AddedByChat( + surrogate.id, surrogate.text, textSources, surrogate.votes, + surrogate.addedByChat, surrogate.additionDate + ) + else -> error("LatelyAdded poll option must have either added_by_user or added_by_chat") + } + } + + override fun serialize(encoder: Encoder, value: LatelyAdded) { + PollOptionSurrogate.serializer().serialize( + encoder, + when (value) { + is AddedByUser -> PollOptionSurrogate( + id = value.id, + text = value.text, + textEntities = value.textSources.toRawMessageEntities(), + votes = value.votes, + addedByUser = value.addedByUser, + additionDate = value.additionDate + ) + is AddedByChat -> PollOptionSurrogate( + id = value.id, + text = value.text, + textEntities = value.textSources.toRawMessageEntities(), + votes = value.votes, + addedByChat = value.addedByChat, + additionDate = value.additionDate + ) + } + ) + } + } + } + + @RiskFeature + companion object : KSerializer { + override val descriptor: SerialDescriptor = PollOptionSurrogate.serializer().descriptor - companion object { fun simple( + id: PollOptionPersistentId, text: String, textSources: List, votes: Int = 0 - ) = SimplePollOption(text, textSources, votes) + ) = Simple(id, text, textSources, votes) fun simple( + id: PollOptionPersistentId, textSources: List, votes: Int = 0 - ) = SimplePollOption(textSources.makeSourceString(), textSources, votes) + ) = Simple(id, textSources.makeSourceString(), textSources, votes) fun simple( + id: PollOptionPersistentId, votes: Int = 0, builder: EntitiesBuilderBody ) = simple( + id, EntitiesBuilder().apply(builder).build(), votes ) - } -} -@Suppress("SERIALIZER_TYPE_INCOMPATIBLE") -@Serializable(PollOptionSerializer::class) -data class SimplePollOption ( - @SerialName(textField) - override val text: String, - @SerialName(textEntitiesField) - override val textSources: List = emptyList(), - @SerialName(votesCountField) - override val votes: Int = 0 -) : PollOption() { - override fun asInput(): InputPollOption = InputPollOption(text, null, textSources) -} - -@RiskFeature -object PollOptionSerializer : KSerializer { - @Serializable - private data class RawPollOption( - @SerialName(textField) - val text: String, - @SerialName(textEntitiesField) - val textSources: List = emptyList(), - @SerialName(votesCountField) - val votes: Int = 0 - ) - override val descriptor: SerialDescriptor = RawPollOption.serializer().descriptor - - override fun deserialize(decoder: Decoder): PollOption { - val raw = RawPollOption.serializer().deserialize( - decoder - ) - - return SimplePollOption(raw.text, raw.textSources.asTextSources(raw.text), raw.votes) - } - - override fun serialize(encoder: Encoder, value: PollOption) { - when (value) { - is SimplePollOption -> RawPollOption.serializer().serialize( - encoder, - RawPollOption( - value.text, - value.textSources.toRawMessageEntities(), - value.votes + override fun deserialize(decoder: Decoder): PollOption { + val surrogate = PollOptionSurrogate.serializer().deserialize(decoder) + val textSources = surrogate.textEntities.asTextSources(surrogate.text) + return when { + surrogate.addedByUser != null -> LatelyAdded.AddedByUser( + id = surrogate.id, + text = surrogate.text, + textSources = textSources, + votes = surrogate.votes, + addedByUser = surrogate.addedByUser, + additionDate = surrogate.additionDate ) + surrogate.addedByChat != null -> LatelyAdded.AddedByChat( + id = surrogate.id, + text = surrogate.text, + textSources = textSources, + votes = surrogate.votes, + addedByChat = surrogate.addedByChat, + additionDate = surrogate.additionDate + ) + else -> Simple( + id = surrogate.id, + text = surrogate.text, + textSources = textSources, + votes = surrogate.votes + ) + } + } + + override fun serialize(encoder: Encoder, value: PollOption) { + PollOptionSurrogate.serializer().serialize( + encoder, + when (value) { + is Simple -> PollOptionSurrogate( + id = value.id, + text = value.text, + textEntities = value.textSources.toRawMessageEntities(), + votes = value.votes + ) + is LatelyAdded -> when (value) { + is LatelyAdded.AddedByUser -> PollOptionSurrogate( + id = value.id, + text = value.text, + textEntities = value.textSources.toRawMessageEntities(), + votes = value.votes, + addedByUser = value.addedByUser, + additionDate = value.additionDate + ) + is LatelyAdded.AddedByChat -> PollOptionSurrogate( + id = value.id, + text = value.text, + textEntities = value.textSources.toRawMessageEntities(), + votes = value.votes, + addedByChat = value.addedByChat, + additionDate = value.additionDate + ) + } + } ) } }