mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-07 06:43:43 +00:00
Update API [skip ci]
This commit is contained in:
parent
f16480f67e
commit
2150d65f78
@ -8795,13 +8795,14 @@ public extension Api.functions.payments {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public extension Api.functions.payments {
|
public extension Api.functions.payments {
|
||||||
static func getStarsTransactions(flags: Int32, peer: Api.InputPeer, offset: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.payments.StarsStatus>) {
|
static func getStarsTransactions(flags: Int32, peer: Api.InputPeer, offset: String, limit: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.payments.StarsStatus>) {
|
||||||
let buffer = Buffer()
|
let buffer = Buffer()
|
||||||
buffer.appendInt32(1731904249)
|
buffer.appendInt32(-1751937702)
|
||||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||||
peer.serialize(buffer, true)
|
peer.serialize(buffer, true)
|
||||||
serializeString(offset, buffer: buffer, boxed: false)
|
serializeString(offset, buffer: buffer, boxed: false)
|
||||||
return (FunctionDescription(name: "payments.getStarsTransactions", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("offset", String(describing: offset))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.payments.StarsStatus? in
|
serializeInt32(limit, buffer: buffer, boxed: false)
|
||||||
|
return (FunctionDescription(name: "payments.getStarsTransactions", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("offset", String(describing: offset)), ("limit", String(describing: limit))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.payments.StarsStatus? in
|
||||||
let reader = BufferReader(buffer)
|
let reader = BufferReader(buffer)
|
||||||
var result: Api.payments.StarsStatus?
|
var result: Api.payments.StarsStatus?
|
||||||
if let signature = reader.readInt32() {
|
if let signature = reader.readInt32() {
|
||||||
|
|||||||
@ -76,7 +76,7 @@ private enum RequestStarsStateError {
|
|||||||
case generic
|
case generic
|
||||||
}
|
}
|
||||||
|
|
||||||
private func _internal_requestStarsState(account: Account, peerId: EnginePeer.Id, subject: StarsTransactionsContext.Subject, offset: String?) -> Signal<InternalStarsStatus, RequestStarsStateError> {
|
private func _internal_requestStarsState(account: Account, peerId: EnginePeer.Id, mode: StarsTransactionsContext.Mode, offset: String?, limit: Int32) -> Signal<InternalStarsStatus, RequestStarsStateError> {
|
||||||
return account.postbox.transaction { transaction -> Peer? in
|
return account.postbox.transaction { transaction -> Peer? in
|
||||||
return transaction.getPeer(peerId)
|
return transaction.getPeer(peerId)
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ private func _internal_requestStarsState(account: Account, peerId: EnginePeer.Id
|
|||||||
let signal: Signal<Api.payments.StarsStatus, MTRpcError>
|
let signal: Signal<Api.payments.StarsStatus, MTRpcError>
|
||||||
if let offset {
|
if let offset {
|
||||||
var flags: Int32 = 0
|
var flags: Int32 = 0
|
||||||
switch subject {
|
switch mode {
|
||||||
case .incoming:
|
case .incoming:
|
||||||
flags = 1 << 0
|
flags = 1 << 0
|
||||||
case .outgoing:
|
case .outgoing:
|
||||||
@ -97,7 +97,7 @@ private func _internal_requestStarsState(account: Account, peerId: EnginePeer.Id
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
signal = account.network.request(Api.functions.payments.getStarsTransactions(flags: flags, peer: inputPeer, offset: offset))
|
signal = account.network.request(Api.functions.payments.getStarsTransactions(flags: flags, peer: inputPeer, offset: offset, limit: limit))
|
||||||
} else {
|
} else {
|
||||||
signal = account.network.request(Api.functions.payments.getStarsStatus(peer: inputPeer))
|
signal = account.network.request(Api.functions.payments.getStarsStatus(peer: inputPeer))
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ private final class StarsContextImpl {
|
|||||||
}
|
}
|
||||||
self.previousLoadTimestamp = currentTimestamp
|
self.previousLoadTimestamp = currentTimestamp
|
||||||
|
|
||||||
self.disposable.set((_internal_requestStarsState(account: self.account, peerId: self.peerId, subject: .all, offset: nil)
|
self.disposable.set((_internal_requestStarsState(account: self.account, peerId: self.peerId, mode: .all, offset: nil, limit: 5)
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
@ -220,7 +220,7 @@ private final class StarsContextImpl {
|
|||||||
|
|
||||||
self._state?.isLoading = true
|
self._state?.isLoading = true
|
||||||
|
|
||||||
self.disposable.set((_internal_requestStarsState(account: self.account, peerId: self.peerId, subject: .all, offset: nextOffset)
|
self.disposable.set((_internal_requestStarsState(account: self.account, peerId: self.peerId, mode: .all, offset: nextOffset, limit: 10)
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||||
if let self {
|
if let self {
|
||||||
self.updateState(StarsContext.State(flags: [], balance: status.balance, transactions: currentState.transactions + status.transactions, canLoadMore: status.nextOffset != nil, isLoading: false))
|
self.updateState(StarsContext.State(flags: [], balance: status.balance, transactions: currentState.transactions + status.transactions, canLoadMore: status.nextOffset != nil, isLoading: false))
|
||||||
@ -437,7 +437,7 @@ private final class StarsTransactionsContextImpl {
|
|||||||
private let account: Account
|
private let account: Account
|
||||||
private weak var starsContext: StarsContext?
|
private weak var starsContext: StarsContext?
|
||||||
private let peerId: EnginePeer.Id
|
private let peerId: EnginePeer.Id
|
||||||
private let subject: StarsTransactionsContext.Subject
|
private let mode: StarsTransactionsContext.Mode
|
||||||
|
|
||||||
private var _state: StarsTransactionsContext.State
|
private var _state: StarsTransactionsContext.State
|
||||||
private let _statePromise = Promise<StarsTransactionsContext.State>()
|
private let _statePromise = Promise<StarsTransactionsContext.State>()
|
||||||
@ -449,17 +449,22 @@ private final class StarsTransactionsContextImpl {
|
|||||||
private let disposable = MetaDisposable()
|
private let disposable = MetaDisposable()
|
||||||
private var stateDisposable: Disposable?
|
private var stateDisposable: Disposable?
|
||||||
|
|
||||||
init(account: Account, starsContext: StarsContext, subject: StarsTransactionsContext.Subject) {
|
init(account: Account, subject: StarsTransactionsContext.Subject, mode: StarsTransactionsContext.Mode) {
|
||||||
assert(Queue.mainQueue().isCurrent())
|
assert(Queue.mainQueue().isCurrent())
|
||||||
|
|
||||||
self.account = account
|
self.account = account
|
||||||
|
switch subject {
|
||||||
|
case let .starsContext(starsContext):
|
||||||
self.starsContext = starsContext
|
self.starsContext = starsContext
|
||||||
self.peerId = starsContext.peerId
|
self.peerId = starsContext.peerId
|
||||||
self.subject = subject
|
case let .peer(peerId):
|
||||||
|
self.peerId = peerId
|
||||||
|
}
|
||||||
|
self.mode = mode
|
||||||
|
|
||||||
let currentTransactions = starsContext.currentState?.transactions ?? []
|
let currentTransactions = self.starsContext?.currentState?.transactions ?? []
|
||||||
let initialTransactions: [StarsContext.State.Transaction]
|
let initialTransactions: [StarsContext.State.Transaction]
|
||||||
switch subject {
|
switch mode {
|
||||||
case .all:
|
case .all:
|
||||||
initialTransactions = currentTransactions
|
initialTransactions = currentTransactions
|
||||||
case .incoming:
|
case .incoming:
|
||||||
@ -471,6 +476,7 @@ private final class StarsTransactionsContextImpl {
|
|||||||
self._state = StarsTransactionsContext.State(transactions: initialTransactions, canLoadMore: true, isLoading: false)
|
self._state = StarsTransactionsContext.State(transactions: initialTransactions, canLoadMore: true, isLoading: false)
|
||||||
self._statePromise.set(.single(self._state))
|
self._statePromise.set(.single(self._state))
|
||||||
|
|
||||||
|
if let starsContext = self.starsContext {
|
||||||
self.stateDisposable = (starsContext.state
|
self.stateDisposable = (starsContext.state
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] state in
|
|> deliverOnMainQueue).start(next: { [weak self] state in
|
||||||
guard let self, let state else {
|
guard let self, let state else {
|
||||||
@ -479,7 +485,7 @@ private final class StarsTransactionsContextImpl {
|
|||||||
|
|
||||||
let currentTransactions = state.transactions
|
let currentTransactions = state.transactions
|
||||||
let filteredTransactions: [StarsContext.State.Transaction]
|
let filteredTransactions: [StarsContext.State.Transaction]
|
||||||
switch subject {
|
switch mode {
|
||||||
case .all:
|
case .all:
|
||||||
filteredTransactions = currentTransactions
|
filteredTransactions = currentTransactions
|
||||||
case .incoming:
|
case .incoming:
|
||||||
@ -507,6 +513,7 @@ private final class StarsTransactionsContextImpl {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
assert(Queue.mainQueue().isCurrent())
|
assert(Queue.mainQueue().isCurrent())
|
||||||
@ -529,7 +536,7 @@ private final class StarsTransactionsContextImpl {
|
|||||||
updatedState.isLoading = true
|
updatedState.isLoading = true
|
||||||
self.updateState(updatedState)
|
self.updateState(updatedState)
|
||||||
|
|
||||||
self.disposable.set((_internal_requestStarsState(account: self.account, peerId: self.peerId, subject: self.subject, offset: nextOffset)
|
self.disposable.set((_internal_requestStarsState(account: self.account, peerId: self.peerId, mode: self.mode, offset: nextOffset, limit: 10)
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] status in
|
|> deliverOnMainQueue).start(next: { [weak self] status in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
@ -542,7 +549,7 @@ private final class StarsTransactionsContextImpl {
|
|||||||
updatedState.canLoadMore = self.nextOffset != nil
|
updatedState.canLoadMore = self.nextOffset != nil
|
||||||
self.updateState(updatedState)
|
self.updateState(updatedState)
|
||||||
|
|
||||||
if case .all = self.subject, nextOffset.isEmpty {
|
if case .all = self.mode, nextOffset.isEmpty {
|
||||||
self.starsContext?.updateBalance(status.balance, transactions: status.transactions)
|
self.starsContext?.updateBalance(status.balance, transactions: status.transactions)
|
||||||
} else {
|
} else {
|
||||||
self.starsContext?.updateBalance(status.balance, transactions: nil)
|
self.starsContext?.updateBalance(status.balance, transactions: nil)
|
||||||
@ -572,6 +579,11 @@ public final class StarsTransactionsContext {
|
|||||||
fileprivate let impl: QueueLocalObject<StarsTransactionsContextImpl>
|
fileprivate let impl: QueueLocalObject<StarsTransactionsContextImpl>
|
||||||
|
|
||||||
public enum Subject {
|
public enum Subject {
|
||||||
|
case starsContext(StarsContext)
|
||||||
|
case peer(EnginePeer.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Mode {
|
||||||
case all
|
case all
|
||||||
case incoming
|
case incoming
|
||||||
case outgoing
|
case outgoing
|
||||||
@ -601,9 +613,9 @@ public final class StarsTransactionsContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init(account: Account, starsContext: StarsContext, subject: Subject) {
|
init(account: Account, subject: Subject, mode: Mode) {
|
||||||
self.impl = QueueLocalObject(queue: Queue.mainQueue(), generate: {
|
self.impl = QueueLocalObject(queue: Queue.mainQueue(), generate: {
|
||||||
return StarsTransactionsContextImpl(account: account, starsContext: starsContext, subject: subject)
|
return StarsTransactionsContextImpl(account: account, subject: subject, mode: mode)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,8 +75,8 @@ public extension TelegramEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public func peerStarsTransactionsContext(starsContext: StarsContext, subject: StarsTransactionsContext.Subject) -> StarsTransactionsContext {
|
public func peerStarsTransactionsContext(subject: StarsTransactionsContext.Subject, mode: StarsTransactionsContext.Mode) -> StarsTransactionsContext {
|
||||||
return StarsTransactionsContext(account: self.account, starsContext: starsContext, subject: subject)
|
return StarsTransactionsContext(account: self.account, subject: subject, mode: mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sendStarsPaymentForm(formId: Int64, source: BotPaymentInvoiceSource) -> Signal<SendBotPaymentResult, SendBotPaymentFormError> {
|
public func sendStarsPaymentForm(formId: Int64, source: BotPaymentInvoiceSource) -> Signal<SendBotPaymentResult, SendBotPaymentFormError> {
|
||||||
|
|||||||
@ -433,7 +433,7 @@ final class StarsStatisticsScreenComponent: Component {
|
|||||||
if let current = self.allTransactionsContext {
|
if let current = self.allTransactionsContext {
|
||||||
allTransactionsContext = current
|
allTransactionsContext = current
|
||||||
} else {
|
} else {
|
||||||
allTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(starsContext: component.starsContext, subject: .all)
|
allTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .starsContext(component.starsContext), mode: .all)
|
||||||
}
|
}
|
||||||
|
|
||||||
panelItems.append(StarsTransactionsPanelContainerComponent.Item(
|
panelItems.append(StarsTransactionsPanelContainerComponent.Item(
|
||||||
|
|||||||
@ -554,21 +554,21 @@ final class StarsTransactionsScreenComponent: Component {
|
|||||||
if let current = self.allTransactionsContext {
|
if let current = self.allTransactionsContext {
|
||||||
allTransactionsContext = current
|
allTransactionsContext = current
|
||||||
} else {
|
} else {
|
||||||
allTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(starsContext: component.starsContext, subject: .all)
|
allTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .starsContext(component.starsContext), mode: .all)
|
||||||
}
|
}
|
||||||
|
|
||||||
let incomingTransactionsContext: StarsTransactionsContext
|
let incomingTransactionsContext: StarsTransactionsContext
|
||||||
if let current = self.incomingTransactionsContext {
|
if let current = self.incomingTransactionsContext {
|
||||||
incomingTransactionsContext = current
|
incomingTransactionsContext = current
|
||||||
} else {
|
} else {
|
||||||
incomingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(starsContext: component.starsContext, subject: .incoming)
|
incomingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .starsContext(component.starsContext), mode: .incoming)
|
||||||
}
|
}
|
||||||
|
|
||||||
let outgoingTransactionsContext: StarsTransactionsContext
|
let outgoingTransactionsContext: StarsTransactionsContext
|
||||||
if let current = self.outgoingTransactionsContext {
|
if let current = self.outgoingTransactionsContext {
|
||||||
outgoingTransactionsContext = current
|
outgoingTransactionsContext = current
|
||||||
} else {
|
} else {
|
||||||
outgoingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(starsContext: component.starsContext, subject: .outgoing)
|
outgoingTransactionsContext = component.context.engine.payments.peerStarsTransactionsContext(subject: .starsContext(component.starsContext), mode: .outgoing)
|
||||||
}
|
}
|
||||||
|
|
||||||
panelItems.append(StarsTransactionsPanelContainerComponent.Item(
|
panelItems.append(StarsTransactionsPanelContainerComponent.Item(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user