Skip to content

Commit 005887b

Browse files
author
Isaac
committed
Stars ref
1 parent ef652c0 commit 005887b

File tree

7 files changed

+295
-54
lines changed

7 files changed

+295
-54
lines changed

submodules/AccountContext/Sources/AccountContext.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,14 +896,12 @@ public enum JoinAffiliateProgramScreenMode {
896896

897897
public final class Active {
898898
public let targetPeer: EnginePeer
899-
public let link: String
900-
public let userCount: Int
901-
public let copyLink: () -> Void
899+
public let bot: TelegramConnectedStarRefBotList.Item
900+
public let copyLink: (TelegramConnectedStarRefBotList.Item) -> Void
902901

903-
public init(targetPeer: EnginePeer, link: String, userCount: Int, copyLink: @escaping () -> Void) {
902+
public init(targetPeer: EnginePeer, bot: TelegramConnectedStarRefBotList.Item, copyLink: @escaping (TelegramConnectedStarRefBotList.Item) -> Void) {
904903
self.targetPeer = targetPeer
905-
self.link = link
906-
self.userCount = userCount
904+
self.bot = bot
907905
self.copyLink = copyLink
908906
}
909907
}

submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,6 @@ func _internal_updateStarRefProgram(account: Account, id: EnginePeer.Id, program
632632
}
633633

634634
public final class TelegramConnectedStarRefBotList : Equatable {
635-
636635
public final class Item: Equatable {
637636
public let peer: EnginePeer
638637
public let url: String

submodules/TelegramCore/Sources/TelegramEngine/Payments/Stars.swift

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

submodules/TelegramUI/Components/PeerInfo/AffiliateProgramSetupScreen/Sources/AffiliateProgramSetupScreen.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,8 @@ If you end your affiliate program:
364364
programDuration: bot.durationMonths,
365365
mode: .active(JoinAffiliateProgramScreenMode.Active(
366366
targetPeer: targetPeer,
367-
link: bot.url,
368-
userCount: Int(bot.participants),
369-
copyLink: { [weak self] in
367+
bot: bot,
368+
copyLink: { [weak self] bot in
370369
guard let self, let component = self.component else {
371370
return
372371
}

0 commit comments

Comments
 (0)