From 9fa17c1360d020e0e4fcade68a9f291beeac4eb3 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Wed, 10 Jul 2024 18:54:30 +0300 Subject: [PATCH] Reused existing code in converters --- .../payments/PaidMediaToTelegramPaidMedia.kt | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/PaidMediaToTelegramPaidMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/PaidMediaToTelegramPaidMedia.kt index f9222f6af9..fe35555b2f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/PaidMediaToTelegramPaidMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/PaidMediaToTelegramPaidMedia.kt @@ -1,27 +1,13 @@ package dev.inmo.tgbotapi.types.message.payments -import dev.inmo.tgbotapi.types.media.TelegramPaidMedia -import dev.inmo.tgbotapi.types.media.TelegramPaidMediaPhoto -import dev.inmo.tgbotapi.types.media.TelegramPaidMediaVideo +import dev.inmo.tgbotapi.types.media.* fun PaidMedia.toTelegramPaidMediaOrNull(): TelegramPaidMedia? = when (this) { - is PaidMedia.Photo -> TelegramPaidMediaPhoto( - file = this.photo.biggest.fileId - ) - is PaidMedia.Video -> TelegramPaidMediaPhoto( - file = this.video.fileId - ) + is PaidMedia.Photo -> toTelegramMediaPhoto() + is PaidMedia.Video -> toTelegramPaidMediaVideo() is PaidMedia.Preview, is PaidMedia.Unknown -> null } -fun PaidMedia.Video.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = TelegramPaidMediaVideo( - file = this.video.fileId, - duration = this.video.duration, - width = this.video.width, - height = this.video.height, - thumb = this.video.thumbnail?.fileId - ) +fun PaidMedia.Video.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = this.video.toTelegramPaidMediaVideo() -fun PaidMedia.Photo.toTelegramMediaPhoto(): TelegramPaidMediaPhoto = TelegramPaidMediaPhoto( - file = this.photo.fileId -) +fun PaidMedia.Photo.toTelegramMediaPhoto(): TelegramPaidMediaPhoto = this.photo.biggest.toTelegramPaidMediaPhoto()