Various improvements

This commit is contained in:
Ilya Laktyushin 2025-02-27 22:04:52 +04:00
parent e12b20be74
commit 43d6e7e81c
3 changed files with 84 additions and 22 deletions

View File

@ -92,7 +92,7 @@ public final class ChatUserInfoItem: ListViewItem {
}
}
public final class ChatUserInfoItemNode: ListViewItemNode {
public final class ChatUserInfoItemNode: ListViewItemNode, ASGestureRecognizerDelegate {
public var controllerInteraction: ChatControllerInteraction?
public let offsetContainer: ASDisplayNode
@ -210,6 +210,29 @@ public final class ChatUserInfoItemNode: ListViewItemNode {
self.groupsButtonNode.addTarget(self, action: #selector(self.groupsPressed), forControlEvents: .touchUpInside)
}
override public func didLoad() {
super.didLoad()
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:)))
tapRecognizer.delegate = self.wrappedGestureRecognizerDelegate
self.offsetContainer.view.addGestureRecognizer(tapRecognizer)
}
public override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
let location = gestureRecognizer.location(in: self.offsetContainer.view)
if let backgroundContent = self.backgroundContent, backgroundContent.frame.contains(location) {
return true
}
return false
}
@objc private func tapGesture(_ gestureRecognizer: UITapGestureRecognizer) {
guard let item = self.item else {
return
}
item.controllerInteraction.openPeer(item.peer, .info(nil), nil, .default)
}
override public func updateAbsoluteRect(_ rect: CGRect, within containerSize: CGSize) {
super.updateAbsoluteRect(rect, within: containerSize)

View File

@ -32,6 +32,7 @@ final class StarsTransactionsScreenComponent: Component {
let context: AccountContext
let starsContext: StarsContext
let starsRevenueStatsContext: StarsRevenueStatsContext
let subscriptionsContext: StarsSubscriptionsContext
let openTransaction: (StarsContext.State.Transaction) -> Void
let openSubscription: (StarsContext.State.Subscription) -> Void
@ -42,6 +43,7 @@ final class StarsTransactionsScreenComponent: Component {
init(
context: AccountContext,
starsContext: StarsContext,
starsRevenueStatsContext: StarsRevenueStatsContext,
subscriptionsContext: StarsSubscriptionsContext,
openTransaction: @escaping (StarsContext.State.Transaction) -> Void,
openSubscription: @escaping (StarsContext.State.Subscription) -> Void,
@ -51,6 +53,7 @@ final class StarsTransactionsScreenComponent: Component {
) {
self.context = context
self.starsContext = starsContext
self.starsRevenueStatsContext = starsRevenueStatsContext
self.subscriptionsContext = subscriptionsContext
self.openTransaction = openTransaction
self.openSubscription = openSubscription
@ -134,6 +137,9 @@ final class StarsTransactionsScreenComponent: Component {
private var stateDisposable: Disposable?
private var starsState: StarsContext.State?
private var revenueStateDisposable: Disposable?
private var revenueState: StarsRevenueStatsContextState?
private var previousBalance: StarsAmount?
private var subscriptionsStateDisposable: Disposable?
@ -190,6 +196,8 @@ final class StarsTransactionsScreenComponent: Component {
deinit {
self.stateDisposable?.dispose()
self.revenueStateDisposable?.dispose()
self.subscriptionsStateDisposable?.dispose()
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
@ -376,6 +384,18 @@ final class StarsTransactionsScreenComponent: Component {
}
})
self.revenueStateDisposable = (component.starsRevenueStatsContext.state
|> deliverOnMainQueue).start(next: { [weak self] state in
guard let self else {
return
}
self.revenueState = state
if !self.isUpdating {
self.state?.updated()
}
})
self.subscriptionsStateDisposable = (component.subscriptionsContext.state
|> deliverOnMainQueue).start(next: { [weak self] state in
guard let self else {
@ -607,14 +627,8 @@ final class StarsTransactionsScreenComponent: Component {
contentHeight += descriptionSize.height
contentHeight += 29.0
let withdrawAvailable: Bool
#if DEBUG
withdrawAvailable = "".isEmpty
#else
withdrawAvailable = "".isEmpty
#endif
let withdrawAvailable = self.revenueState?.stats?.balances.withdrawEnabled ?? false
let premiumConfiguration = PremiumConfiguration.with(appConfiguration: component.context.currentAppConfiguration.with { $0 })
let balanceSize = self.balanceView.update(
transition: .immediate,
@ -1064,6 +1078,7 @@ final class StarsTransactionsScreenComponent: Component {
public final class StarsTransactionsScreen: ViewControllerComponentContainer {
private let context: AccountContext
private let starsContext: StarsContext
private let starsRevenueStatsContext: StarsRevenueStatsContext
private let subscriptionsContext: StarsSubscriptionsContext
private let options = Promise<[StarsTopUpOption]>()
@ -1074,6 +1089,7 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer {
self.context = context
self.starsContext = starsContext
self.starsRevenueStatsContext = context.engine.payments.peerStarsRevenueContext(peerId: context.account.peerId)
self.subscriptionsContext = context.engine.payments.peerStarsSubscriptionsContext(starsContext: starsContext)
var buyImpl: (() -> Void)?
@ -1082,8 +1098,9 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer {
var openTransactionImpl: ((StarsContext.State.Transaction) -> Void)?
var openSubscriptionImpl: ((StarsContext.State.Subscription) -> Void)?
super.init(context: context, component: StarsTransactionsScreenComponent(
context: context,
starsContext: starsContext,
context: self.context,
starsContext: self.starsContext,
starsRevenueStatsContext: self.starsRevenueStatsContext,
subscriptionsContext: self.subscriptionsContext,
openTransaction: { transaction in
openTransactionImpl?(transaction)
@ -1205,23 +1222,30 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer {
case .serverProvided:
return
case .requestPassword:
let controller = self.context.sharedContext.makeStarsWithdrawalScreen(context: context, completion: { [weak self] amount in
let _ = (self.starsRevenueStatsContext.state
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self] state in
guard let self else {
return
}
let controller = confirmStarsRevenueWithdrawalController(context: context, peerId: context.account.peerId, amount: amount, present: { [weak self] c, a in
self?.present(c, in: .window(.root))
}, completion: { url in
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: url, forceExternal: true, presentationData: presentationData, navigationController: nil, dismissInput: {})
Queue.mainQueue().after(2.0) {
context.starsContext?.load(force: true)
let controller = self.context.sharedContext.makeStarsWithdrawalScreen(context: context, completion: { [weak self] amount in
guard let self else {
return
}
let controller = confirmStarsRevenueWithdrawalController(context: context, peerId: context.account.peerId, amount: amount, present: { [weak self] c, a in
self?.present(c, in: .window(.root))
}, completion: { url in
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: url, forceExternal: true, presentationData: presentationData, navigationController: nil, dismissInput: {})
Queue.mainQueue().after(2.0) {
context.starsContext?.load(force: true)
}
})
self.present(controller, in: .window(.root))
})
self.present(controller, in: .window(.root))
self.push(controller)
})
self.push(controller)
default:
let controller = starsRevenueWithdrawalController(context: context, peerId: context.account.peerId, amount: 0, initialError: error, present: { [weak self] c, a in
self?.present(c, in: .window(.root))

View File

@ -162,6 +162,21 @@ func preparedChatHistoryViewTransition(from fromView: ChatHistoryView?, to toVie
}
index -= 1
}
if let currentScrollToItem = scrollToItem {
index = 0
for entry in toView.filteredEntries.reversed() {
if index > currentScrollToItem.index {
if entry.index.timestamp > 10 {
break
} else if case .ChatInfoEntry = entry {
scrollToItem = ListViewScrollToItem(index: index, position: .bottom(0.0), animated: false, curve: curve, directionHint: .Down)
break
}
}
index += 1
}
}
}
if scrollToItem == nil {