mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Support MSG_WAIT_TIMEOUT
This commit is contained in:
parent
a4b40dd216
commit
9e9af96594
@ -3,7 +3,7 @@
|
|||||||
@implementation Serialization
|
@implementation Serialization
|
||||||
|
|
||||||
- (NSUInteger)currentLayer {
|
- (NSUInteger)currentLayer {
|
||||||
return 129;
|
return 131;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id _Nullable)parseMessage:(NSData * _Nullable)data {
|
- (id _Nullable)parseMessage:(NSData * _Nullable)data {
|
||||||
|
|||||||
@ -10,5 +10,6 @@
|
|||||||
@property (nonatomic) NSUInteger floodWaitSeconds;
|
@property (nonatomic) NSUInteger floodWaitSeconds;
|
||||||
|
|
||||||
@property (nonatomic) bool waitingForTokenExport;
|
@property (nonatomic) bool waitingForTokenExport;
|
||||||
|
@property (nonatomic, strong) id waitingForRequestToComplete;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -196,6 +196,20 @@
|
|||||||
{
|
{
|
||||||
if (request.errorContext != nil)
|
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.requestContext == nil)
|
||||||
{
|
{
|
||||||
if (request.errorContext.minimalExecuteTime > currentTime + DBL_EPSILON)
|
if (request.errorContext.minimalExecuteTime > currentTime + DBL_EPSILON)
|
||||||
@ -407,10 +421,23 @@
|
|||||||
|
|
||||||
if (request.errorContext != nil)
|
if (request.errorContext != nil)
|
||||||
{
|
{
|
||||||
if (request.errorContext.minimalExecuteTime > currentTime)
|
if (request.errorContext.minimalExecuteTime > currentTime) {
|
||||||
continue;
|
continue;
|
||||||
if (request.errorContext.waitingForTokenExport)
|
}
|
||||||
|
if (request.errorContext.waitingForTokenExport) {
|
||||||
continue;
|
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))
|
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);
|
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)
|
else if (rpcError.errorCode == 420 || [rpcError.errorDescription rangeOfString:@"FLOOD_WAIT_"].location != NSNotFound)
|
||||||
{
|
{
|
||||||
if (request.errorContext == nil)
|
if (request.errorContext == nil)
|
||||||
|
|||||||
@ -1410,22 +1410,37 @@ public final class AccountViewTracker {
|
|||||||
let polled = self.polledChannel(peerId: peerId).start()
|
let polled = self.polledChannel(peerId: peerId).start()
|
||||||
|
|
||||||
var addHole = false
|
var addHole = false
|
||||||
let historyIsValid: Signal<Bool, NoError>
|
let pollingCompleted: Signal<Bool, NoError>
|
||||||
if let context = self.channelPollingContexts[peerId] {
|
if let context = self.channelPollingContexts[peerId] {
|
||||||
if !context.isUpdatedValue {
|
if !context.isUpdatedValue {
|
||||||
addHole = true
|
addHole = true
|
||||||
}
|
}
|
||||||
historyIsValid = context.isUpdated.get()
|
pollingCompleted = context.isUpdated.get()
|
||||||
} else {
|
} else {
|
||||||
addHole = true
|
addHole = true
|
||||||
historyIsValid = .single(true)
|
pollingCompleted = .single(true)
|
||||||
}
|
}
|
||||||
|
let isAutomaticallyTracked = Promise<Bool>(false)
|
||||||
if addHole {
|
if addHole {
|
||||||
let _ = self.account?.postbox.transaction({ transaction -> Void in
|
let _ = (self.account!.postbox.transaction { transaction -> Bool in
|
||||||
if transaction.getPeerChatListIndex(peerId) == nil {
|
if transaction.getPeerChatListIndex(peerId) == nil {
|
||||||
transaction.addHole(peerId: peerId, namespace: Namespaces.Message.Cloud, space: .everywhere, range: 1 ... (Int32.max - 1))
|
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
|
let validHistory = historyIsValid
|
||||||
|
|||||||
@ -210,7 +210,7 @@ public class BoxedMessage: NSObject {
|
|||||||
|
|
||||||
public class Serialization: NSObject, MTSerialization {
|
public class Serialization: NSObject, MTSerialization {
|
||||||
public func currentLayer() -> UInt {
|
public func currentLayer() -> UInt {
|
||||||
return 130
|
return 131
|
||||||
}
|
}
|
||||||
|
|
||||||
public func parseMessage(_ data: Data!) -> Any! {
|
public func parseMessage(_ data: Data!) -> Any! {
|
||||||
|
|||||||
@ -2331,10 +2331,16 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
} else {
|
} else {
|
||||||
webpage = self.chatPresentationInterfaceState.urlPreview?.1
|
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))
|
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 (cachedData, cachedDataMessages, readStateData) = extractAdditionalData(view: view, chatLocation: chatLocation)
|
||||||
|
|
||||||
let combinedInitialData = ChatHistoryCombinedInitialData(initialData: initialData, buttonKeyboardMessage: view.topTaggedMessages.first, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData)
|
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 {
|
if preloaded {
|
||||||
return .HistoryView(view: view, type: .Generic(type: updateType), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: combinedInitialData, id: location.id)
|
return .HistoryView(view: view, type: .Generic(type: updateType), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: combinedInitialData, id: location.id)
|
||||||
} else {
|
} else {
|
||||||
|
if view.isLoading {
|
||||||
|
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
|
||||||
|
}
|
||||||
var scrollPosition: ChatHistoryViewScrollPosition?
|
var scrollPosition: ChatHistoryViewScrollPosition?
|
||||||
|
|
||||||
let canScrollToRead: Bool
|
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 {
|
} else if view.isAddedToChatList, let historyScrollState = (initialData?.chatInterfaceState as? ChatInterfaceState)?.historyScrollState, tagMask == nil {
|
||||||
scrollPosition = .positionRestoration(index: historyScrollState.messageIndex, relativeOffset: CGFloat(historyScrollState.relativeOffset))
|
scrollPosition = .positionRestoration(index: historyScrollState.messageIndex, relativeOffset: CGFloat(historyScrollState.relativeOffset))
|
||||||
} else {
|
} 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) {
|
if view.entries.isEmpty && (view.holeEarlier || view.holeLater) {
|
||||||
fadeIn = true
|
fadeIn = true
|
||||||
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
|
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 (cachedData, cachedDataMessages, readStateData) = extractAdditionalData(view: view, chatLocation: chatLocation)
|
||||||
|
|
||||||
let combinedInitialData = ChatHistoryCombinedInitialData(initialData: initialData, buttonKeyboardMessage: view.topTaggedMessages.first, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData)
|
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 {
|
if preloaded {
|
||||||
return .HistoryView(view: view, type: .Generic(type: updateType), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: combinedInitialData, id: location.id)
|
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