mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-03 23:29:33 +00:00
refactor: merged GiftInfo and UniqueGiftInfo into one sealed interface
This commit is contained in:
@@ -10,45 +10,62 @@ import kotlin.jvm.JvmName
|
||||
|
||||
|
||||
@Serializable
|
||||
data class GiftInfo private constructor(
|
||||
@SerialName(giftField)
|
||||
val gift: Gift,
|
||||
@SerialName(ownedGiftIdField)
|
||||
val ownedGiftId: GiftId? = null,
|
||||
@SerialName(convertStarCountField)
|
||||
val convertStarCount: Int? = null,
|
||||
@SerialName(prepaidUpgradeStarCountField)
|
||||
val prepaidUpgradeStarCount: Int? = null,
|
||||
@SerialName(canBeUpgradedField)
|
||||
val canBeUpgraded: Boolean = false,
|
||||
@SerialName(textField)
|
||||
val text: String? = null,
|
||||
@SerialName(entitiesField)
|
||||
val entities: RawMessageEntities = emptyList(),
|
||||
@SerialName(isPrivateField)
|
||||
val isPrivate: Boolean = false
|
||||
) {
|
||||
companion object {
|
||||
@JvmName("PublicConstructor")
|
||||
operator fun invoke(
|
||||
gift: Gift,
|
||||
ownedGiftId: GiftId? = null,
|
||||
convertStarCount: Int? = null,
|
||||
prepaidUpgradeStarCount: Int? = null,
|
||||
canBeUpgraded: Boolean = false,
|
||||
text: String? = null,
|
||||
textSources: TextSourcesList = emptyList(),
|
||||
position: Int,
|
||||
isPrivate: Boolean = false
|
||||
) = GiftInfo(
|
||||
gift,
|
||||
ownedGiftId,
|
||||
convertStarCount,
|
||||
prepaidUpgradeStarCount,
|
||||
canBeUpgraded,
|
||||
text,
|
||||
textSources.toRawMessageEntities(position),
|
||||
isPrivate
|
||||
)
|
||||
sealed interface GiftInfo {
|
||||
val ownedGiftId: GiftId?
|
||||
|
||||
@Serializable
|
||||
data class Regular(
|
||||
@SerialName(giftField)
|
||||
val gift: Gift,
|
||||
@SerialName(ownedGiftIdField)
|
||||
override val ownedGiftId: GiftId? = null,
|
||||
@SerialName(convertStarCountField)
|
||||
val convertStarCount: Int? = null,
|
||||
@SerialName(prepaidUpgradeStarCountField)
|
||||
val prepaidUpgradeStarCount: Int? = null,
|
||||
@SerialName(canBeUpgradedField)
|
||||
val canBeUpgraded: Boolean = false,
|
||||
@SerialName(textField)
|
||||
val text: String? = null,
|
||||
@SerialName(entitiesField)
|
||||
val entities: RawMessageEntities = emptyList(),
|
||||
@SerialName(isPrivateField)
|
||||
val isPrivate: Boolean = false
|
||||
) : GiftInfo {
|
||||
companion object {
|
||||
@JvmName("PublicConstructor")
|
||||
operator fun invoke(
|
||||
gift: Gift,
|
||||
ownedGiftId: GiftId? = null,
|
||||
convertStarCount: Int? = null,
|
||||
prepaidUpgradeStarCount: Int? = null,
|
||||
canBeUpgraded: Boolean = false,
|
||||
text: String? = null,
|
||||
textSources: TextSourcesList = emptyList(),
|
||||
position: Int,
|
||||
isPrivate: Boolean = false
|
||||
) = Regular(
|
||||
gift,
|
||||
ownedGiftId,
|
||||
convertStarCount,
|
||||
prepaidUpgradeStarCount,
|
||||
canBeUpgraded,
|
||||
text,
|
||||
textSources.toRawMessageEntities(position),
|
||||
isPrivate
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Unique(
|
||||
@SerialName(giftField)
|
||||
val gift: UniqueGift,
|
||||
@SerialName(originField)
|
||||
val origin: String? = null,
|
||||
@SerialName(ownedGiftIdField)
|
||||
override val ownedGiftId: GiftId? = null,
|
||||
@SerialName(transferStarCountField)
|
||||
val transferStarCount: Int? = null
|
||||
): GiftInfo
|
||||
}
|
||||
|
@@ -1,17 +0,0 @@
|
||||
package dev.inmo.tgbotapi.types.gifts
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class UniqueGiftInfo(
|
||||
@SerialName(giftField)
|
||||
val gift: UniqueGift,
|
||||
@SerialName(originField)
|
||||
val origin: String? = null,
|
||||
@SerialName(ownedGiftIdField)
|
||||
val ownedGiftId: GiftId? = null,
|
||||
@SerialName(transferStarCountField)
|
||||
val transferStarCount: Int? = null
|
||||
)
|
Reference in New Issue
Block a user