mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Various improvements
This commit is contained in:
parent
ac28ed9d74
commit
bdcc80e649
3 changed files with 57 additions and 16 deletions
|
|
@ -553,7 +553,7 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder {
|
|||
guard let self else {
|
||||
return
|
||||
}
|
||||
if !"".isEmpty, self.giftAuctionStates.count == 1, let gift = self.giftAuctionStates.first?.gift, case let .generic(gift) = gift {
|
||||
if self.giftAuctionStates.count == 1, let gift = self.giftAuctionStates.first?.gift, case let .generic(gift) = gift {
|
||||
if let giftAuctionsManager = self.context.giftAuctionsManager {
|
||||
let _ = (giftAuctionsManager.auctionContext(for: .giftId(gift.id))
|
||||
|> deliverOnMainQueue).start(next: { [weak self] auction in
|
||||
|
|
|
|||
|
|
@ -448,17 +448,60 @@ public class GiftAuctionsManager {
|
|||
}
|
||||
|
||||
public extension GiftAuctionContext.State {
|
||||
var place: Int32? {
|
||||
guard case let .ongoing(_, _, _, _, bidLevels, _, _, _, _, _) = self.auctionState, let myBid = self.myState.bidAmount, let myBidDate = self.myState.bidDate else {
|
||||
func getPlace(myBid: Int64?, myBidDate: Int32?) -> Int32? {
|
||||
guard case let .ongoing(_, _, _, _, bidLevels, _, _, _, _, _) = self.auctionState else {
|
||||
return nil
|
||||
}
|
||||
var place: Int32 = 1
|
||||
for level in bidLevels {
|
||||
if myBid < level.amount || (myBid == level.amount && myBidDate > level.date) {
|
||||
place = level.position + 1
|
||||
guard let myBid = myBid ?? self.myState.bidAmount else {
|
||||
return nil
|
||||
}
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
let myBidDate = self.myState.bidDate ?? currentTime
|
||||
|
||||
let levels = bidLevels
|
||||
guard !levels.isEmpty else {
|
||||
return 1
|
||||
}
|
||||
|
||||
func isWorse(than level: GiftAuctionContext.State.BidLevel) -> Bool {
|
||||
if myBid < level.amount {
|
||||
return true
|
||||
}
|
||||
if myBid == level.amount, myBidDate > level.date {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var lowerIndex: Int = -1
|
||||
for (i, level) in levels.enumerated() {
|
||||
if isWorse(than: level) {
|
||||
lowerIndex = i
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return place
|
||||
if lowerIndex == -1 {
|
||||
return 1
|
||||
}
|
||||
|
||||
let lowerPosition = levels[lowerIndex].position
|
||||
let nextPosition: Int32
|
||||
let nextIndex = lowerIndex + 1
|
||||
if nextIndex < levels.count {
|
||||
nextPosition = levels[nextIndex].position
|
||||
} else {
|
||||
nextPosition = lowerPosition
|
||||
}
|
||||
if nextPosition == lowerPosition + 1 {
|
||||
return lowerPosition + 1
|
||||
} else {
|
||||
return nextPosition
|
||||
}
|
||||
}
|
||||
|
||||
var place: Int32? {
|
||||
return self.getPlace(myBid: nil, myBidDate: nil)
|
||||
}
|
||||
|
||||
var startDate: Int32 {
|
||||
|
|
|
|||
|
|
@ -1781,6 +1781,8 @@ private final class GiftAuctionBidScreenComponent: Component {
|
|||
self.backgroundLayer.backgroundColor = environment.theme.actionSheet.opaqueItemBackgroundColor.cgColor
|
||||
}
|
||||
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
|
||||
transition.setFrame(view: self.dimView, frame: CGRect(origin: CGPoint(), size: availableSize))
|
||||
|
||||
var contentHeight: CGFloat = 0.0
|
||||
|
|
@ -2055,7 +2057,6 @@ private final class GiftAuctionBidScreenComponent: Component {
|
|||
minBidAnimatedItems.append(AnimatedTextComponent.Item(id: "static", content: .text(minBidString)))
|
||||
}
|
||||
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
let dropTimeout = max(0, nextDropDate - currentTime)
|
||||
|
||||
let minutes = Int(dropTimeout / 60)
|
||||
|
|
@ -2235,19 +2236,16 @@ private final class GiftAuctionBidScreenComponent: Component {
|
|||
var topBidsComponents: [(EnginePeer.Id, AnyComponent<Empty>)] = []
|
||||
|
||||
if let giftAuctionState = self.giftAuctionState, case let .ongoing(_, _, _, _, bidLevels, topBidders, _, _, _, _) = giftAuctionState.auctionState {
|
||||
if var myBidAmount = giftAuctionState.myState.bidAmount, let myBidDate = giftAuctionState.myState.bidDate, let peer = self.peersMap[component.context.account.peerId] {
|
||||
if var myBidAmount = giftAuctionState.myState.bidAmount, var myBidDate = giftAuctionState.myState.bidDate, let peer = self.peersMap[component.context.account.peerId] {
|
||||
var place: Int32 = 1
|
||||
var isBiddingUp = false
|
||||
if self.amount.realValue > myBidAmount {
|
||||
myBidAmount = Int64(self.amount.realValue)
|
||||
myBidDate = currentTime
|
||||
isBiddingUp = true
|
||||
}
|
||||
for level in bidLevels {
|
||||
if myBidAmount < level.amount || (myBidAmount == level.amount && myBidDate > level.date) {
|
||||
place = level.position + 1
|
||||
}
|
||||
}
|
||||
|
||||
place = giftAuctionState.getPlace(myBid: myBidAmount, myBidDate: myBidDate) ?? 1
|
||||
|
||||
var bidTitle: String
|
||||
var bidTitleColor: UIColor
|
||||
var bidStatus: PeerComponent.Status?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue