1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

replace username to full

This commit is contained in:
InsanusMokrassar 2024-01-09 11:45:12 +06:00
parent 294f80032c
commit 0f5bce592b
3 changed files with 6 additions and 6 deletions

View File

@ -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<ChatIdentifier> {
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<ChatIdentifier> {
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)
}
}
}

View File

@ -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 == '@' })

View File

@ -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
}
}