mirror of
				https://github.com/InsanusMokrassar/TelegramBotAPI.git
				synced 2025-10-27 10:10:24 +00:00 
			
		
		
		
	Merge pull request #20 from InsanusMokrassar/0.10.3
hotfix for username
This commit is contained in:
		| @@ -28,6 +28,10 @@ work with media groups lists | |||||||
| * Now most part of usernames in library have type `Username` | * Now most part of usernames in library have type `Username` | ||||||
| * Fix `replyMarkup` in `InlineQueryResultArticle` | * Fix `replyMarkup` in `InlineQueryResultArticle` | ||||||
|  |  | ||||||
|  | ### 0.10.3 | ||||||
|  |  | ||||||
|  | * Hotfix for username data class | ||||||
|  |  | ||||||
| ## 0.9.0 | ## 0.9.0 | ||||||
|  |  | ||||||
| * Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in | * Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| project.version = "0.10.2" | project.version = "0.10.3" | ||||||
| project.group = "com.github.insanusmokrassar" | project.group = "com.github.insanusmokrassar" | ||||||
|  |  | ||||||
| buildscript { | buildscript { | ||||||
|   | |||||||
| @@ -19,19 +19,11 @@ fun Identifier.toChatId(): ChatId = ChatId(this) | |||||||
|  |  | ||||||
| @Serializable(ChatIdentifierSerializer::class) | @Serializable(ChatIdentifierSerializer::class) | ||||||
| data class Username( | data class Username( | ||||||
|     private val baseUsername: String |     val username: String | ||||||
| ) : ChatIdentifier() { | ) : ChatIdentifier() { | ||||||
|     @Transient |     init { | ||||||
|     val username: String = if (!baseUsername.startsWith("@")) { |         if (!username.startsWith("@")) { | ||||||
|         "@$baseUsername" |             throw IllegalArgumentException("Username must starts with `@`") | ||||||
|     } else { |  | ||||||
|         baseUsername |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     override fun equals(other: Any?): Boolean { |  | ||||||
|         return super.equals(other) || when (other) { |  | ||||||
|             is String -> super.equals("@$other") |  | ||||||
|             else -> false |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -44,7 +36,11 @@ internal class ChatIdentifierSerializer: KSerializer<ChatIdentifier> { | |||||||
|         val id = input.decodeString() |         val id = input.decodeString() | ||||||
|         return id.toLongOrNull() ?.let { |         return id.toLongOrNull() ?.let { | ||||||
|             ChatId(it) |             ChatId(it) | ||||||
|         } ?: Username(id) |         } ?: if (!id.startsWith("@")) { | ||||||
|  |             Username("@$id") | ||||||
|  |         } else { | ||||||
|  |             Username(id) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun serialize(output: Encoder, obj: ChatIdentifier) { |     override fun serialize(output: Encoder, obj: ChatIdentifier) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user