From 61a6d4a88036eae7dbac24e1f282e893c3a5cba2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 21 Apr 2023 21:13:15 +0600 Subject: [PATCH] add support of via_chat_folder_invite_link --- .../dev/inmo/tgbotapi/types/ChatIdentifier.kt | 4 +- .../dev/inmo/tgbotapi/types/ChatInviteLink.kt | 37 +++++++++++++++++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 3 +- .../types/chat/member/ChatMemberUpdated.kt | 4 +- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index b005d1b9e9..b870ad90ff 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -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 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt index 91a295a843..4fa5e3507c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt @@ -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 { override val descriptor: SerialDescriptor @@ -179,6 +213,9 @@ object ChatInviteLinkSerializer : KSerializer { inviteLink, creator, name, membersLimit, isRevoked, expirationDateTime ) } + inviteLink.contains(ChatFolderInviteLink.addListLinkPart) -> ChatFolderInviteLinkUnlimited( + inviteLink, creator, name, isRevoked, expirationDateTime + ) else -> ChatInviteLinkUnlimited( inviteLink, creator, name, isRevoked, expirationDateTime ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 11e4e6fbe3..f65b22b650 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -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" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated.kt index 81f4ac184b..c4f7027d6e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/member/ChatMemberUpdated.kt @@ -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