Skip to content

Commit 2adccff

Browse files
author
Isaac
committed
Merge commit '7ac624dd59ce896ce84a96813abfbe771e0cf0e0'
2 parents 8fb9e44 + 7ac624d commit 2adccff

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

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

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,10 @@ public final class StarsContext {
878878
private final class StarsTransactionsContextImpl {
879879
private let account: Account
880880
private weak var starsContext: StarsContext?
881-
private let peerId: EnginePeer.Id
881+
fileprivate let peerId: EnginePeer.Id
882882
private let mode: StarsTransactionsContext.Mode
883883

884-
private var _state: StarsTransactionsContext.State
884+
fileprivate var _state: StarsTransactionsContext.State
885885
private let _statePromise = Promise<StarsTransactionsContext.State>()
886886
var state: Signal<StarsTransactionsContext.State, NoError> {
887887
return self._statePromise.get()
@@ -894,17 +894,24 @@ private final class StarsTransactionsContextImpl {
894894
init(account: Account, subject: StarsTransactionsContext.Subject, mode: StarsTransactionsContext.Mode) {
895895
assert(Queue.mainQueue().isCurrent())
896896

897+
898+
let currentTransactions: [StarsContext.State.Transaction]
899+
897900
self.account = account
898901
switch subject {
902+
case let .starsTransactionsContext(transactionsContext):
903+
self.peerId = transactionsContext.peerId
904+
currentTransactions = transactionsContext.currentState?.transactions ?? []
899905
case let .starsContext(starsContext):
900906
self.starsContext = starsContext
901907
self.peerId = starsContext.peerId
908+
currentTransactions = starsContext.currentState?.transactions ?? []
902909
case let .peer(peerId):
903910
self.peerId = peerId
911+
currentTransactions = []
904912
}
905913
self.mode = mode
906914

907-
let currentTransactions = self.starsContext?.currentState?.transactions ?? []
908915
let initialTransactions: [StarsContext.State.Transaction]
909916
switch mode {
910917
case .all:
@@ -918,7 +925,33 @@ private final class StarsTransactionsContextImpl {
918925
self._state = StarsTransactionsContext.State(transactions: initialTransactions, canLoadMore: true, isLoading: false)
919926
self._statePromise.set(.single(self._state))
920927

921-
if let starsContext = self.starsContext {
928+
if case let .starsTransactionsContext(transactionsContext) = subject {
929+
self.stateDisposable = (transactionsContext.state
930+
|> deliverOnMainQueue).start(next: { [weak self] state in
931+
guard let self else {
932+
return
933+
}
934+
let currentTransactions = state.transactions
935+
let filteredTransactions: [StarsContext.State.Transaction]
936+
switch mode {
937+
case .all:
938+
filteredTransactions = currentTransactions
939+
case .incoming:
940+
filteredTransactions = currentTransactions.filter { $0.count > 0 }
941+
case .outgoing:
942+
filteredTransactions = currentTransactions.filter { $0.count < 0 }
943+
}
944+
945+
if !filteredTransactions.isEmpty && self._state.transactions.isEmpty && filteredTransactions != initialTransactions {
946+
var updatedState = self._state
947+
updatedState.transactions.removeAll(where: { $0.flags.contains(.isLocal) })
948+
for transaction in filteredTransactions.reversed() {
949+
updatedState.transactions.insert(transaction, at: 0)
950+
}
951+
self.updateState(updatedState)
952+
}
953+
})
954+
} else if case let .starsContext(starsContext) = subject {
922955
self.stateDisposable = (starsContext.state
923956
|> deliverOnMainQueue).start(next: { [weak self] state in
924957
guard let self, let state else {
@@ -1021,6 +1054,7 @@ public final class StarsTransactionsContext {
10211054
fileprivate let impl: QueueLocalObject<StarsTransactionsContextImpl>
10221055

10231056
public enum Subject {
1057+
case starsTransactionsContext(StarsTransactionsContext)
10241058
case starsContext(StarsContext)
10251059
case peer(EnginePeer.Id)
10261060
}
@@ -1043,6 +1077,14 @@ public final class StarsTransactionsContext {
10431077
}
10441078
}
10451079

1080+
public var currentState: StarsTransactionsContext.State? {
1081+
var state: StarsTransactionsContext.State?
1082+
self.impl.syncWith { impl in
1083+
state = impl._state
1084+
}
1085+
return state
1086+
}
1087+
10461088
public func reload() {
10471089
self.impl.with {
10481090
$0.loadMore(reload: true)
@@ -1060,6 +1102,14 @@ public final class StarsTransactionsContext {
10601102
return StarsTransactionsContextImpl(account: account, subject: subject, mode: mode)
10611103
})
10621104
}
1105+
1106+
var peerId: EnginePeer.Id {
1107+
var peerId: EnginePeer.Id?
1108+
self.impl.syncWith { impl in
1109+
peerId = impl.peerId
1110+
}
1111+
return peerId!
1112+
}
10631113
}
10641114

10651115
private final class StarsSubscriptionsContextImpl {

submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsStatisticsScreen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,15 +663,15 @@ final class StarsStatisticsScreenComponent: Component {
663663
if let current = self.incomingTransactionsContext {
664664
incomingTransactionsContext = current
665665
} else {
666-
incomingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .peer(component.peerId), mode: .incoming)
666+
incomingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .starsTransactionsContext(allTransactionsContext), mode: .incoming)
667667
self.incomingTransactionsContext = incomingTransactionsContext
668668
}
669669

670670
let outgoingTransactionsContext: StarsTransactionsContext
671671
if let current = self.outgoingTransactionsContext {
672672
outgoingTransactionsContext = current
673673
} else {
674-
outgoingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .peer(component.peerId), mode: .outgoing)
674+
outgoingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .starsTransactionsContext(allTransactionsContext), mode: .outgoing)
675675
self.outgoingTransactionsContext = outgoingTransactionsContext
676676
}
677677

0 commit comments

Comments
 (0)