From a1b2aed78c75dd4e4e1f328cca384a2cde188f3c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Feb 2019 14:35:58 +0800 Subject: [PATCH] hotfix for username --- CHANGELOG.md | 4 ++++ build.gradle | 2 +- .../TelegramBotAPI/types/ChatIdentifier.kt | 22 ++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2350f49bf3..aae807f2bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ work with media groups lists * Now most part of usernames in library have type `Username` * Fix `replyMarkup` in `InlineQueryResultArticle` +### 0.10.3 + +* Hotfix for username data class + ## 0.9.0 * Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in diff --git a/build.gradle b/build.gradle index 340034426d..9bf5d340ff 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -project.version = "0.10.2" +project.version = "0.10.3" project.group = "com.github.insanusmokrassar" buildscript { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt index 176f3292d3..127e9964d7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatIdentifier.kt @@ -19,19 +19,11 @@ fun Identifier.toChatId(): ChatId = ChatId(this) @Serializable(ChatIdentifierSerializer::class) data class Username( - private val baseUsername: String + val username: String ) : ChatIdentifier() { - @Transient - val username: String = if (!baseUsername.startsWith("@")) { - "@$baseUsername" - } else { - baseUsername - } - - override fun equals(other: Any?): Boolean { - return super.equals(other) || when (other) { - is String -> super.equals("@$other") - else -> false + init { + if (!username.startsWith("@")) { + throw IllegalArgumentException("Username must starts with `@`") } } } @@ -44,7 +36,11 @@ internal class ChatIdentifierSerializer: KSerializer { val id = input.decodeString() return id.toLongOrNull() ?.let { ChatId(it) - } ?: Username(id) + } ?: if (!id.startsWith("@")) { + Username("@$id") + } else { + Username(id) + } } override fun serialize(output: Encoder, obj: ChatIdentifier) {