mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Various improvements
This commit is contained in:
@@ -219,36 +219,22 @@ private func getReceiptData() -> Data? {
|
|||||||
|
|
||||||
extension InAppPurchaseManager: SKPaymentTransactionObserver {
|
extension InAppPurchaseManager: SKPaymentTransactionObserver {
|
||||||
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
||||||
for transaction in transactions {
|
self.stateQueue.async {
|
||||||
let accountPeerId = "\(self.engine.account.peerId.toInt64())"
|
let accountPeerId = "\(self.engine.account.peerId.toInt64())"
|
||||||
|
var transactionsToAssign: [SKPaymentTransaction] = []
|
||||||
|
for transaction in transactions {
|
||||||
if let applicationUsername = transaction.payment.applicationUsername, applicationUsername != accountPeerId {
|
if let applicationUsername = transaction.payment.applicationUsername, applicationUsername != accountPeerId {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
let productIdentifier = transaction.payment.productIdentifier
|
let productIdentifier = transaction.payment.productIdentifier
|
||||||
self.stateQueue.async {
|
|
||||||
let transactionState: TransactionState?
|
let transactionState: TransactionState?
|
||||||
switch transaction.transactionState {
|
switch transaction.transactionState {
|
||||||
case .purchased:
|
case .purchased:
|
||||||
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transaction \(transaction.transactionIdentifier ?? ""), original transaction \(transaction.original?.transactionIdentifier ?? "none") purchased")
|
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transaction \(transaction.transactionIdentifier ?? ""), original transaction \(transaction.original?.transactionIdentifier ?? "none") purchased")
|
||||||
let transactionIdentifier = transaction.transactionIdentifier
|
|
||||||
transactionState = .purchased(transactionId: transactionIdentifier)
|
|
||||||
if let transactionIdentifier = transactionIdentifier {
|
|
||||||
self.disposableSet.set(
|
|
||||||
self.engine.payments.sendAppStoreReceipt(receipt: getReceiptData() ?? Data(), restore: false).start(error: { [weak self] _ in
|
|
||||||
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transaction \(transaction.transactionIdentifier ?? "") failed to assign AppStore transaction")
|
|
||||||
queue.finishTransaction(transaction)
|
|
||||||
|
|
||||||
if let strongSelf = self, let context = strongSelf.paymentContexts[productIdentifier] {
|
transactionState = .purchased(transactionId: transaction.transactionIdentifier)
|
||||||
context.subscriber(.assignFailed)
|
transactionsToAssign.append(transaction)
|
||||||
}
|
|
||||||
}, completed: {
|
|
||||||
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transaction \(transaction.transactionIdentifier ?? "") successfully assigned AppStore transaction")
|
|
||||||
queue.finishTransaction(transaction)
|
|
||||||
}),
|
|
||||||
forKey: transactionIdentifier
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case .restored:
|
case .restored:
|
||||||
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transaction \(transaction.transactionIdentifier ?? ""), original transaction \(transaction.original?.transactionIdentifier ?? "") restroring")
|
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transaction \(transaction.transactionIdentifier ?? ""), original transaction \(transaction.original?.transactionIdentifier ?? "") restroring")
|
||||||
let transactionIdentifier = transaction.transactionIdentifier
|
let transactionIdentifier = transaction.transactionIdentifier
|
||||||
@@ -272,6 +258,31 @@ extension InAppPurchaseManager: SKPaymentTransactionObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !transactionsToAssign.isEmpty {
|
||||||
|
let transactionIds = transactionsToAssign.compactMap({ $0.transactionIdentifier }).joined(separator: ", ")
|
||||||
|
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), sending receipt for transactions [\(transactionIds)]")
|
||||||
|
|
||||||
|
self.disposableSet.set(
|
||||||
|
self.engine.payments.sendAppStoreReceipt(receipt: getReceiptData() ?? Data(), restore: false).start(error: { [weak self] _ in
|
||||||
|
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transactions [\(transactionIds)] failed to assign")
|
||||||
|
for transaction in transactions {
|
||||||
|
self?.stateQueue.async {
|
||||||
|
if let strongSelf = self, let context = strongSelf.paymentContexts[transaction.payment.productIdentifier] {
|
||||||
|
context.subscriber(.assignFailed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
queue.finishTransaction(transaction)
|
||||||
|
}
|
||||||
|
}, completed: {
|
||||||
|
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transactions [\(transactionIds)] successfully assigned")
|
||||||
|
for transaction in transactions {
|
||||||
|
queue.finishTransaction(transaction)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
forKey: transactionIds
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1422,16 +1422,23 @@ private final class PremiumIntroScreenComponent: CombinedComponent {
|
|||||||
return .never()
|
return .never()
|
||||||
}
|
}
|
||||||
|> timeout(15.0, queue: Queue.mainQueue(), alternate: .fail(.timeout))
|
|> timeout(15.0, queue: Queue.mainQueue(), alternate: .fail(.timeout))
|
||||||
|> deliverOnMainQueue).start(error: { _ in
|
|> deliverOnMainQueue).start(error: { [weak self] _ in
|
||||||
|
if let strongSelf = self {
|
||||||
|
strongSelf.inProgress = false
|
||||||
|
strongSelf.updated(transition: .immediate)
|
||||||
|
strongSelf.completion()
|
||||||
|
|
||||||
addAppLogEvent(postbox: strongSelf.context.account.postbox, type: "premium.promo_screen_fail")
|
addAppLogEvent(postbox: strongSelf.context.account.postbox, type: "premium.promo_screen_fail")
|
||||||
|
|
||||||
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
|
||||||
let errorText = presentationData.strings.Premium_Purchase_ErrorUnknown
|
let errorText = presentationData.strings.Premium_Purchase_ErrorUnknown
|
||||||
let alertController = textAlertController(context: strongSelf.context, title: nil, text: errorText, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})])
|
let alertController = textAlertController(context: strongSelf.context, title: nil, text: errorText, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})])
|
||||||
strongSelf.present(alertController)
|
strongSelf.present(alertController)
|
||||||
|
}
|
||||||
}, completed: { [weak self] in
|
}, completed: { [weak self] in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
let _ = updatePremiumPromoConfigurationOnce(account: strongSelf.context.account).start()
|
let _ = updatePremiumPromoConfigurationOnce(account: strongSelf.context.account).start()
|
||||||
|
strongSelf.inProgress = false
|
||||||
strongSelf.isPremium = true
|
strongSelf.isPremium = true
|
||||||
strongSelf.updated(transition: .easeInOut(duration: 0.25))
|
strongSelf.updated(transition: .easeInOut(duration: 0.25))
|
||||||
strongSelf.completion()
|
strongSelf.completion()
|
||||||
|
|||||||
@@ -852,6 +852,8 @@ private final class LimitSheetContent: CombinedComponent {
|
|||||||
transition: .immediate
|
transition: .immediate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let contentSize: CGSize
|
||||||
|
if state.initialized {
|
||||||
let gradientColors: [UIColor]
|
let gradientColors: [UIColor]
|
||||||
if isPremiumDisabled {
|
if isPremiumDisabled {
|
||||||
gradientColors = [
|
gradientColors = [
|
||||||
@@ -867,7 +869,6 @@ private final class LimitSheetContent: CombinedComponent {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.initialized {
|
|
||||||
let limit = limit.update(
|
let limit = limit.update(
|
||||||
component: PremiumLimitDisplayComponent(
|
component: PremiumLimitDisplayComponent(
|
||||||
inactiveColor: theme.list.itemBlocksSeparatorColor.withAlphaComponent(0.5),
|
inactiveColor: theme.list.itemBlocksSeparatorColor.withAlphaComponent(0.5),
|
||||||
@@ -889,7 +890,6 @@ private final class LimitSheetContent: CombinedComponent {
|
|||||||
context.add(limit
|
context.add(limit
|
||||||
.position(CGPoint(x: context.availableSize.width / 2.0, y: limit.size.height / 2.0 + 44.0))
|
.position(CGPoint(x: context.availableSize.width / 2.0, y: limit.size.height / 2.0 + 44.0))
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
let isIncreaseButton = !reachedMaximumLimit && !isPremiumDisabled
|
let isIncreaseButton = !reachedMaximumLimit && !isPremiumDisabled
|
||||||
let button = button.update(
|
let button = button.update(
|
||||||
@@ -939,7 +939,10 @@ private final class LimitSheetContent: CombinedComponent {
|
|||||||
.position(CGPoint(x: buttonFrame.midX, y: buttonFrame.midY))
|
.position(CGPoint(x: buttonFrame.midX, y: buttonFrame.midY))
|
||||||
)
|
)
|
||||||
|
|
||||||
let contentSize = CGSize(width: context.availableSize.width, height: buttonFrame.maxY + 5.0 + environment.safeInsets.bottom)
|
contentSize = CGSize(width: context.availableSize.width, height: buttonFrame.maxY + 5.0 + environment.safeInsets.bottom)
|
||||||
|
} else {
|
||||||
|
contentSize = CGSize(width: context.availableSize.width, height: 351.0 + environment.safeInsets.bottom)
|
||||||
|
}
|
||||||
|
|
||||||
return contentSize
|
return contentSize
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -808,6 +808,10 @@ public final class SolidRoundedButtonView: UIView {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
self.animationTimer?.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
private func setupGloss() {
|
private func setupGloss() {
|
||||||
if self.gloss {
|
if self.gloss {
|
||||||
if self.shimmerView == nil {
|
if self.shimmerView == nil {
|
||||||
@@ -1002,7 +1006,7 @@ public final class SolidRoundedButtonView: UIView {
|
|||||||
compositingFilter = nil
|
compositingFilter = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let globalTimeOffset = self.icon == nil
|
let globalTimeOffset = self.icon == nil && self.animation == nil
|
||||||
|
|
||||||
shimmerView.update(backgroundColor: .clear, foregroundColor: color.withAlphaComponent(alpha), gradientSize: 70.0, globalTimeOffset: globalTimeOffset, duration: 3.0, horizontal: true)
|
shimmerView.update(backgroundColor: .clear, foregroundColor: color.withAlphaComponent(alpha), gradientSize: 70.0, globalTimeOffset: globalTimeOffset, duration: 3.0, horizontal: true)
|
||||||
borderShimmerView.update(backgroundColor: .clear, foregroundColor: color.withAlphaComponent(borderAlpha), gradientSize: 70.0, globalTimeOffset: globalTimeOffset, duration: 3.0, horizontal: true)
|
borderShimmerView.update(backgroundColor: .clear, foregroundColor: color.withAlphaComponent(borderAlpha), gradientSize: 70.0, globalTimeOffset: globalTimeOffset, duration: 3.0, horizontal: true)
|
||||||
|
|||||||
Reference in New Issue
Block a user