mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Carry custom operations into the next cycle after reset
This commit is contained in:
@@ -296,6 +296,7 @@ public final class AccountStateManager {
|
||||
var collectedPollCompletionSubscribers: [(Int32, ([MessageId]) -> Void)] = []
|
||||
var collectedReplayAsynchronouslyBuiltFinalState: [(AccountFinalState, () -> Void)] = []
|
||||
var processEvents: [(Int32, AccountFinalStateEvents)] = []
|
||||
var customOperations: [(Int32, Signal<Void, NoError>)] = []
|
||||
|
||||
var replacedOperations: [AccountStateManagerOperation] = []
|
||||
|
||||
@@ -313,6 +314,8 @@ public final class AccountStateManager {
|
||||
collectedReplayAsynchronouslyBuiltFinalState.append((finalState, completion))
|
||||
case let .processEvents(operationId, events):
|
||||
processEvents.append((operationId, events))
|
||||
case let .custom(operationId, customSignal):
|
||||
customOperations.append((operationId, customSignal))
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -335,6 +338,10 @@ public final class AccountStateManager {
|
||||
replacedOperations.append(AccountStateManagerOperation(content: .processEvents(operationId, events)))
|
||||
}
|
||||
|
||||
for (operationId, customSignal) in customOperations {
|
||||
replacedOperations.append(AccountStateManagerOperation(content: .custom(operationId, customSignal)))
|
||||
}
|
||||
|
||||
self.operations.removeAll()
|
||||
self.operations.append(contentsOf: replacedOperations)
|
||||
}
|
||||
|
||||
@@ -60,40 +60,6 @@ private func dialogTopMessage(network: Network, postbox: Postbox, peerId: PeerId
|
||||
}
|
||||
}
|
||||
|
||||
func fetchPeerCloudReadState(network: Network, postbox: Postbox, peerId: PeerId, inputPeer: Api.InputPeer) -> Signal<PeerReadState?, NoError> {
|
||||
return network.request(Api.functions.messages.getPeerDialogs(peers: [.inputDialogPeer(peer: inputPeer)]))
|
||||
|> map { result -> PeerReadState? in
|
||||
switch result {
|
||||
case let .peerDialogs(dialogs, _, _, _, _):
|
||||
if let dialog = dialogs.filter({ $0.peerId == peerId }).first {
|
||||
let apiTopMessage: Int32
|
||||
let apiReadInboxMaxId: Int32
|
||||
let apiReadOutboxMaxId: Int32
|
||||
let apiUnreadCount: Int32
|
||||
let apiMarkedUnread: Bool
|
||||
switch dialog {
|
||||
case let .dialog(flags, _, topMessage, readInboxMaxId, readOutboxMaxId, unreadCount, _, _, _, _, _):
|
||||
apiTopMessage = topMessage
|
||||
apiReadInboxMaxId = readInboxMaxId
|
||||
apiReadOutboxMaxId = readOutboxMaxId
|
||||
apiUnreadCount = unreadCount
|
||||
apiMarkedUnread = (flags & (1 << 3)) != 0
|
||||
case .dialogFolder:
|
||||
assertionFailure()
|
||||
return nil
|
||||
}
|
||||
|
||||
return .idBased(maxIncomingReadId: apiReadInboxMaxId, maxOutgoingReadId: apiReadOutboxMaxId, maxKnownId: apiTopMessage, count: apiUnreadCount, markedUnread: apiMarkedUnread)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|> `catch` { _ -> Signal<PeerReadState?, NoError> in
|
||||
return .single(nil)
|
||||
}
|
||||
}
|
||||
|
||||
private func dialogReadState(network: Network, postbox: Postbox, peerId: PeerId) -> Signal<(PeerReadState, PeerReadStateMarker), PeerReadStateValidationError> {
|
||||
return dialogTopMessage(network: network, postbox: postbox, peerId: peerId)
|
||||
|> mapToSignal { topMessage -> Signal<(PeerReadState, PeerReadStateMarker), PeerReadStateValidationError> in
|
||||
|
||||
Reference in New Issue
Block a user