mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 20:28:05 +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 notificationToken = Promise<Data>()
|
||||||
public let voipToken = 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 notificationTokenDisposable = MetaDisposable()
|
||||||
private let voipTokenDisposable = MetaDisposable()
|
private let voipTokenDisposable = MetaDisposable()
|
||||||
|
|
||||||
@ -1017,58 +1027,58 @@ public class Account {
|
|||||||
|
|
||||||
self.networkTypeValue.set(currentNetworkType())
|
self.networkTypeValue.set(currentNetworkType())
|
||||||
|
|
||||||
let appliedNotificationToken = self.notificationToken.get()
|
let appliedNotificationToken = combineLatest(self.notificationToken.get(), self.notificationTokensVersionPromise.get())
|
||||||
|> distinctUntilChanged
|
|> distinctUntilChanged(isEqual: { $0 == $1 })
|
||||||
|> mapToSignal { token -> Signal<Void, NoError> in
|
|> mapToSignal { token, _ -> Signal<Void, NoError> in
|
||||||
var tokenString = ""
|
var tokenString = ""
|
||||||
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||||
for i in 0 ..< token.count {
|
for i in 0 ..< token.count {
|
||||||
let byte = bytes.advanced(by: i).pointee
|
let byte = bytes.advanced(by: i).pointee
|
||||||
tokenString = tokenString.appendingFormat("%02x", Int32(byte))
|
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())
|
self.notificationTokenDisposable.set(appliedNotificationToken.start())
|
||||||
|
|
||||||
let appliedVoipToken = self.voipToken.get()
|
let appliedVoipToken = combineLatest(self.voipToken.get(), self.notificationTokensVersionPromise.get())
|
||||||
|> distinctUntilChanged
|
|> distinctUntilChanged(isEqual: { $0 == $1 })
|
||||||
|> mapToSignal { token -> Signal<Void, NoError> in
|
|> mapToSignal { token, _ -> Signal<Void, NoError> in
|
||||||
var tokenString = ""
|
var tokenString = ""
|
||||||
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
token.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||||
for i in 0 ..< token.count {
|
for i in 0 ..< token.count {
|
||||||
let byte = bytes.advanced(by: i).pointee
|
let byte = bytes.advanced(by: i).pointee
|
||||||
tokenString = tokenString.appendingFormat("%02x", Int32(byte))
|
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
self.voipTokenDisposable.set(appliedVoipToken.start())
|
||||||
|
|
||||||
let serviceTasksMasterBecomeMaster = shouldBeServiceTaskMaster.get()
|
let serviceTasksMasterBecomeMaster = shouldBeServiceTaskMaster.get()
|
||||||
|
|||||||
@ -261,24 +261,26 @@ private final class MultipartUploadManager {
|
|||||||
case let .data(data):
|
case let .data(data):
|
||||||
fileData = data
|
fileData = data
|
||||||
}
|
}
|
||||||
let partData = self.state.transformHeader(data: fileData!.subdata(in: partOffset ..< (partOffset + partSize)))
|
if let fileData = fileData {
|
||||||
var currentBigTotalParts: Int? = nil
|
let partData = self.state.transformHeader(data: fileData.subdata(in: partOffset ..< (partOffset + partSize)))
|
||||||
if self.bigParts {
|
var currentBigTotalParts: Int? = nil
|
||||||
let totalParts = (resourceData.size / self.defaultPartSize) + (resourceData.size % self.defaultPartSize == 0 ? 0 : 1)
|
if self.bigParts {
|
||||||
currentBigTotalParts = totalParts
|
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()
|
|
||||||
}
|
}
|
||||||
}))
|
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:
|
case .uploading:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,17 +9,17 @@ import Foundation
|
|||||||
|
|
||||||
public func requestRecentAccountSessions(account: Account) -> Signal<[RecentAccountSession], NoError> {
|
public func requestRecentAccountSessions(account: Account) -> Signal<[RecentAccountSession], NoError> {
|
||||||
return account.network.request(Api.functions.account.getAuthorizations())
|
return account.network.request(Api.functions.account.getAuthorizations())
|
||||||
|> retryRequest
|
|> retryRequest
|
||||||
|> map { result -> [RecentAccountSession] in
|
|> map { result -> [RecentAccountSession] in
|
||||||
var sessions: [RecentAccountSession] = []
|
var sessions: [RecentAccountSession] = []
|
||||||
switch result {
|
switch result {
|
||||||
case let .authorizations(authorizations):
|
case let .authorizations(authorizations):
|
||||||
for authorization in authorizations {
|
for authorization in authorizations {
|
||||||
sessions.append(RecentAccountSession(apiAuthorization: authorization))
|
sessions.append(RecentAccountSession(apiAuthorization: authorization))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return sessions
|
|
||||||
}
|
}
|
||||||
|
return sessions
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TerminateSessionError {
|
public enum TerminateSessionError {
|
||||||
@ -29,19 +29,23 @@ public enum TerminateSessionError {
|
|||||||
|
|
||||||
public func terminateAccountSession(account: Account, hash: Int64) -> Signal<Void, TerminateSessionError> {
|
public func terminateAccountSession(account: Account, hash: Int64) -> Signal<Void, TerminateSessionError> {
|
||||||
return account.network.request(Api.functions.account.resetAuthorization(hash: hash))
|
return account.network.request(Api.functions.account.resetAuthorization(hash: hash))
|
||||||
|> map {_ in}
|
|> mapError { error -> TerminateSessionError in
|
||||||
|> mapError { error -> TerminateSessionError in
|
if error.errorCode == 406 {
|
||||||
if error.errorCode == 406 {
|
return .freshReset
|
||||||
return .freshReset
|
|
||||||
}
|
|
||||||
return .generic
|
|
||||||
}
|
}
|
||||||
|
return .generic
|
||||||
|
}
|
||||||
|
|> mapToSignal { _ -> Signal<Void, TerminateSessionError> in
|
||||||
|
account.updateNotificationTokensVersion()
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func terminateOtherAccountSessions(account: Account) -> Signal<Void, NoError> {
|
public func terminateOtherAccountSessions(account: Account) -> Signal<Void, NoError> {
|
||||||
return account.network.request(Api.functions.auth.resetAuthorizations())
|
return account.network.request(Api.functions.auth.resetAuthorizations())
|
||||||
|> retryRequest
|
|> retryRequest
|
||||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||||
return .complete()
|
account.updateNotificationTokensVersion()
|
||||||
}
|
return .complete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user