From ab0faf8073fdaa1406d2b3a5952f8928f77297fc Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 14 Sep 2023 18:16:51 +0400 Subject: [PATCH] Various fixes --- .../Sources/AccountContext.swift | 2 +- .../Sources/PremiumLimitScreen.swift | 35 ++++++++++++------- .../Sources/ChannelStatsController.swift | 2 +- .../Sources/MediaEditorScreen.swift | 6 ++-- .../TelegramUI/Sources/OpenResolvedUrl.swift | 9 +++-- submodules/TelegramUI/Sources/OpenUrl.swift | 2 +- .../Sources/SharedAccountContext.swift | 4 +-- .../Sources/TelegramRootController.swift | 5 --- .../UrlHandling/Sources/UrlHandling.swift | 12 +++++-- 9 files changed, 49 insertions(+), 28 deletions(-) diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index 03e94d166e..b25c0e1b89 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -987,7 +987,7 @@ public enum PremiumLimitSubject { case expiringStories case storiesWeekly case storiesMonthly - case storiesChannelBoost(peer: EnginePeer, level: Int32, currentLevelBoosts: Int32, nextLevelBoosts: Int32?, link: String?, boosted: Bool) + case storiesChannelBoost(peer: EnginePeer, isCurrent: Bool, level: Int32, currentLevelBoosts: Int32, nextLevelBoosts: Int32?, link: String?, boosted: Bool) } public protocol ComposeController: ViewController { diff --git a/submodules/PremiumUI/Sources/PremiumLimitScreen.swift b/submodules/PremiumUI/Sources/PremiumLimitScreen.swift index 5f11653f81..2459882848 100644 --- a/submodules/PremiumUI/Sources/PremiumLimitScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumLimitScreen.swift @@ -774,7 +774,12 @@ private final class LimitSheetContent: CombinedComponent { let subject = component.subject let premiumConfiguration = PremiumConfiguration.with(appConfiguration: component.context.currentAppConfiguration.with { $0 }) - let isPremiumDisabled = premiumConfiguration.isPremiumDisabled + let isPremiumDisabled: Bool + if case .storiesChannelBoost = subject { + isPremiumDisabled = false + } else { + isPremiumDisabled = premiumConfiguration.isPremiumDisabled + } let sideInset: CGFloat = 16.0 + environment.safeInsets.left let textSideInset: CGFloat = 32.0 + environment.safeInsets.left @@ -1027,8 +1032,8 @@ private final class LimitSheetContent: CombinedComponent { string = strings.Premium_MaxStoriesMonthlyNoPremiumText("\(limit)").string } buttonAnimationName = nil - case let .storiesChannelBoost(peer, level, currentLevelBoosts, nextLevelBoosts, link, boosted): - if link == nil, state.initialized { + case let .storiesChannelBoost(peer, isCurrent, level, currentLevelBoosts, nextLevelBoosts, link, boosted): + if link == nil, !isCurrent, state.initialized { peerShortcutChild = peerShortcut.update( component: Button( content: AnyComponent( @@ -1246,7 +1251,7 @@ private final class LimitSheetContent: CombinedComponent { let limit = limit.update( component: PremiumLimitDisplayComponent( - inactiveColor: theme.list.itemBlocksSeparatorColor.withAlphaComponent(0.5), + inactiveColor: theme.list.itemBlocksSeparatorColor.withAlphaComponent(0.3), activeColors: gradientColors, inactiveTitle: defaultTitle, inactiveValue: defaultValue, @@ -1302,7 +1307,7 @@ private final class LimitSheetContent: CombinedComponent { var buttonOffset: CGFloat = 0.0 var textOffset: CGFloat = 228.0 + topOffset - if case let .storiesChannelBoost(_, _, _, _, link, _) = component.subject { + if case let .storiesChannelBoost(_, _, _, _, _, link, _) = component.subject { if let link { let linkButton = linkButton.update( component: SolidRoundedButtonComponent( @@ -1316,7 +1321,11 @@ private final class LimitSheetContent: CombinedComponent { fontSize: 17.0, height: 50.0, cornerRadius: 10.0, - action: {} + action: { + if component.action() { + component.dismiss() + } + } ), availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0, height: 50.0), transition: context.transition @@ -1386,11 +1395,15 @@ private final class LimitSheetContent: CombinedComponent { height -= 78.0 } - if case let .storiesChannelBoost(_, _, _, _, link, _) = component.subject { + if case let .storiesChannelBoost(_, isCurrent, _, _, _, link, _) = component.subject { if link != nil { height += 66.0 } else { - height -= 53.0 - 32.0 + if isCurrent { + height -= 53.0 + } else { + height -= 53.0 - 32.0 + } } } @@ -1510,7 +1523,7 @@ public class PremiumLimitScreen: ViewControllerComponentContainer { case storiesWeekly case storiesMonthly - case storiesChannelBoost(peer: EnginePeer, level: Int32, currentLevelBoosts: Int32, nextLevelBoosts: Int32?, link: String?, boosted: Bool) + case storiesChannelBoost(peer: EnginePeer, isCurrent: Bool, level: Int32, currentLevelBoosts: Int32, nextLevelBoosts: Int32?, link: String?, boosted: Bool) } private let context: AccountContext @@ -1611,10 +1624,8 @@ private final class PeerShortcutComponent: Component { self.component = component self.state = state - self.backgroundColor = component.theme.list.itemBlocksSeparatorColor.withAlphaComponent(0.5) + self.backgroundColor = component.theme.list.itemBlocksSeparatorColor.withAlphaComponent(0.3) - - self.avatarNode.frame = CGRect(origin: CGPoint(x: 1.0, y: 1.0), size: CGSize(width: 30.0, height: 30.0)) self.avatarNode.setPeer( context: component.context, diff --git a/submodules/StatisticsUI/Sources/ChannelStatsController.swift b/submodules/StatisticsUI/Sources/ChannelStatsController.swift index 0e5dd6b505..27206884e3 100644 --- a/submodules/StatisticsUI/Sources/ChannelStatsController.swift +++ b/submodules/StatisticsUI/Sources/ChannelStatsController.swift @@ -627,7 +627,7 @@ private func channelStatsControllerEntries(state: ChannelStatsControllerState, p if let addressName = peer.addressName, !addressName.isEmpty { link = "t.me/\(addressName)?boost" } else { - link = "t.me/boost?=\(peer.id.id._internalGetInt64Value())" + link = "t.me/c/\(peer.id.id._internalGetInt64Value())?boost" } entries.append(.boostLink(presentationData.theme, link)) } diff --git a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift index 588e41b2d0..6e1f02453f 100644 --- a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift +++ b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift @@ -4463,10 +4463,10 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate if let addressName = peer.addressName, !addressName.isEmpty { link = "t.me/\(peer.addressName ?? "")?boost" } else { - link = "t.me/boost?=\(peer.id.id._internalGetInt64Value())" + link = "t.me/c/\(peer.id.id._internalGetInt64Value())?boost" } - let controller = self.context.sharedContext.makePremiumLimitController(context: self.context, subject: .storiesChannelBoost(peer: peer, level: Int32(status.level), currentLevelBoosts: Int32(status.currentLevelBoosts), nextLevelBoosts: status.nextLevelBoosts.flatMap(Int32.init), link: link, boosted: false), count: Int32(status.boosts), forceDark: true, cancel: {}, action: { [weak self] in + let controller = self.context.sharedContext.makePremiumLimitController(context: self.context, subject: .storiesChannelBoost(peer: peer, isCurrent: true, level: Int32(status.level), currentLevelBoosts: Int32(status.currentLevelBoosts), nextLevelBoosts: status.nextLevelBoosts.flatMap(Int32.init), link: link, boosted: false), count: Int32(status.boosts), forceDark: true, cancel: {}, action: { [weak self] in guard let self else { return true } @@ -4476,6 +4476,8 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate return true }) self.push(controller) + + self.hapticFeedback.impact(.light) }) default: break diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index ac1a800945..04b9d71ebb 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -847,8 +847,13 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur boosted = true } - let subject: PremiumLimitScreen.Subject = .storiesChannelBoost(peer: peer, level: Int32(status.level), currentLevelBoosts: Int32(status.currentLevelBoosts), nextLevelBoosts: status.nextLevelBoosts.flatMap(Int32.init), link: nil, boosted: boosted) - let nextSubject: PremiumLimitScreen.Subject = .storiesChannelBoost(peer: peer, level: Int32(status.level), currentLevelBoosts: Int32(status.currentLevelBoosts), nextLevelBoosts: status.nextLevelBoosts.flatMap(Int32.init), link: nil, boosted: true) + var isCurrent = false + if case let .chat(chatPeerId, _) = urlContext, chatPeerId == peerId { + isCurrent = true + } + + let subject: PremiumLimitScreen.Subject = .storiesChannelBoost(peer: peer, isCurrent: isCurrent, level: Int32(status.level), currentLevelBoosts: Int32(status.currentLevelBoosts), nextLevelBoosts: status.nextLevelBoosts.flatMap(Int32.init), link: nil, boosted: boosted) + let nextSubject: PremiumLimitScreen.Subject = .storiesChannelBoost(peer: peer, isCurrent: isCurrent, level: Int32(status.level), currentLevelBoosts: Int32(status.currentLevelBoosts), nextLevelBoosts: status.nextLevelBoosts.flatMap(Int32.init), link: nil, boosted: true) let nextCount = Int32(status.boosts + 1) var updateImpl: (() -> Void)? diff --git a/submodules/TelegramUI/Sources/OpenUrl.swift b/submodules/TelegramUI/Sources/OpenUrl.swift index 59957a2f22..dcd978e43a 100644 --- a/submodules/TelegramUI/Sources/OpenUrl.swift +++ b/submodules/TelegramUI/Sources/OpenUrl.swift @@ -876,7 +876,7 @@ func openExternalUrlImpl(context: AccountContext, urlContext: OpenURLContext, ur if let domain { convertedUrl = "https://t.me/\(domain)?boost" } else if let channel { - convertedUrl = "https://t.me/boost?channel=\(channel)" + convertedUrl = "https://t.me/c/\(channel)?boost" } } } diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 271e85ddf0..f7b2bc8ecd 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -1782,8 +1782,8 @@ public final class SharedAccountContextImpl: SharedAccountContext { mappedSubject = .storiesWeekly case .storiesMonthly: mappedSubject = .storiesMonthly - case let .storiesChannelBoost(peer, level, currentLevelBoosts, nextLevelBoosts, link, boosted): - mappedSubject = .storiesChannelBoost(peer: peer, level: level, currentLevelBoosts: currentLevelBoosts, nextLevelBoosts: nextLevelBoosts, link: link, boosted: boosted) + case let .storiesChannelBoost(peer, isCurrent, level, currentLevelBoosts, nextLevelBoosts, link, boosted): + mappedSubject = .storiesChannelBoost(peer: peer, isCurrent: isCurrent, level: level, currentLevelBoosts: currentLevelBoosts, nextLevelBoosts: nextLevelBoosts, link: link, boosted: boosted) } return PremiumLimitScreen(context: context, subject: mappedSubject, count: count, forceDark: forceDark, cancel: cancel, action: action) } diff --git a/submodules/TelegramUI/Sources/TelegramRootController.swift b/submodules/TelegramUI/Sources/TelegramRootController.swift index aebd04c1e3..cb76952e84 100644 --- a/submodules/TelegramUI/Sources/TelegramRootController.swift +++ b/submodules/TelegramUI/Sources/TelegramRootController.swift @@ -218,11 +218,6 @@ public final class TelegramRootController: NavigationController, TelegramRootCon self.accountSettingsController = accountSettingsController self.rootTabController = tabBarController self.pushViewController(tabBarController, animated: false) - -// Queue.mainQueue().after(0.5) { -// let controller = self.context.sharedContext.makePremiumLimitController(context: self.context, subject: .storiesChannelBoost(title: "MYChannel", level: 0, currentLevelBoosts: 0, nextLevelBoosts: 1, link: "t.me/mychannel?boost"), count: 0, forceDark: true, cancel: {}, action: {}) -// chatListController.present(controller, in: .window(.root)) -// } } public func updateRootControllers(showCallsTab: Bool) { diff --git a/submodules/UrlHandling/Sources/UrlHandling.swift b/submodules/UrlHandling/Sources/UrlHandling.swift index b0de6965f0..b8f4ec23ed 100644 --- a/submodules/UrlHandling/Sources/UrlHandling.swift +++ b/submodules/UrlHandling/Sources/UrlHandling.swift @@ -494,6 +494,7 @@ public func parseInternalUrl(query: String) -> ParsedInternalUrl? { } else if pathComponents.count == 2 && pathComponents[0] == "c" { if let channelId = Int64(pathComponents[1]) { var threadId: Int32? + var boost: Bool = false if let queryItems = components.queryItems { for queryItem in queryItems { if let value = queryItem.value { @@ -502,12 +503,19 @@ public func parseInternalUrl(query: String) -> ParsedInternalUrl? { threadId = intValue } } + } else { + if queryItem.name == "boost" { + boost = true + } } } } - if let threadId = threadId { - return .peer(.id(PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId))), .replyThread(threadId, threadId)) + let peerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId)) + if boost { + return .peer(.id(peerId), .boost) + } else if let threadId = threadId { + return .peer(.id(peerId), .replyThread(threadId, threadId)) } else { return nil }