1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

add support of via_chat_folder_invite_link

This commit is contained in:
InsanusMokrassar 2023-04-21 21:13:15 +06:00
parent e37237cb71
commit 61a6d4a880
4 changed files with 44 additions and 4 deletions

View File

@ -13,9 +13,9 @@ import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.longOrNull
import kotlin.jvm.JvmInline
const val internalTgLinksBeginning = "tg://"
const val internalTgAppLinksBeginning = "tg://"
const val internalLinkBeginning = "https://t.me"
const val internalUserLinkBeginning = "${internalTgLinksBeginning}user?id="
const val internalUserLinkBeginning = "${internalTgAppLinksBeginning}user?id="
@Serializable(ChatIdentifierSerializer::class)
@ClassCastsIncluded

View File

@ -157,6 +157,40 @@ data class ChatInviteLinkUnlimited(
get() = expireDate ?.asDate
}
/**
* Base interface for all [ChatInviteLink]s which are NOT [PrimaryInviteLink]
*/
@Serializable(ChatInviteLinkSerializer::class)
sealed interface ChatFolderInviteLink : ChatInviteLink {
override val isPrimary: Boolean
get() = false
companion object {
const val addListLinkPart = "addlist"
}
}
/**
* Represent [SecondaryChatInviteLink] which have no any restrictions like [ChatInviteLinkWithJoinRequest] or
* [ChatInviteLinkWithLimitedMembers]
*/
@Serializable
data class ChatFolderInviteLinkUnlimited(
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(creatorField)
override val creator: User,
@SerialName(nameField)
override val name: String? = null,
@SerialName(isRevokedField)
override val isRevoked: Boolean = false,
@SerialName(expireDateField)
private val expireDate: TelegramDate? = null,
) : ChatFolderInviteLink {
override val expirationDateTime: DateTime?
get() = expireDate ?.asDate
}
@RiskFeature
object ChatInviteLinkSerializer : KSerializer<ChatInviteLink> {
override val descriptor: SerialDescriptor
@ -179,6 +213,9 @@ object ChatInviteLinkSerializer : KSerializer<ChatInviteLink> {
inviteLink, creator, name, membersLimit, isRevoked, expirationDateTime
)
}
inviteLink.contains(ChatFolderInviteLink.addListLinkPart) -> ChatFolderInviteLinkUnlimited(
inviteLink, creator, name, isRevoked, expirationDateTime
)
else -> ChatInviteLinkUnlimited(
inviteLink, creator, name, isRevoked, expirationDateTime
)

View File

@ -43,7 +43,7 @@ value class CustomEmojiId(
val string: String
) {
val appLink
get() = "${internalTgLinksBeginning}emoji?id=$this"
get() = "${internalTgAppLinksBeginning}emoji?id=$this"
}
typealias Seconds = Int
@ -278,6 +278,7 @@ const val switchInlineQueryField = "switch_inline_query"
const val isAnimatedField = "is_animated"
const val isVideoField = "is_video"
const val inviteLinkField = "invite_link"
const val viaChatFolderInviteLinkField = "via_chat_folder_invite_link"
const val pinnedMessageField = "pinned_message"
const val activeUsernamesField = "active_usernames"
const val customTitleField = "custom_title"

View File

@ -21,5 +21,7 @@ data class ChatMemberUpdated(
@SerialName(newChatMemberField)
val newChatMemberState: ChatMember,
@SerialName(inviteLinkField)
val inviteLink: ChatInviteLink? = null
val inviteLink: ChatInviteLink? = null,
@SerialName(viaChatFolderInviteLinkField)
val viaChatFolderInviteLink: Boolean? = inviteLink is ChatFolderInviteLink
) : WithChat, WithUser