mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Support MSG_WAIT_TIMEOUT
This commit is contained in:
parent
a4b40dd216
commit
9e9af96594
@ -3,7 +3,7 @@
|
||||
@implementation Serialization
|
||||
|
||||
- (NSUInteger)currentLayer {
|
||||
return 129;
|
||||
return 131;
|
||||
}
|
||||
|
||||
- (id _Nullable)parseMessage:(NSData * _Nullable)data {
|
||||
|
@ -10,5 +10,6 @@
|
||||
@property (nonatomic) NSUInteger floodWaitSeconds;
|
||||
|
||||
@property (nonatomic) bool waitingForTokenExport;
|
||||
@property (nonatomic, strong) id waitingForRequestToComplete;
|
||||
|
||||
@end
|
||||
|
@ -196,6 +196,20 @@
|
||||
{
|
||||
if (request.errorContext != nil)
|
||||
{
|
||||
if (request.errorContext.waitingForRequestToComplete != nil) {
|
||||
bool foundDependency = false;
|
||||
for (MTRequest *anotherRequest in _requests) {
|
||||
if (request.errorContext.waitingForRequestToComplete == anotherRequest.internalId) {
|
||||
foundDependency = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundDependency) {
|
||||
needTransaction = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.requestContext == nil)
|
||||
{
|
||||
if (request.errorContext.minimalExecuteTime > currentTime + DBL_EPSILON)
|
||||
@ -407,10 +421,23 @@
|
||||
|
||||
if (request.errorContext != nil)
|
||||
{
|
||||
if (request.errorContext.minimalExecuteTime > currentTime)
|
||||
if (request.errorContext.minimalExecuteTime > currentTime) {
|
||||
continue;
|
||||
if (request.errorContext.waitingForTokenExport)
|
||||
}
|
||||
if (request.errorContext.waitingForTokenExport) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool foundDependency = false;
|
||||
for (MTRequest *anotherRequest in _requests) {
|
||||
if (request.errorContext.waitingForRequestToComplete == anotherRequest.internalId) {
|
||||
foundDependency = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundDependency) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.requestContext == nil || (!request.requestContext.waitingForMessageId && !request.requestContext.delivered && request.requestContext.transactionId == nil))
|
||||
@ -690,6 +717,20 @@
|
||||
request.errorContext.minimalExecuteTime = MAX(request.errorContext.minimalExecuteTime, MTAbsoluteSystemTime() + 2.0);
|
||||
}
|
||||
}
|
||||
else if (rpcError.errorCode == 400 || [rpcError.errorDescription isEqualToString:@"MSG_WAIT_TIMEOUT"])
|
||||
{
|
||||
if (request.errorContext == nil) {
|
||||
request.errorContext = [[MTRequestErrorContext alloc] init];
|
||||
}
|
||||
|
||||
for (MTRequest *anotherRequest in _requests) {
|
||||
if (request.shouldDependOnRequest != nil && request.shouldDependOnRequest(anotherRequest)) {
|
||||
request.errorContext.waitingForRequestToComplete = anotherRequest.internalId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
restartRequest = true;
|
||||
}
|
||||
else if (rpcError.errorCode == 420 || [rpcError.errorDescription rangeOfString:@"FLOOD_WAIT_"].location != NSNotFound)
|
||||
{
|
||||
if (request.errorContext == nil)
|
||||
|
@ -1410,22 +1410,37 @@ public final class AccountViewTracker {
|
||||
let polled = self.polledChannel(peerId: peerId).start()
|
||||
|
||||
var addHole = false
|
||||
let historyIsValid: Signal<Bool, NoError>
|
||||
let pollingCompleted: Signal<Bool, NoError>
|
||||
if let context = self.channelPollingContexts[peerId] {
|
||||
if !context.isUpdatedValue {
|
||||
addHole = true
|
||||
}
|
||||
historyIsValid = context.isUpdated.get()
|
||||
pollingCompleted = context.isUpdated.get()
|
||||
} else {
|
||||
addHole = true
|
||||
historyIsValid = .single(true)
|
||||
pollingCompleted = .single(true)
|
||||
}
|
||||
let isAutomaticallyTracked = Promise<Bool>(false)
|
||||
if addHole {
|
||||
let _ = self.account?.postbox.transaction({ transaction -> Void in
|
||||
let _ = (self.account!.postbox.transaction { transaction -> Bool in
|
||||
if transaction.getPeerChatListIndex(peerId) == nil {
|
||||
transaction.addHole(peerId: peerId, namespace: Namespaces.Message.Cloud, space: .everywhere, range: 1 ... (Int32.max - 1))
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|> deliverOn(self.queue)).start(next: { isTracked in
|
||||
isAutomaticallyTracked.set(.single(isTracked))
|
||||
})
|
||||
}
|
||||
|
||||
let historyIsValid = combineLatest(queue: self.queue,
|
||||
pollingCompleted,
|
||||
isAutomaticallyTracked.get()
|
||||
)
|
||||
|> map { lhs, rhs -> Bool in
|
||||
return lhs || rhs
|
||||
}
|
||||
|
||||
let validHistory = historyIsValid
|
||||
|
@ -210,7 +210,7 @@ public class BoxedMessage: NSObject {
|
||||
|
||||
public class Serialization: NSObject, MTSerialization {
|
||||
public func currentLayer() -> UInt {
|
||||
return 130
|
||||
return 131
|
||||
}
|
||||
|
||||
public func parseMessage(_ data: Data!) -> Any! {
|
||||
|
@ -2331,10 +2331,16 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
} else {
|
||||
webpage = self.chatPresentationInterfaceState.urlPreview?.1
|
||||
}
|
||||
#if DEBUG
|
||||
//webpage = nil
|
||||
#endif
|
||||
|
||||
messages.append(.message(text: text.string, attributes: attributes, mediaReference: webpage.flatMap(AnyMediaReference.standalone), replyToMessageId: self.chatPresentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil))
|
||||
|
||||
#if DEBUG
|
||||
if text.string == "sleep" {
|
||||
messages.append(messages[0])
|
||||
messages.append(messages[0])
|
||||
messages.append(messages[0])
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,15 +93,13 @@ func chatHistoryViewForLocation(_ location: ChatHistoryLocationInput, context: A
|
||||
let (cachedData, cachedDataMessages, readStateData) = extractAdditionalData(view: view, chatLocation: chatLocation)
|
||||
|
||||
let combinedInitialData = ChatHistoryCombinedInitialData(initialData: initialData, buttonKeyboardMessage: view.topTaggedMessages.first, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData)
|
||||
|
||||
if view.isLoading {
|
||||
preloaded = false
|
||||
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
|
||||
}
|
||||
|
||||
if preloaded {
|
||||
return .HistoryView(view: view, type: .Generic(type: updateType), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: combinedInitialData, id: location.id)
|
||||
} else {
|
||||
if view.isLoading {
|
||||
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
|
||||
}
|
||||
var scrollPosition: ChatHistoryViewScrollPosition?
|
||||
|
||||
let canScrollToRead: Bool
|
||||
@ -155,6 +153,12 @@ func chatHistoryViewForLocation(_ location: ChatHistoryLocationInput, context: A
|
||||
} else if view.isAddedToChatList, let historyScrollState = (initialData?.chatInterfaceState as? ChatInterfaceState)?.historyScrollState, tagMask == nil {
|
||||
scrollPosition = .positionRestoration(index: historyScrollState.messageIndex, relativeOffset: CGFloat(historyScrollState.relativeOffset))
|
||||
} else {
|
||||
if case .peer = chatLocation, !view.isAddedToChatList {
|
||||
if view.holeEarlier && view.entries.count <= 2 {
|
||||
fadeIn = true
|
||||
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
|
||||
}
|
||||
}
|
||||
if view.entries.isEmpty && (view.holeEarlier || view.holeLater) {
|
||||
fadeIn = true
|
||||
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
|
||||
@ -181,11 +185,6 @@ func chatHistoryViewForLocation(_ location: ChatHistoryLocationInput, context: A
|
||||
let (cachedData, cachedDataMessages, readStateData) = extractAdditionalData(view: view, chatLocation: chatLocation)
|
||||
|
||||
let combinedInitialData = ChatHistoryCombinedInitialData(initialData: initialData, buttonKeyboardMessage: view.topTaggedMessages.first, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData)
|
||||
|
||||
if view.isLoading {
|
||||
preloaded = false
|
||||
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
|
||||
}
|
||||
|
||||
if preloaded {
|
||||
return .HistoryView(view: view, type: .Generic(type: updateType), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: combinedInitialData, id: location.id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user