mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 09:07:12 +00:00
update users shared related things
This commit is contained in:
parent
072264faad
commit
c5102590cc
@ -264,6 +264,10 @@ const val requestUserField = "request_user"
|
|||||||
const val requestUsersField = "request_users"
|
const val requestUsersField = "request_users"
|
||||||
const val requestChatField = "request_chat"
|
const val requestChatField = "request_chat"
|
||||||
const val requestIdField = "request_id"
|
const val requestIdField = "request_id"
|
||||||
|
const val requestTitleField = "request_title"
|
||||||
|
const val requestUsernameField = "request_username"
|
||||||
|
const val requestPhotoField = "request_photo"
|
||||||
|
const val requestNameField = "request_name"
|
||||||
const val maxQuantityField = "max_quantity"
|
const val maxQuantityField = "max_quantity"
|
||||||
|
|
||||||
const val userIsBotField = "user_is_bot"
|
const val userIsBotField = "user_is_bot"
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.types.buttons
|
package dev.inmo.tgbotapi.types.buttons
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.botAdministratorRightsField
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.botIsMemberField
|
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
import dev.inmo.tgbotapi.types.chatHasUsernameField
|
|
||||||
import dev.inmo.tgbotapi.types.chatIsChannelField
|
|
||||||
import dev.inmo.tgbotapi.types.chatIsCreatedField
|
|
||||||
import dev.inmo.tgbotapi.types.chatIsForumField
|
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.types.requestIdField
|
|
||||||
import dev.inmo.tgbotapi.types.userAdministratorRightsField
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -34,7 +27,13 @@ data class KeyboardButtonRequestChat(
|
|||||||
@SerialName(botAdministratorRightsField)
|
@SerialName(botAdministratorRightsField)
|
||||||
val botRightsInChat: ChatCommonAdministratorRights? = null,
|
val botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
@SerialName(botIsMemberField)
|
@SerialName(botIsMemberField)
|
||||||
val botIsMember: Boolean? = null
|
val botIsMember: Boolean? = null,
|
||||||
|
@SerialName(requestTitleField)
|
||||||
|
val requestTitle: Boolean? = null,
|
||||||
|
@SerialName(requestUsernameField)
|
||||||
|
val requestUsername: Boolean? = null,
|
||||||
|
@SerialName(requestPhotoField)
|
||||||
|
val requestPhoto: Boolean? = null
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun Channel(
|
fun Channel(
|
||||||
|
@ -19,6 +19,9 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
val isBot: Boolean?
|
val isBot: Boolean?
|
||||||
val isPremium: Boolean?
|
val isPremium: Boolean?
|
||||||
val maxCount: Int
|
val maxCount: Int
|
||||||
|
val requestName: Boolean?
|
||||||
|
val requestUsername: Boolean?
|
||||||
|
val requestPhoto: Boolean?
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Any(
|
data class Any(
|
||||||
@ -27,7 +30,13 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
@SerialName(userIsPremiumField)
|
@SerialName(userIsPremiumField)
|
||||||
override val isPremium: Boolean? = null,
|
override val isPremium: Boolean? = null,
|
||||||
@SerialName(maxQuantityField)
|
@SerialName(maxQuantityField)
|
||||||
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
override val maxCount: Int = keyboardButtonRequestUserLimit.first,
|
||||||
|
@SerialName(requestNameField)
|
||||||
|
override val requestName: Boolean? = null,
|
||||||
|
@SerialName(requestUsernameField)
|
||||||
|
override val requestUsername: Boolean? = null,
|
||||||
|
@SerialName(requestPhotoField)
|
||||||
|
override val requestPhoto: Boolean? = null,
|
||||||
) : KeyboardButtonRequestUsers {
|
) : KeyboardButtonRequestUsers {
|
||||||
@SerialName(userIsBotField)
|
@SerialName(userIsBotField)
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
@ -41,7 +50,13 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
@SerialName(userIsPremiumField)
|
@SerialName(userIsPremiumField)
|
||||||
override val isPremium: Boolean? = null,
|
override val isPremium: Boolean? = null,
|
||||||
@SerialName(maxQuantityField)
|
@SerialName(maxQuantityField)
|
||||||
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
override val maxCount: Int = keyboardButtonRequestUserLimit.first,
|
||||||
|
@SerialName(requestNameField)
|
||||||
|
override val requestName: Boolean? = null,
|
||||||
|
@SerialName(requestUsernameField)
|
||||||
|
override val requestUsername: Boolean? = null,
|
||||||
|
@SerialName(requestPhotoField)
|
||||||
|
override val requestPhoto: Boolean? = null,
|
||||||
) : KeyboardButtonRequestUsers {
|
) : KeyboardButtonRequestUsers {
|
||||||
@SerialName(userIsBotField)
|
@SerialName(userIsBotField)
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
@ -53,7 +68,13 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
@SerialName(requestIdField)
|
@SerialName(requestIdField)
|
||||||
override val requestId: RequestId,
|
override val requestId: RequestId,
|
||||||
@SerialName(maxQuantityField)
|
@SerialName(maxQuantityField)
|
||||||
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
override val maxCount: Int = keyboardButtonRequestUserLimit.first,
|
||||||
|
@SerialName(requestNameField)
|
||||||
|
override val requestName: Boolean? = null,
|
||||||
|
@SerialName(requestUsernameField)
|
||||||
|
override val requestUsername: Boolean? = null,
|
||||||
|
@SerialName(requestPhotoField)
|
||||||
|
override val requestPhoto: Boolean? = null,
|
||||||
) : KeyboardButtonRequestUsers {
|
) : KeyboardButtonRequestUsers {
|
||||||
@SerialName(userIsBotField)
|
@SerialName(userIsBotField)
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
@ -73,7 +94,13 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
@SerialName(userIsPremiumField)
|
@SerialName(userIsPremiumField)
|
||||||
val userIsPremium: Boolean? = null,
|
val userIsPremium: Boolean? = null,
|
||||||
@SerialName(maxQuantityField)
|
@SerialName(maxQuantityField)
|
||||||
val maxCount: Int = keyboardButtonRequestUserLimit.first
|
val maxCount: Int = keyboardButtonRequestUserLimit.first,
|
||||||
|
@SerialName(requestNameField)
|
||||||
|
val requestName: Boolean? = null,
|
||||||
|
@SerialName(requestUsernameField)
|
||||||
|
val requestUsername: Boolean? = null,
|
||||||
|
@SerialName(requestPhotoField)
|
||||||
|
val requestPhoto: Boolean? = null,
|
||||||
)
|
)
|
||||||
private val realSerializer = Surrogate.serializer()
|
private val realSerializer = Surrogate.serializer()
|
||||||
|
|
||||||
@ -83,9 +110,29 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
val surrogate = realSerializer.deserialize(decoder)
|
val surrogate = realSerializer.deserialize(decoder)
|
||||||
|
|
||||||
return when (surrogate.userIsBot) {
|
return when (surrogate.userIsBot) {
|
||||||
true -> Bot(surrogate.requestId, surrogate.maxCount)
|
true -> Bot(
|
||||||
false -> Common(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
|
requestId = surrogate.requestId,
|
||||||
null -> Any(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
|
maxCount = surrogate.maxCount,
|
||||||
|
requestName = surrogate.requestName,
|
||||||
|
requestUsername = surrogate.requestUsername,
|
||||||
|
requestPhoto = surrogate.requestPhoto
|
||||||
|
)
|
||||||
|
false -> Common(
|
||||||
|
requestId = surrogate.requestId,
|
||||||
|
isPremium = surrogate.userIsPremium,
|
||||||
|
maxCount = surrogate.maxCount,
|
||||||
|
requestName = surrogate.requestName,
|
||||||
|
requestUsername = surrogate.requestUsername,
|
||||||
|
requestPhoto = surrogate.requestPhoto
|
||||||
|
)
|
||||||
|
null -> Any(
|
||||||
|
requestId = surrogate.requestId,
|
||||||
|
isPremium = surrogate.userIsPremium,
|
||||||
|
maxCount = surrogate.maxCount,
|
||||||
|
requestName = surrogate.requestName,
|
||||||
|
requestUsername = surrogate.requestUsername,
|
||||||
|
requestPhoto = surrogate.requestPhoto
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +140,13 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
realSerializer.serialize(
|
realSerializer.serialize(
|
||||||
encoder,
|
encoder,
|
||||||
Surrogate(
|
Surrogate(
|
||||||
value.requestId,
|
requestId = value.requestId,
|
||||||
value.isBot,
|
userIsBot = value.isBot,
|
||||||
(value as? Common) ?.isPremium,
|
userIsPremium = (value as? Common) ?.isPremium,
|
||||||
value.maxCount
|
maxCount = value.maxCount,
|
||||||
|
requestName = value.requestName,
|
||||||
|
requestUsername = value.requestUsername,
|
||||||
|
requestPhoto = value.requestPhoto
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.request
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.files.Photo
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class SharedUser(
|
||||||
|
@SerialName(userIdField)
|
||||||
|
val id: UserId,
|
||||||
|
@SerialName(firstNameField)
|
||||||
|
val firstName: String? = null,
|
||||||
|
@SerialName(lastNameField)
|
||||||
|
val lastName: String? = null,
|
||||||
|
@SerialName(usernameField)
|
||||||
|
val username: Username? = null,
|
||||||
|
@SerialName(photoField)
|
||||||
|
val photo: Photo? = null,
|
||||||
|
)
|
@ -10,7 +10,7 @@ data class UsersShared(
|
|||||||
@SerialName(requestIdField)
|
@SerialName(requestIdField)
|
||||||
override val requestId: RequestId,
|
override val requestId: RequestId,
|
||||||
@SerialName(usersField)
|
@SerialName(usersField)
|
||||||
val users: List<PreviewUser>
|
val users: List<SharedUser>
|
||||||
) : ChatSharedRequest {
|
) : ChatSharedRequest {
|
||||||
val userIds: List<UserId> by lazy {
|
val userIds: List<UserId> by lazy {
|
||||||
users.map { it.id }
|
users.map { it.id }
|
||||||
@ -19,8 +19,16 @@ data class UsersShared(
|
|||||||
get() = userIds.first()
|
get() = userIds.first()
|
||||||
constructor(
|
constructor(
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
user: PreviewUser
|
user: SharedUser
|
||||||
) : this(requestId, listOf(user))
|
) : this(requestId, listOf(user))
|
||||||
|
constructor(
|
||||||
|
requestId: RequestId,
|
||||||
|
userIds: List<UserId>
|
||||||
|
) : this(requestId, userIds.map { SharedUser(it) })
|
||||||
|
constructor(
|
||||||
|
requestId: RequestId,
|
||||||
|
userId: UserId
|
||||||
|
) : this(requestId, SharedUser(userId))
|
||||||
override val chatId: ChatId
|
override val chatId: ChatId
|
||||||
get() = userId
|
get() = userId
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user