From a17af67f83d2a23758bcdb80facd399dd220aa32 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 11 Dec 2019 10:18:12 +0600 Subject: [PATCH] User as PrivateChat --- CHANGELOG.md | 4 ++++ .../MessageEntity/TextMentionMessageEntity.kt | 15 ++++++++++++--- .../insanusmokrassar/TelegramBotAPI/types/User.kt | 11 ++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a66d7ccd..e8c33ba0ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ ### 0.20.1 +* `User` now implement `PrivateChat` +* `TextMentionMessageEntity` now accept `PrivateChat` instead of `User` in main constructor + * `TextMentionMessageEntity` now contains not user, but contains `PrivateChat` + ## 0.19.0 ImplicitReflection removing * Total rework of serialization for requests. Now all `SimpleRequest` children have: diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt index 4bbe2ea2da..41e2eb1f48 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt @@ -1,14 +1,23 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity import com.github.insanusmokrassar.TelegramBotAPI.types.User +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown class TextMentionMessageEntity( override val offset: Int, override val length: Int, override val sourceString: String, - val user: User + val privateChat: PrivateChat ) : MessageEntity { - override val asMarkdownSource: String = sourceString.mentionMarkdown(user.id) - override val asHtmlSource: String = sourceString.mentionMarkdown(user.id) + @Deprecated("Deprecated due to the fact that there is more common constructor") + constructor( + offset: Int, + length: Int, + sourceString: String, + user: User + ) : this(offset, length, sourceString, user as PrivateChat) + + override val asMarkdownSource: String = sourceString.mentionMarkdown(privateChat.id) + override val asHtmlSource: String = sourceString.mentionMarkdown(privateChat.id) } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt index d3c99ba12a..7e2e291df5 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt @@ -1,19 +1,20 @@ package com.github.insanusmokrassar.TelegramBotAPI.types +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class User( - val id: ChatId, + override val id: ChatId, @SerialName(isBotField) val isBot: Boolean = false, @SerialName(firstNameField) - val firstName: String, + override val firstName: String, @SerialName(lastNameField) - val lastName: String? = null, + override val lastName: String = "", @SerialName(usernameField) - val username: Username? = null, + override val username: Username? = null, @SerialName(languageCodeField) val languageCode: String? = null -) +) : PrivateChat