Various improvements

This commit is contained in:
Ilya Laktyushin
2022-06-06 16:28:23 +04:00
parent 5d1e4b4be0
commit 9ad1b7bf86
6 changed files with 263 additions and 175 deletions

View File

@@ -1320,35 +1320,40 @@ private final class PremiumIntroScreenComponent: CombinedComponent {
super.init()
let availableProducts: Signal<[InAppPurchaseManager.Product], NoError>
if let inAppPurchaseManager = context.inAppPurchaseManager {
let otherPeerName: Signal<String?, NoError>
if case let .profile(peerId) = source {
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
otherPeerName = context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId))
|> map { peer -> String? in
return peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)
}
} else {
otherPeerName = .single(nil)
}
self.disposable = combineLatest(
queue: Queue.mainQueue(),
inAppPurchaseManager.availableProducts,
context.account.postbox.peerView(id: context.account.peerId)
|> map { view -> Bool in
return view.peers[view.peerId]?.isPremium ?? false
},
otherPeerName
).start(next: { [weak self] products, isPremium, otherPeerName in
if let strongSelf = self {
strongSelf.premiumProduct = products.first
strongSelf.isPremium = isPremium
strongSelf.otherPeerName = otherPeerName
strongSelf.updated(transition: .immediate)
}
})
availableProducts = inAppPurchaseManager.availableProducts
} else {
availableProducts = .single([])
}
let otherPeerName: Signal<String?, NoError>
if case let .profile(peerId) = source {
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
otherPeerName = context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId))
|> map { peer -> String? in
return peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)
}
} else {
otherPeerName = .single(nil)
}
self.disposable = combineLatest(
queue: Queue.mainQueue(),
availableProducts,
context.account.postbox.peerView(id: context.account.peerId)
|> map { view -> Bool in
return view.peers[view.peerId]?.isPremium ?? false
},
otherPeerName
).start(next: { [weak self] products, isPremium, otherPeerName in
if let strongSelf = self {
strongSelf.premiumProduct = products.first
strongSelf.isPremium = isPremium
strongSelf.otherPeerName = otherPeerName
strongSelf.updated(transition: .immediate)
}
})
}
deinit {