mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-03-03 17:32:23 +00:00
improvements(?) in users api
This commit is contained in:
@@ -125,7 +125,7 @@ val UserId.userLink: String
|
||||
val User.userLink: String
|
||||
get() = id.toChatId().userLink
|
||||
|
||||
typealias UserId = ChatId
|
||||
typealias UserId = IdChatIdentifier
|
||||
|
||||
fun RawChatId.toChatId(): ChatId = ChatId(this)
|
||||
fun Long.toChatId(): ChatId = ChatId(RawChatId(this))
|
||||
|
||||
@@ -758,7 +758,12 @@ internal data class RawMessage(
|
||||
is PrivateForumChatImpl -> chat.copy(id = chatId)
|
||||
is CommonUser -> chat
|
||||
is CommonBot -> chat
|
||||
is PrivateChatImpl -> chat
|
||||
is PrivateChatImpl -> PrivateForumChatImpl(
|
||||
id = chatId,
|
||||
username = chat.username,
|
||||
firstName = chat.firstName,
|
||||
lastName = chat.lastName
|
||||
)
|
||||
}
|
||||
PrivateForumContentMessageImpl(
|
||||
messageId = messageId,
|
||||
|
||||
@@ -17,9 +17,9 @@ data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstr
|
||||
val user: User,
|
||||
override val subsources: TextSourcesList
|
||||
) : MultilevelTextSource {
|
||||
override val markdown: String by lazy { source.textMentionMarkdown(user.id) }
|
||||
override val markdownV2: String by lazy { textMentionMarkdownV2(user.id) }
|
||||
override val html: String by lazy { textMentionHTML(user.id) }
|
||||
override val markdown: String by lazy { source.textMentionMarkdown(user.id.toChatId()) }
|
||||
override val markdownV2: String by lazy { textMentionMarkdownV2(user.id.toChatId()) }
|
||||
override val html: String by lazy { textMentionHTML(user.id.toChatId()) }
|
||||
}
|
||||
|
||||
fun mentionTextSource(parts: TextSourcesList, user: User) = TextMentionTextSource(parts.makeString(), user, parts)
|
||||
|
||||
@@ -52,6 +52,7 @@ object EncryptedElementSerializer : KSerializer<EncryptedPassportElement> {
|
||||
val json = value.let {
|
||||
encryptedElementsClassesByTypes.forEach { (key, encapsulator) ->
|
||||
val json = encapsulator.encapsulate(value) { data ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
nonstrictJsonFormat.encodeToJsonElement(this as KSerializer<EncryptedPassportElement>, data).jsonObject
|
||||
} ?: return@forEach
|
||||
return@let JsonObject(json + (typeField to JsonPrimitive(key)))
|
||||
|
||||
@@ -23,7 +23,7 @@ data class UsersShared(
|
||||
) : this(requestId, listOf(user))
|
||||
|
||||
override val chatId: ChatId
|
||||
get() = userId
|
||||
get() = userId.toChatId()
|
||||
|
||||
companion object {
|
||||
operator fun invoke(
|
||||
|
||||
@@ -6,10 +6,11 @@ fun <T : Throwable> Throwable.causedBy(kclass: KClass<T>, additionalFilterOnHapp
|
||||
var current = this
|
||||
while (kclass.isInstance(current) == false) {
|
||||
when {
|
||||
kclass.isInstance(current) -> return additionalFilterOnHappened(current as T)
|
||||
kclass.isInstance(current) -> @Suppress("UNCHECKED_CAST") return additionalFilterOnHappened(current as T)
|
||||
else -> current = current.cause ?: return null
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return current as T
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import dev.inmo.tgbotapi.types.toChatId
|
||||
|
||||
/**
|
||||
* Trying to convert current [PrivateChat] to [User]
|
||||
@@ -18,6 +19,6 @@ fun PrivateChat.toUser(): User = when (this) {
|
||||
is ExtendedBot -> this
|
||||
is ExtendedPrivateChatImpl -> CommonUser(id, firstName, lastName, username)
|
||||
is PrivateChatImpl -> CommonUser(id, firstName, lastName, username)
|
||||
is ExtendedPrivateForumChatImpl -> CommonUser(id, firstName, lastName, username)
|
||||
is PrivateForumChatImpl -> CommonUser(id, firstName, lastName, username)
|
||||
is ExtendedPrivateForumChatImpl -> CommonUser(id.toChatId(), firstName, lastName, username)
|
||||
is PrivateForumChatImpl -> CommonUser(id.toChatId(), firstName, lastName, username)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user