From c4d10d07fefc02ec56a75c1ba07fe01ac01a94ae Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 28 Jun 2021 22:06:25 +0400 Subject: [PATCH] Add debugging --- .../NotificationServiceObjC/Sources/Serialization.m | 2 +- .../MtProtoKit/Sources/MTBindKeyMessageService.m | 10 ++++++++++ submodules/Postbox/Sources/Peer.swift | 10 +++++++--- .../TelegramCore/Sources/State/Serialization.swift | 2 +- .../TelegramUI/Sources/SharedAccountContext.swift | 7 ++++++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Telegram/NotificationService/NotificationServiceObjC/Sources/Serialization.m b/Telegram/NotificationService/NotificationServiceObjC/Sources/Serialization.m index 051b0659b0..61ca472a92 100644 --- a/Telegram/NotificationService/NotificationServiceObjC/Sources/Serialization.m +++ b/Telegram/NotificationService/NotificationServiceObjC/Sources/Serialization.m @@ -3,7 +3,7 @@ @implementation Serialization - (NSUInteger)currentLayer { - return 129; + return 131; } - (id _Nullable)parseMessage:(NSData * _Nullable)data { diff --git a/submodules/MtProtoKit/Sources/MTBindKeyMessageService.m b/submodules/MtProtoKit/Sources/MTBindKeyMessageService.m index 6a9b69723b..d352df9384 100644 --- a/submodules/MtProtoKit/Sources/MTBindKeyMessageService.m +++ b/submodules/MtProtoKit/Sources/MTBindKeyMessageService.m @@ -10,6 +10,8 @@ #import #import #import +#import +#import #import "MTInternalMessageParser.h" #import "MTRpcResultMessage.h" #import "MTBuffer.h" @@ -142,6 +144,14 @@ if (rpcResultMessage.data.length >= 4) { uint32_t signature = 0; [rpcResultMessage.data getBytes:&signature range:NSMakeRange(0, 4)]; + + id parsedMessage = [MTInternalMessageParser parseMessage:rpcResultMessage.data]; + if ([parsedMessage isKindOfClass:[MTRpcError class]]) { + if (MTLogEnabled()) { + MTRpcError *rpcError = (MTRpcError *)parsedMessage; + MTLog(@"[MTRequestMessageService#%p response for %" PRId64 " is error: %d: %@]", self, _currentMessageId, (int)rpcError.errorCode, rpcError.errorDescription); + } + } //boolTrue#997275b5 = Bool; if (signature == 0x997275b5U) { diff --git a/submodules/Postbox/Sources/Peer.swift b/submodules/Postbox/Sources/Peer.swift index 40f0332680..24ed7cce16 100644 --- a/submodules/Postbox/Sources/Peer.swift +++ b/submodules/Postbox/Sources/Peer.swift @@ -162,10 +162,16 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable { self.id = Id(rawValue: Int64(bitPattern: idHighBits | idLowBits)) } - assert(self.toInt64() == n) + assert(self._toInt64() == n) } public func toInt64() -> Int64 { + let result = self._toInt64() + assert(PeerId(result) == self) + return result + } + + private func _toInt64() -> Int64 { let data = UInt64(bitPattern: self.id.rawValue) let idLowBits = data & 0xffffffff @@ -191,8 +197,6 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable { result = Int64(bitPattern: data) } - assert(PeerId(result) == self) - return result } diff --git a/submodules/TelegramCore/Sources/State/Serialization.swift b/submodules/TelegramCore/Sources/State/Serialization.swift index 5de71bcf6d..49c4905c61 100644 --- a/submodules/TelegramCore/Sources/State/Serialization.swift +++ b/submodules/TelegramCore/Sources/State/Serialization.swift @@ -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! { diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index c40310a218..471284ed50 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -551,7 +551,12 @@ public final class SharedAccountContextImpl: SharedAccountContext { } if self.activeAccountsValue!.primary == nil && self.activeAccountsValue!.currentAuth == nil { - self.beginNewAuth(testingEnvironment: false) + #if DEBUG + let testingEnvironment = true + #else + let testingEnvironment = false + #endif + self.beginNewAuth(testingEnvironment: testingEnvironment) } })) })