From aeb6fad4093524da0cd5dd54f7139936159ed6f5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 21 Sep 2021 18:49:29 +0600 Subject: [PATCH] add LocationContent#copy --- .../types/message/content/LocationContent.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt index f00fd71c44..0318a85859 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt @@ -19,6 +19,25 @@ import kotlinx.serialization.encoding.* sealed interface LocationContent : MessageContent { val location: Location + fun copy(location: Location = this.location) { + when (this) { + is LiveLocationContent -> LiveLocationContent( + (location as? LiveLocation) ?: this.location.copy( + longitude = location.longitude, + latitude = location.latitude, + horizontalAccuracy = location.horizontalAccuracy + ) + ) + is StaticLocationContent -> StaticLocationContent( + (location as? StaticLocation) ?: this.location.copy( + longitude = location.longitude, + latitude = location.latitude, + horizontalAccuracy = location.horizontalAccuracy + ) + ) + } + } + companion object { operator fun invoke(location: Location): LocationContent { return when (location) {