mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
ChatPermissions now is interface
This commit is contained in:
parent
554d47e301
commit
81fdf50217
@ -5,36 +5,32 @@ import kotlinx.serialization.KSerializer
|
|||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
@Serializable
|
/**
|
||||||
data class ChatPermissions(
|
* Represents any type with common permissions list
|
||||||
@SerialName(canSendMessagesField)
|
*
|
||||||
val canSendMessages: Boolean? = null,
|
* !!WARNING!! Default serializer of this interface is using [ChatPermissionsImpl] as surrogate and in fact serialized
|
||||||
@SerialName(canSendAudiosField)
|
* and deserialized as [ChatPermissionsImpl]. In case you wish some custom behaviour you must implement your own
|
||||||
val canSendAudios: Boolean? = null,
|
* [KSerializer] or pass another serializer
|
||||||
@SerialName(canSendDocumentsField)
|
*/
|
||||||
val canSendDocuments: Boolean? = null,
|
@Serializable(ChatPermissions.Companion::class)
|
||||||
@SerialName(canSendPhotosField)
|
interface ChatPermissions {
|
||||||
val canSendPhotos: Boolean? = null,
|
val canSendMessages: Boolean?
|
||||||
@SerialName(canSendVideosField)
|
val canSendAudios: Boolean?
|
||||||
val canSendVideos: Boolean? = null,
|
val canSendDocuments: Boolean?
|
||||||
@SerialName(canSendVideoNotesField)
|
val canSendPhotos: Boolean?
|
||||||
val canSendVideoNotes: Boolean? = null,
|
val canSendVideos: Boolean?
|
||||||
@SerialName(canSendVoiceNotesField)
|
val canSendVideoNotes: Boolean?
|
||||||
val canSendVoiceNotes: Boolean? = null,
|
val canSendVoiceNotes: Boolean?
|
||||||
@SerialName(canSendPollsField)
|
val canSendPolls: Boolean?
|
||||||
val canSendPolls: Boolean? = null,
|
val canSendOtherMessages: Boolean?
|
||||||
@SerialName(canSendOtherMessagesField)
|
val canAddWebPagePreviews: Boolean?
|
||||||
val canSendOtherMessages: Boolean? = null,
|
val canChangeInfo: Boolean?
|
||||||
@SerialName(canAddWebPagePreviewsField)
|
val canInviteUsers: Boolean?
|
||||||
val canAddWebPagePreviews: Boolean? = null,
|
val canPinMessages: Boolean?
|
||||||
@SerialName(canChangeInfoField)
|
|
||||||
val canChangeInfo: Boolean? = null,
|
|
||||||
@SerialName(canInviteUsersField)
|
|
||||||
val canInviteUsers: Boolean? = null,
|
|
||||||
@SerialName(canPinMessagesField)
|
|
||||||
val canPinMessages: Boolean? = null
|
|
||||||
) {
|
|
||||||
@Transient
|
@Transient
|
||||||
val isGranular
|
val isGranular
|
||||||
get() = canSendAudios != null ||
|
get() = canSendAudios != null ||
|
||||||
@ -44,7 +40,37 @@ data class ChatPermissions(
|
|||||||
canSendVideos != null ||
|
canSendVideos != null ||
|
||||||
canSendVoiceNotes != null
|
canSendVoiceNotes != null
|
||||||
|
|
||||||
companion object {
|
companion object : KSerializer<ChatPermissions> {
|
||||||
|
operator fun invoke(
|
||||||
|
canSendMessages: Boolean? = null,
|
||||||
|
canSendAudios: Boolean? = null,
|
||||||
|
canSendDocuments: Boolean? = null,
|
||||||
|
canSendPhotos: Boolean? = null,
|
||||||
|
canSendVideos: Boolean? = null,
|
||||||
|
canSendVideoNotes: Boolean? = null,
|
||||||
|
canSendVoiceNotes: Boolean? = null,
|
||||||
|
canSendPolls: Boolean? = null,
|
||||||
|
canSendOtherMessages: Boolean? = null,
|
||||||
|
canAddWebPagePreviews: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canPinMessages: Boolean? = null
|
||||||
|
) = ChatPermissionsImpl(
|
||||||
|
canSendMessages = canSendMessages,
|
||||||
|
canSendAudios = canSendAudios,
|
||||||
|
canSendDocuments = canSendDocuments,
|
||||||
|
canSendPhotos = canSendPhotos,
|
||||||
|
canSendVideos = canSendVideos,
|
||||||
|
canSendVideoNotes = canSendVideoNotes,
|
||||||
|
canSendVoiceNotes = canSendVoiceNotes,
|
||||||
|
canSendPolls = canSendPolls,
|
||||||
|
canSendOtherMessages = canSendOtherMessages,
|
||||||
|
canAddWebPagePreviews = canAddWebPagePreviews,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canPinMessages = canPinMessages
|
||||||
|
)
|
||||||
|
|
||||||
fun Granular(
|
fun Granular(
|
||||||
canSendMessages: Boolean? = null,
|
canSendMessages: Boolean? = null,
|
||||||
canSendAudios: Boolean? = null,
|
canSendAudios: Boolean? = null,
|
||||||
@ -97,6 +123,37 @@ data class ChatPermissions(
|
|||||||
canInviteUsers = canInviteUsers,
|
canInviteUsers = canInviteUsers,
|
||||||
canPinMessages = canPinMessages
|
canPinMessages = canPinMessages
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val realSerializer = ChatPermissionsImpl.serializer()
|
||||||
|
override val descriptor: SerialDescriptor
|
||||||
|
get() = realSerializer.descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): ChatPermissions {
|
||||||
|
return realSerializer.deserialize(decoder)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: ChatPermissions) {
|
||||||
|
realSerializer.serialize(
|
||||||
|
encoder,
|
||||||
|
(value as? ChatPermissionsImpl) ?: value.run {
|
||||||
|
ChatPermissionsImpl(
|
||||||
|
canSendMessages = canSendMessages,
|
||||||
|
canSendAudios = canSendAudios,
|
||||||
|
canSendDocuments = canSendDocuments,
|
||||||
|
canSendPhotos = canSendPhotos,
|
||||||
|
canSendVideos = canSendVideos,
|
||||||
|
canSendVideoNotes = canSendVideoNotes,
|
||||||
|
canSendVoiceNotes = canSendVoiceNotes,
|
||||||
|
canSendPolls = canSendPolls,
|
||||||
|
canSendOtherMessages = canSendOtherMessages,
|
||||||
|
canAddWebPagePreviews = canAddWebPagePreviews,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canPinMessages = canPinMessages
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.chat
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.Transient
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class ChatPermissionsImpl(
|
||||||
|
@SerialName(canSendMessagesField)
|
||||||
|
override val canSendMessages: Boolean? = null,
|
||||||
|
@SerialName(canSendAudiosField)
|
||||||
|
override val canSendAudios: Boolean? = null,
|
||||||
|
@SerialName(canSendDocumentsField)
|
||||||
|
override val canSendDocuments: Boolean? = null,
|
||||||
|
@SerialName(canSendPhotosField)
|
||||||
|
override val canSendPhotos: Boolean? = null,
|
||||||
|
@SerialName(canSendVideosField)
|
||||||
|
override val canSendVideos: Boolean? = null,
|
||||||
|
@SerialName(canSendVideoNotesField)
|
||||||
|
override val canSendVideoNotes: Boolean? = null,
|
||||||
|
@SerialName(canSendVoiceNotesField)
|
||||||
|
override val canSendVoiceNotes: Boolean? = null,
|
||||||
|
@SerialName(canSendPollsField)
|
||||||
|
override val canSendPolls: Boolean? = null,
|
||||||
|
@SerialName(canSendOtherMessagesField)
|
||||||
|
override val canSendOtherMessages: Boolean? = null,
|
||||||
|
@SerialName(canAddWebPagePreviewsField)
|
||||||
|
override val canAddWebPagePreviews: Boolean? = null,
|
||||||
|
@SerialName(canChangeInfoField)
|
||||||
|
override val canChangeInfo: Boolean? = null,
|
||||||
|
@SerialName(canInviteUsersField)
|
||||||
|
override val canInviteUsers: Boolean? = null,
|
||||||
|
@SerialName(canPinMessagesField)
|
||||||
|
override val canPinMessages: Boolean? = null
|
||||||
|
) : ChatPermissions
|
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.types.chat.member
|
package dev.inmo.tgbotapi.types.chat.member
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
||||||
import dev.inmo.tgbotapi.types.chat.User
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@ -13,25 +14,25 @@ data class RestrictedChatMember(
|
|||||||
@SerialName(isMemberField)
|
@SerialName(isMemberField)
|
||||||
val isMember: Boolean = false,
|
val isMember: Boolean = false,
|
||||||
@SerialName(canSendMessagesField)
|
@SerialName(canSendMessagesField)
|
||||||
val canSendMessages: Boolean = false,
|
override val canSendMessages: Boolean = false,
|
||||||
@SerialName(canSendAudiosField)
|
@SerialName(canSendAudiosField)
|
||||||
val canSendAudios: Boolean = false,
|
override val canSendAudios: Boolean = false,
|
||||||
@SerialName(canSendDocumentsField)
|
@SerialName(canSendDocumentsField)
|
||||||
val canSendDocuments: Boolean = false,
|
override val canSendDocuments: Boolean = false,
|
||||||
@SerialName(canSendPhotosField)
|
@SerialName(canSendPhotosField)
|
||||||
val canSendPhotos: Boolean = false,
|
override val canSendPhotos: Boolean = false,
|
||||||
@SerialName(canSendVideosField)
|
@SerialName(canSendVideosField)
|
||||||
val canSendVideos: Boolean = false,
|
override val canSendVideos: Boolean = false,
|
||||||
@SerialName(canSendVideoNotesField)
|
@SerialName(canSendVideoNotesField)
|
||||||
val canSendVideoNotes: Boolean = false,
|
override val canSendVideoNotes: Boolean = false,
|
||||||
@SerialName(canSendVoiceNotesField)
|
@SerialName(canSendVoiceNotesField)
|
||||||
val canSendVoiceNotes: Boolean = false,
|
override val canSendVoiceNotes: Boolean = false,
|
||||||
@SerialName(canSendPollsField)
|
@SerialName(canSendPollsField)
|
||||||
val canSendPolls: Boolean = false,
|
override val canSendPolls: Boolean = false,
|
||||||
@SerialName(canSendOtherMessagesField)
|
@SerialName(canSendOtherMessagesField)
|
||||||
val canSendOtherMessages: Boolean = false,
|
override val canSendOtherMessages: Boolean = false,
|
||||||
@SerialName(canAddWebPagePreviewsField)
|
@SerialName(canAddWebPagePreviewsField)
|
||||||
val canAddWebpagePreviews: Boolean = false,
|
override val canAddWebPagePreviews: Boolean = false,
|
||||||
@SerialName(canChangeInfoField)
|
@SerialName(canChangeInfoField)
|
||||||
override val canChangeInfo: Boolean = false,
|
override val canChangeInfo: Boolean = false,
|
||||||
@SerialName(canInviteUsersField)
|
@SerialName(canInviteUsersField)
|
||||||
@ -40,7 +41,7 @@ data class RestrictedChatMember(
|
|||||||
override val canPinMessages: Boolean = false,
|
override val canPinMessages: Boolean = false,
|
||||||
@SerialName(canManageTopicsField)
|
@SerialName(canManageTopicsField)
|
||||||
override val canManageTopics: Boolean = false
|
override val canManageTopics: Boolean = false
|
||||||
) : BannedChatMember, SpecialRightsChatMember {
|
) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "restricted"
|
private val type: String = "restricted"
|
||||||
|
Loading…
Reference in New Issue
Block a user