fixes in Username

This commit is contained in:
InsanusMokrassar 2019-02-17 21:12:56 +08:00
parent 063a43922c
commit 45ba325f1b
2 changed files with 16 additions and 5 deletions

View File

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

View File

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