@@ -306,6 +306,10 @@ public struct StarsAmount: Equatable, Comparable, Hashable, Codable, CustomStrin
306306 }
307307
308308 public static func + ( lhs: StarsAmount , rhs: StarsAmount ) -> StarsAmount {
309+ if rhs. value < 0 || rhs. nanos < 0 {
310+ return lhs - StarsAmount( value: abs ( rhs. value) , nanos: abs ( rhs. nanos) )
311+ }
312+
309313 let totalNanos = Int64 ( lhs. nanos) + Int64( rhs. nanos)
310314 let overflow = totalNanos / 1_000_000_000
311315 let remainingNanos = totalNanos % 1_000_000_000
@@ -533,7 +537,7 @@ private final class StarsContextImpl {
533537 }
534538 var transactions = state. transactions
535539 if addTransaction {
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 ) , at: 0 )
540+ 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 )
537541 }
538542
539543 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) )
@@ -556,10 +560,6 @@ private extension StarsContext.State.Transaction {
556560 init ? ( apiTransaction: Api . StarsTransaction , peerId: EnginePeer . Id ? , transaction: Transaction ) {
557561 switch apiTransaction {
558562 case let . starsTransaction( apiFlags, id, stars, date, transactionPeer, title, description, photo, transactionDate, transactionUrl, _, messageId, extendedMedia, subscriptionPeriod, giveawayPostId, starGift, floodskipNumber, starrefCommissionPermille, starrefPeer, starrefAmount) :
559- let _ = starrefCommissionPermille
560- let _ = starrefPeer
561- let _ = starrefAmount
562-
563563 let parsedPeer : StarsContext . State . Transaction . Peer
564564 var paidMessageId : MessageId ?
565565 var giveawayMessageId : MessageId ?
@@ -615,7 +615,7 @@ private extension StarsContext.State.Transaction {
615615
616616 let media = extendedMedia. flatMap ( { $0. compactMap { textMediaAndExpirationTimerFromApiMedia ( $0, PeerId ( 0 ) ) . media } } ) ?? [ ]
617617 let _ = subscriptionPeriod
618- 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)
618+ 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 : ) ) )
619619 }
620620 }
621621}
@@ -690,6 +690,9 @@ public final class StarsContext {
690690 public let subscriptionPeriod : Int32 ?
691691 public let starGift : StarGift ?
692692 public let floodskipNumber : Int32 ?
693+ public let starrefCommissionPermille : Int32 ?
694+ public let starrefPeerId : PeerId ?
695+ public let starrefAmount : StarsAmount ?
693696
694697 public init (
695698 flags: Flags ,
@@ -707,7 +710,10 @@ public final class StarsContext {
707710 media: [ Media ] ,
708711 subscriptionPeriod: Int32 ? ,
709712 starGift: StarGift ? ,
710- floodskipNumber: Int32 ?
713+ floodskipNumber: Int32 ? ,
714+ starrefCommissionPermille: Int32 ? ,
715+ starrefPeerId: PeerId ? ,
716+ starrefAmount: StarsAmount ?
711717 ) {
712718 self . flags = flags
713719 self . id = id
@@ -725,6 +731,9 @@ public final class StarsContext {
725731 self . subscriptionPeriod = subscriptionPeriod
726732 self . starGift = starGift
727733 self . floodskipNumber = floodskipNumber
734+ self . starrefCommissionPermille = starrefCommissionPermille
735+ self . starrefPeerId = starrefPeerId
736+ self . starrefAmount = starrefAmount
728737 }
729738
730739 public static func == ( lhs: Transaction , rhs: Transaction ) -> Bool {
@@ -776,6 +785,15 @@ public final class StarsContext {
776785 if lhs. floodskipNumber != rhs. floodskipNumber {
777786 return false
778787 }
788+ if lhs. starrefCommissionPermille != rhs. starrefCommissionPermille {
789+ return false
790+ }
791+ if lhs. starrefPeerId != rhs. starrefPeerId {
792+ return false
793+ }
794+ if lhs. starrefAmount != rhs. starrefAmount {
795+ return false
796+ }
779797 return true
780798 }
781799 }
0 commit comments