@@ -302,6 +302,10 @@ public struct StarsAmount: Equatable, Comparable, Hashable, Codable, CustomStrin
302302 }
303303
304304 public static func + ( lhs: StarsAmount , rhs: StarsAmount ) -> StarsAmount {
305+ if rhs. value < 0 || rhs. nanos < 0 {
306+ return lhs - StarsAmount( value: abs ( rhs. value) , nanos: abs ( rhs. nanos) )
307+ }
308+
305309 let totalNanos = Int64 ( lhs. nanos) + Int64( rhs. nanos)
306310 let overflow = totalNanos / 1_000_000_000
307311 let remainingNanos = totalNanos % 1_000_000_000
@@ -529,7 +533,7 @@ private final class StarsContextImpl {
529533 }
530534 var transactions = state. transactions
531535 if addTransaction {
532- transactions. insert ( . init( flags: [ . isLocal] , id: " \( arc4random ( ) ) " , count: balance, date: Int32 ( Date ( ) . timeIntervalSince1970) , peer: . appStore, title: nil , description: nil , photo: nil , transactionDate: nil , transactionUrl: nil , paidMessageId: nil , giveawayMessageId: nil , media: [ ] , subscriptionPeriod: nil , starGift: nil , floodskipNumber: nil ) , at: 0 )
536+ transactions. insert ( . init( flags: [ . isLocal] , id: " \( arc4random ( ) ) " , count: balance, date: Int32 ( Date ( ) . timeIntervalSince1970) , peer: . appStore, title: nil , description: nil , photo: nil , transactionDate: nil , transactionUrl: nil , paidMessageId: nil , giveawayMessageId: nil , media: [ ] , subscriptionPeriod: nil , starGift: nil , floodskipNumber: nil , starrefCommissionPermille : nil , starrefPeerId : nil , starrefAmount : nil ) , at: 0 )
533537 }
534538
535539 self . updateState ( StarsContext . State ( flags: [ . isPendingBalance] , balance: max ( StarsAmount ( value: 0 , nanos: 0 ) , state. balance + balance) , subscriptions: state. subscriptions, canLoadMoreSubscriptions: state. canLoadMoreSubscriptions, transactions: transactions, canLoadMoreTransactions: state. canLoadMoreTransactions, isLoading: state. isLoading) )
@@ -552,10 +556,6 @@ private extension StarsContext.State.Transaction {
552556 init ? ( apiTransaction: Api . StarsTransaction , peerId: EnginePeer . Id ? , transaction: Transaction ) {
553557 switch apiTransaction {
554558 case let . starsTransaction( apiFlags, id, stars, date, transactionPeer, title, description, photo, transactionDate, transactionUrl, _, messageId, extendedMedia, subscriptionPeriod, giveawayPostId, starGift, floodskipNumber, starrefCommissionPermille, starrefPeer, starrefAmount) :
555- let _ = starrefCommissionPermille
556- let _ = starrefPeer
557- let _ = starrefAmount
558-
559559 let parsedPeer : StarsContext . State . Transaction . Peer
560560 var paidMessageId : MessageId ?
561561 var giveawayMessageId : MessageId ?
@@ -611,7 +611,7 @@ private extension StarsContext.State.Transaction {
611611
612612 let media = extendedMedia. flatMap ( { $0. compactMap { textMediaAndExpirationTimerFromApiMedia ( $0, PeerId ( 0 ) ) . media } } ) ?? [ ]
613613 let _ = subscriptionPeriod
614- self . init ( flags: flags, id: id, count: StarsAmount ( apiAmount: stars) , date: date, peer: parsedPeer, title: title, description: description, photo: photo. flatMap ( TelegramMediaWebFile . init) , transactionDate: transactionDate, transactionUrl: transactionUrl, paidMessageId: paidMessageId, giveawayMessageId: giveawayMessageId, media: media, subscriptionPeriod: subscriptionPeriod, starGift: starGift. flatMap { StarGift ( apiStarGift: $0) } , floodskipNumber: floodskipNumber)
614+ self . init ( flags: flags, id: id, count: StarsAmount ( apiAmount: stars) , date: date, peer: parsedPeer, title: title, description: description, photo: photo. flatMap ( TelegramMediaWebFile . init) , transactionDate: transactionDate, transactionUrl: transactionUrl, paidMessageId: paidMessageId, giveawayMessageId: giveawayMessageId, media: media, subscriptionPeriod: subscriptionPeriod, starGift: starGift. flatMap { StarGift ( apiStarGift: $0) } , floodskipNumber: floodskipNumber, starrefCommissionPermille : starrefCommissionPermille , starrefPeerId : starrefPeer . flatMap ( \ . peerId ) , starrefAmount : starrefAmount . flatMap ( StarsAmount . init ( apiAmount : ) ) )
615615 }
616616 }
617617}
@@ -686,6 +686,9 @@ public final class StarsContext {
686686 public let subscriptionPeriod : Int32 ?
687687 public let starGift : StarGift ?
688688 public let floodskipNumber : Int32 ?
689+ public let starrefCommissionPermille : Int32 ?
690+ public let starrefPeerId : PeerId ?
691+ public let starrefAmount : StarsAmount ?
689692
690693 public init (
691694 flags: Flags ,
@@ -703,7 +706,10 @@ public final class StarsContext {
703706 media: [ Media ] ,
704707 subscriptionPeriod: Int32 ? ,
705708 starGift: StarGift ? ,
706- floodskipNumber: Int32 ?
709+ floodskipNumber: Int32 ? ,
710+ starrefCommissionPermille: Int32 ? ,
711+ starrefPeerId: PeerId ? ,
712+ starrefAmount: StarsAmount ?
707713 ) {
708714 self . flags = flags
709715 self . id = id
@@ -721,6 +727,9 @@ public final class StarsContext {
721727 self . subscriptionPeriod = subscriptionPeriod
722728 self . starGift = starGift
723729 self . floodskipNumber = floodskipNumber
730+ self . starrefCommissionPermille = starrefCommissionPermille
731+ self . starrefPeerId = starrefPeerId
732+ self . starrefAmount = starrefAmount
724733 }
725734
726735 public static func == ( lhs: Transaction , rhs: Transaction ) -> Bool {
@@ -772,6 +781,15 @@ public final class StarsContext {
772781 if lhs. floodskipNumber != rhs. floodskipNumber {
773782 return false
774783 }
784+ if lhs. starrefCommissionPermille != rhs. starrefCommissionPermille {
785+ return false
786+ }
787+ if lhs. starrefPeerId != rhs. starrefPeerId {
788+ return false
789+ }
790+ if lhs. starrefAmount != rhs. starrefAmount {
791+ return false
792+ }
775793 return true
776794 }
777795 }
0 commit comments