mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
fixes in Username
This commit is contained in:
parent
063a43922c
commit
45ba325f1b
@ -22,6 +22,10 @@ work with media groups lists
|
||||
|
||||
### 0.10.2
|
||||
|
||||
* Fixes in `Username`
|
||||
* Now you can create username object using string which is not starting with `@`
|
||||
* Now `Username` correctly comparing with strings, which are not starting with `@`
|
||||
|
||||
## 0.9.0
|
||||
|
||||
* Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in
|
||||
|
@ -19,12 +19,19 @@ fun Identifier.toChatId(): ChatId = ChatId(this)
|
||||
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
data class Username(
|
||||
val username: String
|
||||
private val baseUsername: String
|
||||
) : ChatIdentifier() {
|
||||
init {
|
||||
if (!username.startsWith("@")) {
|
||||
throw IllegalArgumentException("Username must starts with `@`")
|
||||
}
|
||||
@Transient
|
||||
val username: String = if (!baseUsername.startsWith("@")) {
|
||||
"@$baseUsername"
|
||||
} else {
|
||||
baseUsername
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super.equals(other) || other ?.let {
|
||||
super.equals("@$it")
|
||||
} ?: false
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user