mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
replace username to full
This commit is contained in:
parent
294f80032c
commit
0f5bce592b
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 == '@' })
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user