diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 30270966cd..e065b7ba2e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -99,7 +99,7 @@ value class Username( get() = withoutAt init { - if (!username.startsWith("@")) { + if (!full.startsWith("@")) { throw IllegalArgumentException("Username must starts with `@`") } } @@ -132,7 +132,7 @@ object ChatIdentifierSerializer : KSerializer { override fun serialize(encoder: Encoder, value: ChatIdentifier) { when (value) { is IdChatIdentifier -> encoder.encodeLong(value.chatId) - is Username -> encoder.encodeString(value.username) + is Username -> encoder.encodeString(value.full) } } } @@ -170,7 +170,7 @@ object FullChatIdentifierSerializer : KSerializer { when (value) { is ChatId -> encoder.encodeLong(value.chatId) is ChatIdWithThreadId -> encoder.encodeString("${value.chatId}/${value.threadId}") - is Username -> encoder.encodeString(value.username) + is Username -> encoder.encodeString(value.full) } } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/MentionTextSource.kt index e8f49ecb44..933293694d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/MentionTextSource.kt @@ -45,5 +45,5 @@ inline fun mention(vararg parts: TextSource) = mention(parts.toList()) inline fun mention(whoToMention: String) = mention(regular(whoToMention)) @Suppress("NOTHING_TO_INLINE") -inline fun mention(whoToMention: Username) = mention(whoToMention.username.dropWhile { it == '@' }) +inline fun mention(whoToMention: Username) = mention(whoToMention.full.dropWhile { it == '@' }) diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt index 004de4dc0f..98fd148b1e 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/ChatIdentifierTests.kt @@ -33,10 +33,10 @@ class ChatIdentifierTests { @Test fun `Cast_from_String_to_Username_is_working_correctly`() { - assertEquals(testUsername, testUsername.toUsername().username) + assertEquals(testUsername, testUsername.toUsername().full) assertFails("Username creating must fail when trying to create from string which is not starting from @ symbol") { - testUsername.replace("@", "").toUsername().username + testUsername.replace("@", "").toUsername().full } }