1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

update users shared related things

This commit is contained in:
InsanusMokrassar 2024-04-18 15:03:22 +06:00
parent 072264faad
commit c5102590cc
5 changed files with 103 additions and 22 deletions

View File

@ -264,6 +264,10 @@ const val requestUserField = "request_user"
const val requestUsersField = "request_users"
const val requestChatField = "request_chat"
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 userIsBotField = "user_is_bot"

View File

@ -1,15 +1,8 @@
package dev.inmo.tgbotapi.types.buttons
import dev.inmo.tgbotapi.types.botAdministratorRightsField
import dev.inmo.tgbotapi.types.botIsMemberField
import dev.inmo.tgbotapi.types.*
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.requestIdField
import dev.inmo.tgbotapi.types.userAdministratorRightsField
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -34,7 +27,13 @@ data class KeyboardButtonRequestChat(
@SerialName(botAdministratorRightsField)
val botRightsInChat: ChatCommonAdministratorRights? = null,
@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 {
fun Channel(

View File

@ -19,6 +19,9 @@ sealed interface KeyboardButtonRequestUsers {
val isBot: Boolean?
val isPremium: Boolean?
val maxCount: Int
val requestName: Boolean?
val requestUsername: Boolean?
val requestPhoto: Boolean?
@Serializable
data class Any(
@ -27,7 +30,13 @@ sealed interface KeyboardButtonRequestUsers {
@SerialName(userIsPremiumField)
override val isPremium: Boolean? = null,
@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 {
@SerialName(userIsBotField)
@EncodeDefault
@ -41,7 +50,13 @@ sealed interface KeyboardButtonRequestUsers {
@SerialName(userIsPremiumField)
override val isPremium: Boolean? = null,
@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 {
@SerialName(userIsBotField)
@EncodeDefault
@ -53,7 +68,13 @@ sealed interface KeyboardButtonRequestUsers {
@SerialName(requestIdField)
override val requestId: RequestId,
@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 {
@SerialName(userIsBotField)
@EncodeDefault
@ -73,7 +94,13 @@ sealed interface KeyboardButtonRequestUsers {
@SerialName(userIsPremiumField)
val userIsPremium: Boolean? = null,
@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()
@ -83,9 +110,29 @@ sealed interface KeyboardButtonRequestUsers {
val surrogate = realSerializer.deserialize(decoder)
return when (surrogate.userIsBot) {
true -> Bot(surrogate.requestId, surrogate.maxCount)
false -> Common(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
null -> Any(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
true -> Bot(
requestId = surrogate.requestId,
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(
encoder,
Surrogate(
value.requestId,
value.isBot,
(value as? Common) ?.isPremium,
value.maxCount
requestId = value.requestId,
userIsBot = value.isBot,
userIsPremium = (value as? Common) ?.isPremium,
maxCount = value.maxCount,
requestName = value.requestName,
requestUsername = value.requestUsername,
requestPhoto = value.requestPhoto
)
)
}

View File

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

View File

@ -10,7 +10,7 @@ data class UsersShared(
@SerialName(requestIdField)
override val requestId: RequestId,
@SerialName(usersField)
val users: List<PreviewUser>
val users: List<SharedUser>
) : ChatSharedRequest {
val userIds: List<UserId> by lazy {
users.map { it.id }
@ -19,8 +19,16 @@ data class UsersShared(
get() = userIds.first()
constructor(
requestId: RequestId,
user: PreviewUser
user: SharedUser
) : 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
get() = userId
}