mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 04:08:07 +00:00
no message
This commit is contained in:
parent
501de4a5fe
commit
bcc7d11fdb
@ -885,6 +885,16 @@ public class Account {
|
||||
|
||||
public let notificationToken = Promise<Data>()
|
||||
public let voipToken = Promise<Data>()
|
||||
|
||||
private var notificationTokensVersionValue = 0 {
|
||||
didSet {
|
||||
self.notificationTokensVersionPromise.set(self.notificationTokensVersionValue)
|
||||
}
|
||||
}
|
||||
func updateNotificationTokensVersion() {
|
||||
self.notificationTokensVersionValue += 1
|
||||
}
|
||||
private let notificationTokensVersionPromise = ValuePromise<Int>(0)
|
||||
private let notificationTokenDisposable = MetaDisposable()
|
||||
private let voipTokenDisposable = MetaDisposable()
|
||||
|
||||
@ -1017,58 +1027,58 @@ public class Account {
|
||||
|
||||
self.networkTypeValue.set(currentNetworkType())
|
||||
|
||||
let appliedNotificationToken = self.notificationToken.get()
|
||||
|> distinctUntilChanged
|
||||
|> mapToSignal { token -> Signal<Void, NoError> in
|
||||
var tokenString = ""
|
||||
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
for i in 0 ..< token.count {
|
||||
let byte = bytes.advanced(by: i).pointee
|
||||
tokenString = tokenString.appendingFormat("%02x", Int32(byte))
|
||||
let appliedNotificationToken = combineLatest(self.notificationToken.get(), self.notificationTokensVersionPromise.get())
|
||||
|> distinctUntilChanged(isEqual: { $0 == $1 })
|
||||
|> mapToSignal { token, _ -> Signal<Void, NoError> in
|
||||
var tokenString = ""
|
||||
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
for i in 0 ..< token.count {
|
||||
let byte = bytes.advanced(by: i).pointee
|
||||
tokenString = tokenString.appendingFormat("%02x", Int32(byte))
|
||||
}
|
||||
}
|
||||
|
||||
var appSandbox: Api.Bool = .boolFalse
|
||||
#if DEBUG
|
||||
appSandbox = .boolTrue
|
||||
#endif
|
||||
|
||||
return masterNotificationsKey(account: self, ignoreDisabled: false)
|
||||
|> mapToSignal { secret -> Signal<Void, NoError> in
|
||||
return network.request(Api.functions.account.registerDevice(tokenType: 1, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|
||||
|> retryRequest
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
|
||||
var appSandbox: Api.Bool = .boolFalse
|
||||
#if DEBUG
|
||||
appSandbox = .boolTrue
|
||||
#endif
|
||||
|
||||
return masterNotificationsKey(account: self, ignoreDisabled: false)
|
||||
|> mapToSignal { secret -> Signal<Void, NoError> in
|
||||
return network.request(Api.functions.account.registerDevice(tokenType: 1, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|
||||
|> retryRequest
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.notificationTokenDisposable.set(appliedNotificationToken.start())
|
||||
|
||||
let appliedVoipToken = self.voipToken.get()
|
||||
|> distinctUntilChanged
|
||||
|> mapToSignal { token -> Signal<Void, NoError> in
|
||||
var tokenString = ""
|
||||
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
for i in 0 ..< token.count {
|
||||
let byte = bytes.advanced(by: i).pointee
|
||||
tokenString = tokenString.appendingFormat("%02x", Int32(byte))
|
||||
}
|
||||
}
|
||||
|
||||
var appSandbox: Api.Bool = .boolFalse
|
||||
#if DEBUG
|
||||
appSandbox = .boolTrue
|
||||
#endif
|
||||
|
||||
return masterNotificationsKey(account: self, ignoreDisabled: false)
|
||||
|> mapToSignal { secret -> Signal<Void, NoError> in
|
||||
return network.request(Api.functions.account.registerDevice(tokenType: 9, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|
||||
|> retryRequest
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
let appliedVoipToken = combineLatest(self.voipToken.get(), self.notificationTokensVersionPromise.get())
|
||||
|> distinctUntilChanged(isEqual: { $0 == $1 })
|
||||
|> mapToSignal { token, _ -> Signal<Void, NoError> in
|
||||
var tokenString = ""
|
||||
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
for i in 0 ..< token.count {
|
||||
let byte = bytes.advanced(by: i).pointee
|
||||
tokenString = tokenString.appendingFormat("%02x", Int32(byte))
|
||||
}
|
||||
}
|
||||
|
||||
var appSandbox: Api.Bool = .boolFalse
|
||||
#if DEBUG
|
||||
appSandbox = .boolTrue
|
||||
#endif
|
||||
|
||||
return masterNotificationsKey(account: self, ignoreDisabled: false)
|
||||
|> mapToSignal { secret -> Signal<Void, NoError> in
|
||||
return network.request(Api.functions.account.registerDevice(tokenType: 9, token: tokenString, appSandbox: appSandbox, secret: Buffer(data: secret.data), otherUids: []))
|
||||
|> retryRequest
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
}
|
||||
self.voipTokenDisposable.set(appliedVoipToken.start())
|
||||
|
||||
let serviceTasksMasterBecomeMaster = shouldBeServiceTaskMaster.get()
|
||||
|
||||
@ -261,24 +261,26 @@ private final class MultipartUploadManager {
|
||||
case let .data(data):
|
||||
fileData = data
|
||||
}
|
||||
let partData = self.state.transformHeader(data: fileData!.subdata(in: partOffset ..< (partOffset + partSize)))
|
||||
var currentBigTotalParts: Int? = nil
|
||||
if self.bigParts {
|
||||
let totalParts = (resourceData.size / self.defaultPartSize) + (resourceData.size % self.defaultPartSize == 0 ? 0 : 1)
|
||||
currentBigTotalParts = totalParts
|
||||
}
|
||||
self.headerPartState = .uploading
|
||||
let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts, bigPart: self.bigParts))
|
||||
|> deliverOn(self.queue)
|
||||
self.uploadingParts[0] = (partSize, part.start(error: { [weak self] _ in
|
||||
self?.completed(nil)
|
||||
}, completed: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
let _ = strongSelf.uploadingParts.removeValue(forKey: 0)
|
||||
strongSelf.headerPartState = .ready
|
||||
strongSelf.checkState()
|
||||
if let fileData = fileData {
|
||||
let partData = self.state.transformHeader(data: fileData.subdata(in: partOffset ..< (partOffset + partSize)))
|
||||
var currentBigTotalParts: Int? = nil
|
||||
if self.bigParts {
|
||||
let totalParts = (resourceData.size / self.defaultPartSize) + (resourceData.size % self.defaultPartSize == 0 ? 0 : 1)
|
||||
currentBigTotalParts = totalParts
|
||||
}
|
||||
}))
|
||||
self.headerPartState = .uploading
|
||||
let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts, bigPart: self.bigParts))
|
||||
|> deliverOn(self.queue)
|
||||
self.uploadingParts[0] = (partSize, part.start(error: { [weak self] _ in
|
||||
self?.completed(nil)
|
||||
}, completed: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
let _ = strongSelf.uploadingParts.removeValue(forKey: 0)
|
||||
strongSelf.headerPartState = .ready
|
||||
strongSelf.checkState()
|
||||
}
|
||||
}))
|
||||
}
|
||||
case .uploading:
|
||||
break
|
||||
}
|
||||
|
||||
@ -9,17 +9,17 @@ import Foundation
|
||||
|
||||
public func requestRecentAccountSessions(account: Account) -> Signal<[RecentAccountSession], NoError> {
|
||||
return account.network.request(Api.functions.account.getAuthorizations())
|
||||
|> retryRequest
|
||||
|> map { result -> [RecentAccountSession] in
|
||||
var sessions: [RecentAccountSession] = []
|
||||
switch result {
|
||||
case let .authorizations(authorizations):
|
||||
for authorization in authorizations {
|
||||
sessions.append(RecentAccountSession(apiAuthorization: authorization))
|
||||
}
|
||||
}
|
||||
return sessions
|
||||
|> retryRequest
|
||||
|> map { result -> [RecentAccountSession] in
|
||||
var sessions: [RecentAccountSession] = []
|
||||
switch result {
|
||||
case let .authorizations(authorizations):
|
||||
for authorization in authorizations {
|
||||
sessions.append(RecentAccountSession(apiAuthorization: authorization))
|
||||
}
|
||||
}
|
||||
return sessions
|
||||
}
|
||||
}
|
||||
|
||||
public enum TerminateSessionError {
|
||||
@ -29,19 +29,23 @@ public enum TerminateSessionError {
|
||||
|
||||
public func terminateAccountSession(account: Account, hash: Int64) -> Signal<Void, TerminateSessionError> {
|
||||
return account.network.request(Api.functions.account.resetAuthorization(hash: hash))
|
||||
|> map {_ in}
|
||||
|> mapError { error -> TerminateSessionError in
|
||||
if error.errorCode == 406 {
|
||||
return .freshReset
|
||||
}
|
||||
return .generic
|
||||
|> mapError { error -> TerminateSessionError in
|
||||
if error.errorCode == 406 {
|
||||
return .freshReset
|
||||
}
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { _ -> Signal<Void, TerminateSessionError> in
|
||||
account.updateNotificationTokensVersion()
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
|
||||
public func terminateOtherAccountSessions(account: Account) -> Signal<Void, NoError> {
|
||||
return account.network.request(Api.functions.auth.resetAuthorizations())
|
||||
|> retryRequest
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
|> retryRequest
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
account.updateNotificationTokensVersion()
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user