Skip to content

Commit d5a9521

Browse files
committed
Various improvements
1 parent b83250a commit d5a9521

File tree

2 files changed

+84
-77
lines changed

2 files changed

+84
-77
lines changed

submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ final class GiftOptionsScreenComponent: Component {
151151

152152
private var loadingGiftId: Int64?
153153

154-
private var _effectiveStarGifts: ([StarGift], StarsFilter)?
154+
private var _effectiveStarGifts: ([StarGift], StarsFilter, Int)?
155155
private var effectiveStarGifts: [StarGift]? {
156156
get {
157-
if let (currentGifts, currentFilter) = self._effectiveStarGifts, currentFilter == self.starsFilter && currentFilter != .transfer {
157+
if let (currentGifts, currentFilter, currentVersion) = self._effectiveStarGifts, currentFilter == self.starsFilter && currentFilter != .transfer && currentVersion == self.state?.starGiftsVersion {
158158
return currentGifts
159-
} else if let allGifts = self.state?.starGifts {
159+
} else if let state = self.state, let allGifts = state.starGifts {
160160
if case .transfer = self.starsFilter {
161161
let filteredGifts: [StarGift] = self.state?.transferStarGifts?.map { gift in
162162
return gift.gift
163163
} ?? []
164-
self._effectiveStarGifts = (filteredGifts, self.starsFilter)
164+
self._effectiveStarGifts = (filteredGifts, self.starsFilter, state.starGiftsVersion)
165165
return filteredGifts
166166
} else {
167167
var sortedGifts = allGifts
@@ -216,7 +216,7 @@ final class GiftOptionsScreenComponent: Component {
216216
}
217217
return false
218218
}
219-
self._effectiveStarGifts = (filteredGifts, self.starsFilter)
219+
self._effectiveStarGifts = (filteredGifts, self.starsFilter, state.starGiftsVersion)
220220
return filteredGifts
221221
}
222222
} else {
@@ -1718,6 +1718,7 @@ final class GiftOptionsScreenComponent: Component {
17181718
fileprivate var disallowedGifts: TelegramDisallowedGifts?
17191719
fileprivate var premiumProducts: [PremiumGiftProduct]?
17201720
fileprivate var starGifts: [StarGift]?
1721+
fileprivate var starGiftsVersion: Int = 0
17211722

17221723
fileprivate let starGiftsContext: ProfileGiftsContext
17231724
fileprivate var transferStarGifts: [ProfileGiftsContext.State.StarGift]?
@@ -1739,7 +1740,7 @@ final class GiftOptionsScreenComponent: Component {
17391740
} else {
17401741
availableProducts = .single([])
17411742
}
1742-
1743+
17431744
self.disposable = combineLatest(
17441745
queue: Queue.mainQueue(),
17451746
context.engine.data.get(
@@ -1861,6 +1862,10 @@ final class GiftOptionsScreenComponent: Component {
18611862
return true
18621863
}
18631864
}
1865+
1866+
if self.starGifts != filteredStarGifts {
1867+
self.starGiftsVersion += 1
1868+
}
18641869
self.starGifts = filteredStarGifts
18651870

18661871
self.updated()

submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,12 +2186,79 @@ private final class GiftAuctionBidScreenComponent: Component {
21862186
giftsPerRound = giftsPerRoundValue
21872187
}
21882188

2189+
var myBidTitleComponent: AnyComponent<Empty>?
2190+
var myBidComponent: AnyComponent<Empty>?
2191+
2192+
var topBidsTitleComponent: AnyComponent<Empty>?
2193+
var topBidsComponents: [(EnginePeer.Id, AnyComponent<Empty>)] = []
2194+
2195+
let place: Int32
2196+
if let giftAuctionState = self.giftAuctionState, case let .ongoing(_, _, _, _, bidLevels, topBidders, _, _, _, _) = giftAuctionState.auctionState {
2197+
var myBidAmount = Int64(self.amount.realValue)
2198+
var myBidDate = currentTime
2199+
var isBiddingUp = true
2200+
2201+
if let currentAmount = giftAuctionState.myState.bidAmount, let currentDate = giftAuctionState.myState.bidDate, currentAmount >= myBidAmount {
2202+
myBidAmount = currentAmount
2203+
myBidDate = currentDate
2204+
isBiddingUp = false
2205+
}
2206+
2207+
place = giftAuctionState.getPlace(myBid: myBidAmount, myBidDate: myBidDate) ?? 1
2208+
2209+
var bidTitle: String
2210+
var bidTitleColor: UIColor
2211+
var bidStatus: PeerComponent.Status?
2212+
if isBiddingUp {
2213+
bidTitleColor = environment.theme.list.itemSecondaryTextColor
2214+
bidTitle = environment.strings.Gift_AuctionBid_BidPreview
2215+
} else if giftAuctionState.myState.isReturned {
2216+
bidTitle = environment.strings.Gift_AuctionBid_Outbid
2217+
bidTitleColor = environment.theme.list.itemDestructiveColor
2218+
bidStatus = .returned
2219+
} else if place > giftsPerRound {
2220+
bidTitle = environment.strings.Gift_AuctionBid_Outbid
2221+
bidTitleColor = environment.theme.list.itemDestructiveColor
2222+
bidStatus = .outbid
2223+
} else {
2224+
bidTitle = environment.strings.Gift_AuctionBid_Winning
2225+
bidTitleColor = environment.theme.list.itemDisclosureActions.constructive.fillColor
2226+
bidStatus = .winning
2227+
}
2228+
2229+
if let peer = self.peersMap[component.context.account.peerId] {
2230+
myBidTitleComponent = AnyComponent(MultilineTextComponent(text: .plain(NSAttributedString(string: bidTitle.uppercased(), font: Font.medium(13.0), textColor: bidTitleColor))))
2231+
myBidComponent = AnyComponent(PeerComponent(context: component.context, theme: environment.theme, groupingSeparator: environment.dateTimeFormat.groupingSeparator, peer: peer, place: place, amount: myBidAmount, status: bidStatus, isLast: true, action: nil))
2232+
}
2233+
2234+
var i: Int32 = 1
2235+
for peer in topBidders {
2236+
var bid: Int64 = 0
2237+
for level in bidLevels {
2238+
if level.position == i {
2239+
bid = level.amount
2240+
break
2241+
}
2242+
}
2243+
topBidsComponents.append((peer.id, AnyComponent(PeerComponent(context: component.context, theme: environment.theme, groupingSeparator: environment.dateTimeFormat.groupingSeparator, peer: peer, place: i, amount: bid, isLast: i == topBidders.count, action: nil))))
2244+
i += 1
2245+
}
2246+
2247+
if !topBidsComponents.isEmpty {
2248+
topBidsTitleComponent = AnyComponent(MultilineTextComponent(text: .plain(NSAttributedString(string: environment.strings.Gift_AuctionBid_TopWinners.uppercased(), font: Font.medium(13.0), textColor: environment.theme.list.itemSecondaryTextColor))))
2249+
}
2250+
} else {
2251+
place = 1
2252+
}
2253+
21892254
var topCutoffRealValue: Int?
2190-
if let giftAuctionState = self.giftAuctionState, case let .ongoing(_, _, _, _, bidLevels, _, _, _, _, _) = giftAuctionState.auctionState {
2191-
for bidLevel in bidLevels {
2192-
if bidLevel.position == giftsPerRound - 1 {
2193-
topCutoffRealValue = Int(bidLevel.amount)
2194-
break
2255+
if place > giftsPerRound {
2256+
if let giftAuctionState = self.giftAuctionState, case let .ongoing(_, _, _, _, bidLevels, _, _, _, _, _) = giftAuctionState.auctionState {
2257+
for bidLevel in bidLevels {
2258+
if bidLevel.position == giftsPerRound - 1 {
2259+
topCutoffRealValue = Int(bidLevel.amount)
2260+
break
2261+
}
21952262
}
21962263
}
21972264
}
@@ -2298,72 +2365,7 @@ private final class GiftAuctionBidScreenComponent: Component {
22982365
self.badgeStars.frame = starsRect
22992366
self.badgeStars.update(size: starsRect.size, color: sliderColor, emitterPosition: CGPoint(x: badgeFrame.midX, y: badgeFrame.maxY - 32.0))
23002367
}
2301-
2302-
var myBidTitleComponent: AnyComponent<Empty>?
2303-
var myBidComponent: AnyComponent<Empty>?
2304-
2305-
var topBidsTitleComponent: AnyComponent<Empty>?
2306-
var topBidsComponents: [(EnginePeer.Id, AnyComponent<Empty>)] = []
2307-
2308-
let place: Int32
2309-
if let giftAuctionState = self.giftAuctionState, case let .ongoing(_, _, _, _, bidLevels, topBidders, _, _, _, _) = giftAuctionState.auctionState {
2310-
var myBidAmount = Int64(self.amount.realValue)
2311-
var myBidDate = currentTime
2312-
var isBiddingUp = true
2313-
2314-
if let currentAmount = giftAuctionState.myState.bidAmount, let currentDate = giftAuctionState.myState.bidDate, currentAmount >= myBidAmount {
2315-
myBidAmount = currentAmount
2316-
myBidDate = currentDate
2317-
isBiddingUp = false
2318-
}
2319-
2320-
place = giftAuctionState.getPlace(myBid: myBidAmount, myBidDate: myBidDate) ?? 1
2321-
2322-
var bidTitle: String
2323-
var bidTitleColor: UIColor
2324-
var bidStatus: PeerComponent.Status?
2325-
if isBiddingUp {
2326-
bidTitleColor = environment.theme.list.itemSecondaryTextColor
2327-
bidTitle = environment.strings.Gift_AuctionBid_BidPreview
2328-
} else if giftAuctionState.myState.isReturned {
2329-
bidTitle = environment.strings.Gift_AuctionBid_Outbid
2330-
bidTitleColor = environment.theme.list.itemDestructiveColor
2331-
bidStatus = .returned
2332-
} else if place > giftsPerRound {
2333-
bidTitle = environment.strings.Gift_AuctionBid_Outbid
2334-
bidTitleColor = environment.theme.list.itemDestructiveColor
2335-
bidStatus = .outbid
2336-
} else {
2337-
bidTitle = environment.strings.Gift_AuctionBid_Winning
2338-
bidTitleColor = environment.theme.list.itemDisclosureActions.constructive.fillColor
2339-
bidStatus = .winning
2340-
}
2341-
2342-
if let peer = self.peersMap[component.context.account.peerId] {
2343-
myBidTitleComponent = AnyComponent(MultilineTextComponent(text: .plain(NSAttributedString(string: bidTitle.uppercased(), font: Font.medium(13.0), textColor: bidTitleColor))))
2344-
myBidComponent = AnyComponent(PeerComponent(context: component.context, theme: environment.theme, groupingSeparator: environment.dateTimeFormat.groupingSeparator, peer: peer, place: place, amount: myBidAmount, status: bidStatus, isLast: true, action: nil))
2345-
}
2346-
2347-
var i: Int32 = 1
2348-
for peer in topBidders {
2349-
var bid: Int64 = 0
2350-
for level in bidLevels {
2351-
if level.position == i {
2352-
bid = level.amount
2353-
break
2354-
}
2355-
}
2356-
topBidsComponents.append((peer.id, AnyComponent(PeerComponent(context: component.context, theme: environment.theme, groupingSeparator: environment.dateTimeFormat.groupingSeparator, peer: peer, place: i, amount: bid, isLast: i == topBidders.count, action: nil))))
2357-
i += 1
2358-
}
2359-
2360-
if !topBidsComponents.isEmpty {
2361-
topBidsTitleComponent = AnyComponent(MultilineTextComponent(text: .plain(NSAttributedString(string: environment.strings.Gift_AuctionBid_TopWinners.uppercased(), font: Font.medium(13.0), textColor: environment.theme.list.itemSecondaryTextColor))))
2362-
}
2363-
} else {
2364-
place = 1
2365-
}
2366-
2368+
23672369
var perks: [([AnimatedTextComponent.Item], String)] = []
23682370

23692371
var minBidAnimatedItems: [AnimatedTextComponent.Item] = []

0 commit comments

Comments
 (0)