Merge branch 'feature/secureid' of https://github.com/peter-iakovlev/TelegramCoreDev into feature/secureid

This commit is contained in:
Mikhail Filimonov 2018-04-27 18:00:22 +04:00
commit c36925e399
3 changed files with 24 additions and 5 deletions

View File

@ -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[..<subIndex])
hex = String(hex[subIndex...])
var ch: UInt32 = 0
Scanner(string: c).scanHexInt32(&ch)
if !Scanner(string: c).scanHexInt32(&ch) {
return Data()
}
var char = UInt8(ch)
data.append(&char, count: 1)
}
@ -886,4 +891,3 @@ public func setupAccount(_ account: Account, fetchCachedResourceRepresentation:
account.managedContactsDisposable.set(manageContacts(network: account.network, postbox: account.postbox).start())
account.managedStickerPacksDisposable.set(manageStickerPacks(network: account.network, postbox: account.postbox).start())
}

View File

@ -629,13 +629,18 @@ private func sortedUpdates(_ updates: [Api.Update]) -> [Api.Update] {
}
private func finalStateWithUpdates(account: Account, state: AccountMutableState, updates: [Api.Update], shouldPoll: Bool, missingUpdates: Bool, shouldResetChannels: Bool, updatesDate: Int32?) -> Signal<AccountFinalState, NoError> {
return account.network.currentGlobalTime
|> take(1)
|> mapToSignal { serverTime -> Signal<AccountFinalState, NoError> 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<AccountFinalState, NoError> {
var updatedState = state
var channelsToPoll = Set<PeerId>()
let serverTime: Int32 = Int32(account.network.globalTime)
for update in sortedUpdates(updates) {
switch update {
case let .updateChannelTooLong(_, channelId, channelPts):

View File

@ -546,6 +546,16 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate {
return context.globalTime()
}
public var currentGlobalTime: Signal<Double, NoError> {
return Signal { subscriber in
self.context.performBatchUpdates({
subscriber.putNext(self.context.globalTime())
subscriber.putCompletion()
})
return EmptyDisposable
}
}
public func requestMessageServiceAuthorizationRequired(_ requestMessageService: MTRequestMessageService!) {
self.loggedOut?()
}