diff --git a/TelegramCore/Account.swift b/TelegramCore/Account.swift index 8a6cdc0f1c..1022d0f991 100644 --- a/TelegramCore/Account.swift +++ b/TelegramCore/Account.swift @@ -373,13 +373,18 @@ public func hexString(_ data: Data) -> String { public func dataWithHexString(_ string: String) -> Data { var hex = string + if hex.count % 2 != 0 { + return Data() + } var data = Data() while hex.count > 0 { let subIndex = hex.index(hex.startIndex, offsetBy: 2) let c = String(hex[.. [Api.Update] { } private func finalStateWithUpdates(account: Account, state: AccountMutableState, updates: [Api.Update], shouldPoll: Bool, missingUpdates: Bool, shouldResetChannels: Bool, updatesDate: Int32?) -> Signal { + return account.network.currentGlobalTime + |> take(1) + |> mapToSignal { serverTime -> Signal in + return finalStateWithUpdatesAndServerTime(account: account, state: state, updates: updates, shouldPoll: shouldPoll, missingUpdates: missingUpdates, shouldResetChannels: shouldResetChannels, updatesDate: updatesDate, serverTime: Int32(serverTime)) + } +} + +private func finalStateWithUpdatesAndServerTime(account: Account, state: AccountMutableState, updates: [Api.Update], shouldPoll: Bool, missingUpdates: Bool, shouldResetChannels: Bool, updatesDate: Int32?, serverTime: Int32) -> Signal { var updatedState = state var channelsToPoll = Set() - let serverTime: Int32 = Int32(account.network.globalTime) - - for update in sortedUpdates(updates) { switch update { case let .updateChannelTooLong(_, channelId, channelPts): diff --git a/TelegramCore/Network.swift b/TelegramCore/Network.swift index 216ed630d3..534a5641fd 100644 --- a/TelegramCore/Network.swift +++ b/TelegramCore/Network.swift @@ -546,6 +546,16 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate { return context.globalTime() } + public var currentGlobalTime: Signal { + return Signal { subscriber in + self.context.performBatchUpdates({ + subscriber.putNext(self.context.globalTime()) + subscriber.putCompletion() + }) + return EmptyDisposable + } + } + public func requestMessageServiceAuthorizationRequired(_ requestMessageService: MTRequestMessageService!) { self.loggedOut?() }