From e5a004f67ad8dc80f6d59f75924f06e669f6f187 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 14 Nov 2025 00:19:58 +0400 Subject: [PATCH] Various fixes --- .../TelegramNotices/Sources/Notices.swift | 32 +++++++++++ .../Components/Gifts/GiftOptionsScreen/BUILD | 1 + .../Sources/GiftOptionsScreen.swift | 55 +++++++++++-------- .../Sources/BadgeLabelView.swift | 1 + .../Sources/GiftAuctionBidScreen.swift | 23 +++++++- .../Sources/GlassBarButtonComponent.swift | 9 +-- 6 files changed, 91 insertions(+), 30 deletions(-) diff --git a/submodules/TelegramNotices/Sources/Notices.swift b/submodules/TelegramNotices/Sources/Notices.swift index 93a69a8bed..b1e4e9ace3 100644 --- a/submodules/TelegramNotices/Sources/Notices.swift +++ b/submodules/TelegramNotices/Sources/Notices.swift @@ -208,6 +208,7 @@ private enum ApplicationSpecificGlobalNotice: Int32 { case videoMessagesPauseSuggestion = 81 case voiceMessagesResumeTrimWarning = 82 case globalPostsSearch = 83 + case giftAuctionTips = 84 var key: ValueBoxKey { let v = ValueBoxKey(length: 4) @@ -589,6 +590,10 @@ private struct ApplicationSpecificNoticeKeys { static func globalPostsSearch() -> NoticeEntryKey { return NoticeEntryKey(namespace: noticeNamespace(namespace: globalNamespace), key: ApplicationSpecificGlobalNotice.globalPostsSearch.key) } + + static func giftAuctionTips() -> NoticeEntryKey { + return NoticeEntryKey(namespace: noticeNamespace(namespace: globalNamespace), key: ApplicationSpecificGlobalNotice.giftAuctionTips.key) + } } public struct ApplicationSpecificNotice { @@ -2586,4 +2591,31 @@ public struct ApplicationSpecificNotice { return Int(previousValue) } } + + public static func getGiftAuctionTips(accountManager: AccountManager) -> Signal { + return accountManager.transaction { transaction -> Int32 in + if let value = transaction.getNotice(ApplicationSpecificNoticeKeys.giftAuctionTips())?.get(ApplicationSpecificCounterNotice.self) { + return value.value + } else { + return 0 + } + } + } + + public static func incrementGiftAuctionTips(accountManager: AccountManager, count: Int = 1) -> Signal { + return accountManager.transaction { transaction -> Int in + var currentValue: Int32 = 0 + if let value = transaction.getNotice(ApplicationSpecificNoticeKeys.giftAuctionTips())?.get(ApplicationSpecificCounterNotice.self) { + currentValue = value.value + } + let previousValue = currentValue + currentValue += Int32(count) + + if let entry = CodableEntry(ApplicationSpecificCounterNotice(value: currentValue)) { + transaction.setNotice(ApplicationSpecificNoticeKeys.giftAuctionTips(), entry) + } + + return Int(previousValue) + } + } } diff --git a/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/BUILD b/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/BUILD index 6d7769c329..558f8cfb5a 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/BUILD +++ b/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/BUILD @@ -21,6 +21,7 @@ swift_library( "//submodules/Components/MultilineTextComponent", "//submodules/Components/BalancedTextComponent", "//submodules/TelegramPresentationData", + "//submodules/TelegramNotices", "//submodules/AccountContext", "//submodules/AppBundle", "//submodules/ItemListUI", diff --git a/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift index 07898b8328..19c2b79c20 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift @@ -7,6 +7,7 @@ import Postbox import TelegramCore import TelegramPresentationData import TelegramUIPreferences +import TelegramNotices import PresentationDataUtils import AccountContext import ComponentFlow @@ -369,22 +370,11 @@ final class GiftOptionsScreenComponent: Component { guard let giftAuctionsManager = component.context.giftAuctionsManager else { return } - - self.loadingGiftId = gift.id - Queue.mainQueue().after(0.25) { - if self.loadingGiftId != nil { - self.state?.updated() - } - } - self.auctionDisposable.set((giftAuctionsManager.auctionContext(for: .giftId(gift.id)) |> deliverOnMainQueue).start(next: { [weak self, weak mainController] auctionContext in guard let self, let auctionContext, let component = self.component, let mainController else { return } - self.loadingGiftId = nil - self.state?.updated() - if let currentBidPeerId = auctionContext.currentBidPeerId { if currentBidPeerId == component.peerId { let giftController = component.context.sharedContext.makeGiftAuctionBidScreen( @@ -419,20 +409,39 @@ final class GiftOptionsScreenComponent: Component { }) } } else { - let giftController = component.context.sharedContext.makeGiftAuctionViewScreen( - context: component.context, - auctionContext: auctionContext, - completion: { [weak mainController] in - let controller = GiftSetupScreen( - context: context, - peerId: component.peerId, - subject: .starGift(gift, nil), - completion: nil + let _ = (ApplicationSpecificNotice.getGiftAuctionTips(accountManager: context.sharedContext.accountManager) + |> deliverOnMainQueue).start(next: { [weak mainController] count in + let presentAuction = { + let giftController = component.context.sharedContext.makeGiftAuctionViewScreen( + context: component.context, + auctionContext: auctionContext, + completion: { [weak mainController] in + let controller = GiftSetupScreen( + context: context, + peerId: component.peerId, + subject: .starGift(gift, nil), + completion: nil + ) + mainController?.push(controller) + } ) - mainController?.push(controller) + mainController?.push(giftController) } - ) - mainController.push(giftController) + + if count > 0 { + presentAuction() + } else { + let infoController = component.context.sharedContext.makeGiftAuctionInfoScreen( + context: component.context, + auctionContext: auctionContext, + completion: { + presentAuction() + let _ = ApplicationSpecificNotice.incrementGiftAuctionTips(accountManager: component.context.sharedContext.accountManager).startStandalone() + } + ) + mainController?.push(infoController) + } + }) } })) } else { diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift index 2f7153f4d4..93ddba948e 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift @@ -109,6 +109,7 @@ final class BadgeLabelView: UIView { } if self.staticLabel.superview == nil { + self.staticLabel.alpha = 0.0 self.staticLabel.textColor = self.color self.staticLabel.font = font self.addSubview(self.staticLabel) diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift index cd7cac15df..2b632cd242 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift @@ -1003,7 +1003,7 @@ private final class GiftAuctionBidScreenComponent: Component { private static func makeSliderSteps(minRealValue: Int, maxRealValue: Int, isLogarithmic: Bool) -> [Int] { if isLogarithmic { - var sliderSteps: [Int] = [1, 10, 50, 100, 500, 1_000, 2_000, 5_000, 10_000, 20_000, 30_000, 40_000, 50_000] + var sliderSteps: [Int] = [100, 500, 1_000, 2_000, 5_000, 10_000, 25_000, 50_000, 100_000, 500_000] sliderSteps.removeAll(where: { $0 <= minRealValue }) sliderSteps.insert(minRealValue, at: 0) sliderSteps.removeAll(where: { $0 >= maxRealValue }) @@ -1083,6 +1083,17 @@ private final class GiftAuctionBidScreenComponent: Component { func withMaxRealValue(_ maxRealValue: Int) -> Amount { return Amount(realValue: self.realValue, minRealValue: self.minRealValue, minAllowedRealValue: self.minAllowedRealValue, maxRealValue: maxRealValue, maxSliderValue: self.maxSliderValue, isLogarithmic: self.isLogarithmic) } + + func cutoffSliderValue(for cutoffRealValue: Int) -> Int { + let clampedReal = max(self.minRealValue, min(cutoffRealValue, self.maxRealValue)) + + return Amount.remapValueToSlider( + realValue: clampedReal, + minAllowedRealValue: self.minAllowedRealValue, + maxSliderValue: self.maxSliderValue, + steps: self.sliderSteps + ) + } } final class View: UIView, UIScrollViewDelegate { @@ -2016,16 +2027,22 @@ private final class GiftAuctionBidScreenComponent: Component { giftsPerRound = giftsPerRoundValue } - var topCutoff: CGFloat? + var topCutoffRealValue: Int? if let giftAuctionState = self.giftAuctionState, case let .ongoing(_, _, _, _, bidLevels, _, _, _, _, _) = giftAuctionState.auctionState { for bidLevel in bidLevels { if bidLevel.position == giftsPerRound - 1 { - topCutoff = CGFloat(bidLevel.amount) / CGFloat(self.amount.maxRealValue) + topCutoffRealValue = Int(bidLevel.amount) break } } } + var topCutoff: CGFloat? + if let topCutoffRealValue { + let cutoffSliderValue = self.amount.cutoffSliderValue(for: topCutoffRealValue) + topCutoff = CGFloat(cutoffSliderValue) / CGFloat(self.amount.maxSliderValue) + } + let _ = self.sliderBackground.update( transition: transition, component: AnyComponent(SliderBackgroundComponent( diff --git a/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift b/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift index bfddbd9db8..9f4fe5b3e0 100644 --- a/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift +++ b/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift @@ -64,7 +64,7 @@ public final class GlassBarButtonComponent: Component { private let containerView: UIView private let genericContainerView: UIView private let genericBackgroundView: SimpleGlassView - private let glassContainerView: UIView + private let glassContainerView: GlassBackgroundContainerView private let glassBackgroundView: GlassBackgroundView private var componentView: ComponentView? @@ -74,7 +74,7 @@ public final class GlassBarButtonComponent: Component { self.containerView = UIView() self.genericContainerView = UIView() self.genericBackgroundView = SimpleGlassView() - self.glassContainerView = UIView() + self.glassContainerView = GlassBackgroundContainerView() self.glassBackgroundView = GlassBackgroundView() super.init(frame: frame) @@ -87,7 +87,7 @@ public final class GlassBarButtonComponent: Component { self.containerView.addSubview(self.glassContainerView) self.genericContainerView.addSubview(self.genericBackgroundView) - self.glassContainerView.addSubview(self.glassBackgroundView) + self.glassContainerView.contentView.addSubview(self.glassBackgroundView) self.addTarget(self, action: #selector(self.pressed), for: .touchUpInside) @@ -176,7 +176,7 @@ public final class GlassBarButtonComponent: Component { switch effectiveState { case .generic: genericAlpha = 1.0 - glassAlpha = 0.001 + glassAlpha = 0.0 case .glass, .tintedGlass: glassAlpha = 1.0 genericAlpha = 0.0 @@ -194,6 +194,7 @@ public final class GlassBarButtonComponent: Component { transition.setAlpha(view: self.glassContainerView, alpha: glassAlpha) transition.setFrame(view: self.glassContainerView, frame: bounds) + self.glassContainerView.update(size: bounds.size, isDark: component.isDark, transition: transition) transition.setFrame(view: self.genericBackgroundView, frame: bounds) transition.setFrame(view: self.glassBackgroundView, frame: bounds)