From 43204554cd3199754fe5d1941d692214acc8b471 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 9 Feb 2024 02:06:06 +0400 Subject: [PATCH] Group boosts --- .../Telegram-iOS/en.lproj/Localizable.strings | 2 + .../Sources/AccountContext.swift | 2 +- .../TelegramUI/Sources/ChatController.swift | 17 ++++- .../TelegramUI/Sources/OpenResolvedUrl.swift | 69 +++++++++++-------- .../UrlHandling/Sources/UrlHandling.swift | 6 +- .../UrlWhitelist/Sources/UrlWhitelist.swift | 4 ++ 6 files changed, 65 insertions(+), 35 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 48f4824125..ea2f5d4539 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -11258,3 +11258,5 @@ Sorry for the inconvenience."; "BoostGift.Members.SectionTitle" = "MEMBERS"; "BoostGift.Members.Search" = "Search Members"; "BoostGift.Members.MaximumReached" = "You can select maximum %@ members."; + +"Chat.ErrorCantBoost" = "Sorry, you can't boost this group or channel."; diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index 4ad8ef2d68..622cd477cb 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -304,7 +304,7 @@ public enum ResolvedUrl { case premiumOffer(reference: String?) case chatFolder(slug: String) case story(peerId: PeerId, id: Int32) - case boost(peerId: PeerId, status: ChannelBoostStatus?, myBoostStatus: MyBoostStatus?) + case boost(peerId: PeerId?, status: ChannelBoostStatus?, myBoostStatus: MyBoostStatus?) case premiumGiftCode(slug: String) case premiumMultiGift(reference: String?) } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 184a26d742..9edd072f24 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -120,6 +120,7 @@ import VideoMessageCameraScreen import TopMessageReactions import PeerInfoScreen import AudioWaveform +import PeerNameColorScreen public enum ChatControllerPeekActions { case standard @@ -961,11 +962,21 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.presentThemeSelection() return true case let .setChatWallpaper(wallpaper, _): - guard message.effectivelyIncoming(strongSelf.context.account.peerId), let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer else { - strongSelf.presentThemeSelection() + guard let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer else { return true } - if peer is TelegramChannel { + if let peer = peer as? TelegramChannel, peer.hasPermission(.changeInfo) { + let _ = (context.engine.peers.getChannelBoostStatus(peerId: peer.id) + |> deliverOnMainQueue).start(next: { [weak self] boostStatus in + guard let self else { + return + } + self.push(ChannelAppearanceScreen(context: self.context, updatedPresentationData: self.updatedPresentationData, peerId: peer.id, boostStatus: boostStatus)) + }) + return true + } + guard message.effectivelyIncoming(strongSelf.context.account.peerId), let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer else { + strongSelf.presentThemeSelection() return true } strongSelf.chatDisplayNode.dismissInput() diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index 2c35372a74..8cb1dbeab5 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -866,18 +866,6 @@ func openResolvedUrlImpl( } }) case let .boost(peerId, status, myBoostStatus): - guard let status else { - return - } - var isCurrent = false - if case let .chat(chatPeerId, _, _) = urlContext, chatPeerId == peerId { - isCurrent = true - } - var forceDark = false - if let updatedPresentationData, updatedPresentationData.initial.theme.overallDarkAppearance { - forceDark = true - } - var dismissedImpl: (() -> Void)? if let storyProgressPauseContext = contentContext as? StoryProgressPauseContext { let updateExternalController = storyProgressPauseContext.update @@ -886,24 +874,45 @@ func openResolvedUrlImpl( } } - let controller = PremiumBoostLevelsScreen( - context: context, - peerId: peerId, - mode: .user(mode: isCurrent ? .current : .external), - status: status, - myBoostStatus: myBoostStatus, - openPeer: { peer in - openPeer(peer, .chat(textInputState: nil, subject: nil, peekData: nil)) - }, - forceDark: forceDark - ) - controller.disposed = { - dismissedImpl?() - } - navigationController?.pushViewController(controller) - - if let storyProgressPauseContext = contentContext as? StoryProgressPauseContext { - storyProgressPauseContext.update(controller) + if let peerId, let status { + var isCurrent = false + if case let .chat(chatPeerId, _, _) = urlContext, chatPeerId == peerId { + isCurrent = true + } + var forceDark = false + if let updatedPresentationData, updatedPresentationData.initial.theme.overallDarkAppearance { + forceDark = true + } + let controller = PremiumBoostLevelsScreen( + context: context, + peerId: peerId, + mode: .user(mode: isCurrent ? .current : .external), + status: status, + myBoostStatus: myBoostStatus, + openPeer: { peer in + openPeer(peer, .chat(textInputState: nil, subject: nil, peekData: nil)) + }, + forceDark: forceDark + ) + controller.disposed = { + dismissedImpl?() + } + navigationController?.pushViewController(controller) + + if let storyProgressPauseContext = contentContext as? StoryProgressPauseContext { + storyProgressPauseContext.update(controller) + } + } else { + let controller = textAlertController(context: context, updatedPresentationData: updatedPresentationData, title: nil, text: presentationData.strings.Chat_ErrorCantBoost, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]) + present(controller, nil) + + controller.dismissed = { _ in + dismissedImpl?() + } + + if let storyProgressPauseContext = contentContext as? StoryProgressPauseContext { + storyProgressPauseContext.update(controller) + } } case let .premiumGiftCode(slug): var forceDark = false diff --git a/submodules/UrlHandling/Sources/UrlHandling.swift b/submodules/UrlHandling/Sources/UrlHandling.swift index db5e176a26..ce2eb0457b 100644 --- a/submodules/UrlHandling/Sources/UrlHandling.swift +++ b/submodules/UrlHandling/Sources/UrlHandling.swift @@ -787,7 +787,11 @@ private func resolveInternalUrl(context: AccountContext, url: ParsedInternalUrl) return .single(.result(.peer(peer._asPeer(), .chat(textInputState: nil, subject: nil, peekData: nil)))) } } else { - return .single(.result(.peer(nil, .info(nil)))) + if case .boost = parameter { + return .single(.result(.boost(peerId: nil, status: nil, myBoostStatus: nil))) + } else { + return .single(.result(.peer(nil, .info(nil)))) + } } } case let .peerId(peerId): diff --git a/submodules/UrlWhitelist/Sources/UrlWhitelist.swift b/submodules/UrlWhitelist/Sources/UrlWhitelist.swift index 2b76a6938d..267db299b7 100644 --- a/submodules/UrlWhitelist/Sources/UrlWhitelist.swift +++ b/submodules/UrlWhitelist/Sources/UrlWhitelist.swift @@ -86,5 +86,9 @@ public func parseUrl(url: String, wasConcealed: Bool) -> (string: String, concea concealed = false } + if url.hasPrefix("tg://premium_multigift") || url.hasPrefix("tg://premium_offer") { + concealed = false + } + return (rawDisplayUrl, concealed) }