From ffbc8883e27b8efd4422d08e65b3b29b84733247 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 30 Mar 2023 16:53:09 +0400 Subject: [PATCH] Add chat limit screen --- .../TelegramEngine/Peers/Communities.swift | 17 +++++++++++++++-- .../Sources/ChatFolderLinkPreviewScreen.swift | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift index 7e9bd8910f..098552f869 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift @@ -362,7 +362,7 @@ public enum JoinChatFolderLinkError { case generic case dialogFilterLimitExceeded(limit: Int32, premiumLimit: Int32) case sharedFolderLimitExceeded(limit: Int32, premiumLimit: Int32) - case tooManyChannels + case tooManyChannels(limit: Int32, premiumLimit: Int32) } func _internal_joinChatFolderLink(account: Account, slug: String, peerIds: [EnginePeer.Id]) -> Signal { @@ -374,7 +374,20 @@ func _internal_joinChatFolderLink(account: Account, slug: String, peerIds: [Engi return account.network.request(Api.functions.communities.joinCommunityInvite(slug: slug, peers: inputPeers)) |> `catch` { error -> Signal in if error.errorDescription == "USER_CHANNELS_TOO_MUCH" { - return .fail(.tooManyChannels) + return account.postbox.transaction { transaction -> (AppConfiguration, Bool) in + return (currentAppConfiguration(transaction: transaction), transaction.getPeer(account.peerId)?.isPremium ?? false) + } + |> castError(JoinChatFolderLinkError.self) + |> mapToSignal { appConfiguration, isPremium -> Signal in + let userDefaultLimits = UserLimitsConfiguration(appConfiguration: appConfiguration, isPremium: false) + let userPremiumLimits = UserLimitsConfiguration(appConfiguration: appConfiguration, isPremium: true) + + if isPremium { + return .fail(.tooManyChannels(limit: userPremiumLimits.maxFolderChatsCount, premiumLimit: userPremiumLimits.maxFolderChatsCount)) + } else { + return .fail(.tooManyChannels(limit: userDefaultLimits.maxFolderChatsCount, premiumLimit: userPremiumLimits.maxFolderChatsCount)) + } + } } else if error.errorDescription == "DIALOG_FILTERS_TOO_MUCH" { return account.postbox.transaction { transaction -> (AppConfiguration, Bool) in return (currentAppConfiguration(transaction: transaction), transaction.getPeer(account.peerId)?.isPremium ?? false) diff --git a/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift b/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift index d280a7adfd..56efdfe6c6 100644 --- a/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift +++ b/submodules/TelegramUI/Components/ChatFolderLinkPreviewScreen/Sources/ChatFolderLinkPreviewScreen.swift @@ -757,6 +757,10 @@ private final class ChatFolderLinkPreviewScreenComponent: Component { let limitController = PremiumLimitScreen(context: component.context, subject: .membershipInSharedFolders, count: limit, action: {}) controller.push(limitController) controller.dismiss() + case let .tooManyChannels(limit, _): + let limitController = PremiumLimitScreen(context: component.context, subject: .chatsPerFolder, count: limit, action: {}) + controller.push(limitController) + controller.dismiss() } }, completed: { [weak self] in guard let self, let controller = self.environment?.controller() else {