Various fixes

This commit is contained in:
Ilya Laktyushin 2025-11-14 00:19:58 +04:00
parent 14c56127fa
commit e5a004f67a
6 changed files with 91 additions and 30 deletions

View File

@ -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<TelegramAccountManagerTypes>) -> Signal<Int32, NoError> {
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<TelegramAccountManagerTypes>, count: Int = 1) -> Signal<Int, NoError> {
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)
}
}
}

View File

@ -21,6 +21,7 @@ swift_library(
"//submodules/Components/MultilineTextComponent",
"//submodules/Components/BalancedTextComponent",
"//submodules/TelegramPresentationData",
"//submodules/TelegramNotices",
"//submodules/AccountContext",
"//submodules/AppBundle",
"//submodules/ItemListUI",

View File

@ -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 {

View File

@ -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)

View File

@ -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(

View File

@ -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<Empty>?
@ -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)