@@ -37,7 +37,7 @@ private func _internal_getStarGiftAuctionState(postbox: Postbox, network: Networ
3737 }
3838 return (
3939 gift: gift,
40- state: GiftAuctionContext . State. AuctionState ( apiAuctionState: state) ,
40+ state: GiftAuctionContext . State. AuctionState ( apiAuctionState: state, transaction : transaction ) ,
4141 myState: GiftAuctionContext . State. MyState ( apiAuctionUserState: userState) ,
4242 timeout: timeout
4343 )
@@ -55,7 +55,7 @@ public final class GiftAuctionContext {
5555 }
5656
5757 public enum AuctionState : Equatable {
58- case ongoing( version: Int32 , startDate: Int32 , endDate: Int32 , minBidAmount: Int64 , bidLevels: [ BidLevel ] , topBidders: [ EnginePeer . Id ] , nextRoundDate: Int32 , giftsLeft: Int32 , currentRound: Int32 , totalRounds: Int32 )
58+ case ongoing( version: Int32 , startDate: Int32 , endDate: Int32 , minBidAmount: Int64 , bidLevels: [ BidLevel ] , topBidders: [ EnginePeer ] , nextRoundDate: Int32 , giftsLeft: Int32 , currentRound: Int32 , totalRounds: Int32 )
5959 case finished( startDate: Int32 , endDate: Int32 , averagePrice: Int64 )
6060 }
6161
@@ -208,10 +208,33 @@ extension GiftAuctionContext.State.BidLevel {
208208}
209209
210210extension GiftAuctionContext . State . AuctionState {
211- init ? ( apiAuctionState: Api . StarGiftAuctionState ) {
211+ init ? ( apiAuctionState: Api . StarGiftAuctionState , peers : [ PeerId : Peer ] ) {
212212 switch apiAuctionState {
213- case let . starGiftAuctionState( version, startDate, endDate, minBidAmount, bidLevels, topBidders, nextRoundAt, giftsLeft, currentRound, totalRounds) :
214- self = . ongoing( version: version, startDate: startDate, endDate: endDate, minBidAmount: minBidAmount, bidLevels: bidLevels. map ( GiftAuctionContext . State. BidLevel. init ( apiBidLevel: ) ) , topBidders: topBidders. map { EnginePeer . Id ( namespace: Namespaces . Peer. CloudUser, id: PeerId . Id. _internalFromInt64Value ( $0) ) } , nextRoundDate: nextRoundAt, giftsLeft: giftsLeft, currentRound: currentRound, totalRounds: totalRounds)
213+ case let . starGiftAuctionState( version, startDate, endDate, minBidAmount, bidLevels, topBiddersPeerIds, nextRoundAt, giftsLeft, currentRound, totalRounds) :
214+ var topBidders : [ EnginePeer ] = [ ]
215+ for peerId in topBiddersPeerIds {
216+ if let peer = peers [ PeerId ( namespace: Namespaces . Peer. CloudUser, id: PeerId . Id. _internalFromInt64Value ( peerId) ) ] {
217+ topBidders. append ( EnginePeer ( peer) )
218+ }
219+ }
220+ self = . ongoing( version: version, startDate: startDate, endDate: endDate, minBidAmount: minBidAmount, bidLevels: bidLevels. map ( GiftAuctionContext . State. BidLevel. init ( apiBidLevel: ) ) , topBidders: topBidders, nextRoundDate: nextRoundAt, giftsLeft: giftsLeft, currentRound: currentRound, totalRounds: totalRounds)
221+ case let . starGiftAuctionStateFinished( startDate, endDate, averagePrice) :
222+ self = . finished( startDate: startDate, endDate: endDate, averagePrice: averagePrice)
223+ case . starGiftAuctionStateNotModified:
224+ return nil
225+ }
226+ }
227+
228+ init ? ( apiAuctionState: Api . StarGiftAuctionState , transaction: Transaction ) {
229+ switch apiAuctionState {
230+ case let . starGiftAuctionState( version, startDate, endDate, minBidAmount, bidLevels, topBiddersPeerIds, nextRoundAt, giftsLeft, currentRound, totalRounds) :
231+ var topBidders : [ EnginePeer ] = [ ]
232+ for peerId in topBiddersPeerIds {
233+ if let peer = transaction. getPeer ( PeerId ( namespace: Namespaces . Peer. CloudUser, id: PeerId . Id. _internalFromInt64Value ( peerId) ) ) {
234+ topBidders. append ( EnginePeer ( peer) )
235+ }
236+ }
237+ self = . ongoing( version: version, startDate: startDate, endDate: endDate, minBidAmount: minBidAmount, bidLevels: bidLevels. map ( GiftAuctionContext . State. BidLevel. init ( apiBidLevel: ) ) , topBidders: topBidders, nextRoundDate: nextRoundAt, giftsLeft: giftsLeft, currentRound: currentRound, totalRounds: totalRounds)
215238 case let . starGiftAuctionStateFinished( startDate, endDate, averagePrice) :
216239 self = . finished( startDate: startDate, endDate: endDate, averagePrice: averagePrice)
217240 case . starGiftAuctionStateNotModified:
@@ -314,7 +337,7 @@ func _internal_getActiveGiftAuctions(account: Account, hash: Int64) -> Signal<[G
314337 auctionContexts. append ( GiftAuctionContext (
315338 account: account,
316339 gift: gift,
317- initialAuctionState: GiftAuctionContext . State. AuctionState ( apiAuctionState: auctionState) ,
340+ initialAuctionState: GiftAuctionContext . State. AuctionState ( apiAuctionState: auctionState, transaction : transaction ) ,
318341 initialMyState: GiftAuctionContext . State. MyState ( apiAuctionUserState: userState) ,
319342 initialTimeout: nil
320343 ) )
0 commit comments