Skip to content

Commit fcf3eba

Browse files
committed
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
2 parents fdfcdea + c49b242 commit fcf3eba

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
@@ -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
}

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)