Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2021-02-19 20:27:57 +04:00
commit 8de942bdd1
10 changed files with 89 additions and 24 deletions

View File

@ -154,7 +154,19 @@ dispatch_block_t fetchImage(BuildConfig *buildConfig, AccountProxyConnection * _
for (NSNumber *datacenterId in account.datacenters) { for (NSNumber *datacenterId in account.datacenters) {
AccountDatacenterInfo *info = account.datacenters[datacenterId]; AccountDatacenterInfo *info = account.datacenters[datacenterId];
[context updateAuthInfoForDatacenterWithId:[datacenterId intValue] authInfo:[[MTDatacenterAuthInfo alloc] initWithAuthKey:info.masterKey.data authKeyId:info.masterKey.keyId saltSet:@[] authKeyAttributes:@{}] selector:MTDatacenterAuthInfoSelectorPersistent]; MTDatacenterAuthInfo *authInfo = [[MTDatacenterAuthInfo alloc] initWithAuthKey:info.masterKey.data authKeyId:info.masterKey.keyId saltSet:@[] authKeyAttributes:@{}];
[context updateAuthInfoForDatacenterWithId:[datacenterId intValue] authInfo:authInfo selector:MTDatacenterAuthInfoSelectorPersistent];
if (info.ephemeralMainKey != nil) {
MTDatacenterAuthInfo *ephemeralMainAuthInfo = [[MTDatacenterAuthInfo alloc] initWithAuthKey:info.ephemeralMainKey.data authKeyId:info.ephemeralMainKey.keyId saltSet:@[] authKeyAttributes:@{}];
[context updateAuthInfoForDatacenterWithId:[datacenterId intValue] authInfo:ephemeralMainAuthInfo selector:MTDatacenterAuthInfoSelectorEphemeralMain];
}
if (info.ephemeralMediaKey != nil) {
MTDatacenterAuthInfo *ephemeralMediaAuthInfo = [[MTDatacenterAuthInfo alloc] initWithAuthKey:info.ephemeralMediaKey.data authKeyId:info.ephemeralMediaKey.keyId saltSet:@[] authKeyAttributes:@{}];
[context updateAuthInfoForDatacenterWithId:[datacenterId intValue] authInfo:ephemeralMediaAuthInfo selector:MTDatacenterAuthInfoSelectorEphemeralMedia];
}
} }
MTProto *mtProto = [[MTProto alloc] initWithContext:context datacenterId:datacenterId usageCalculationInfo:nil requiredAuthToken:nil authTokenMasterDatacenterId:0]; MTProto *mtProto = [[MTProto alloc] initWithContext:context datacenterId:datacenterId usageCalculationInfo:nil requiredAuthToken:nil authTokenMasterDatacenterId:0];

View File

@ -157,7 +157,7 @@ static void reportMemory() {
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
if (_rootPath == nil) { if (_rootPath == nil) {
_bestAttemptContent = request.content; _bestAttemptContent = (UNMutableNotificationContent *)[request.content mutableCopy];
[self completeWithBestAttemptContent]; [self completeWithBestAttemptContent];
return; return;
} }

View File

@ -3,7 +3,7 @@
@implementation Serialization @implementation Serialization
- (NSUInteger)currentLayer { - (NSUInteger)currentLayer {
return 122; return 124;
} }
- (id _Nullable)parseMessage:(NSData * _Nullable)data { - (id _Nullable)parseMessage:(NSData * _Nullable)data {

View File

@ -28,6 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface AccountDatacenterInfo: NSObject @interface AccountDatacenterInfo: NSObject
@property (nonatomic, strong, readonly) AccountDatacenterKey *masterKey; @property (nonatomic, strong, readonly) AccountDatacenterKey *masterKey;
@property (nonatomic, strong, readonly) AccountDatacenterKey *ephemeralMainKey;
@property (nonatomic, strong, readonly) AccountDatacenterKey *ephemeralMediaKey;
@property (nonatomic, strong, readonly) NSArray<AccountDatacenterAddress *> *addressList; @property (nonatomic, strong, readonly) NSArray<AccountDatacenterAddress *> *addressList;
@end @end

View File

@ -116,10 +116,12 @@
@implementation AccountDatacenterInfo @implementation AccountDatacenterInfo
- (instancetype)initWithMasterKey:(AccountDatacenterKey *)masterKey addressList:(NSArray<AccountDatacenterAddress *> *)addressList { - (instancetype)initWithMasterKey:(AccountDatacenterKey *)masterKey ephemeralMainKey:(AccountDatacenterKey * _Nullable)ephemeralMainKey ephemeralMediaKey:(AccountDatacenterKey * _Nullable)ephemeralMediaKey addressList:(NSArray<AccountDatacenterAddress *> *)addressList {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
_masterKey = masterKey; _masterKey = masterKey;
_ephemeralMainKey = ephemeralMainKey;
_ephemeralMediaKey = ephemeralMediaKey;
_addressList = addressList; _addressList = addressList;
} }
return self; return self;
@ -135,6 +137,18 @@
return nil; return nil;
} }
NSDictionary *ephemeralMainKeyDict = dict[@"ephemeralMainKey"];
AccountDatacenterKey *ephemeralMainKey = nil;
if ([ephemeralMainKeyDict isKindOfClass:[NSDictionary class]]) {
ephemeralMainKey = [AccountDatacenterKey parse:ephemeralMainKeyDict];
}
NSDictionary *ephemeralMediaKeyDict = dict[@"ephemeralMediaKey"];
AccountDatacenterKey *ephemeralMediaKey = nil;
if ([ephemeralMediaKeyDict isKindOfClass:[NSDictionary class]]) {
ephemeralMediaKey = [AccountDatacenterKey parse:ephemeralMediaKeyDict];
}
NSArray *addressListArray = dict[@"addressList"]; NSArray *addressListArray = dict[@"addressList"];
if (![addressListArray isKindOfClass:[NSArray class]]) { if (![addressListArray isKindOfClass:[NSArray class]]) {
return nil; return nil;
@ -152,7 +166,7 @@
[addressList addObject:address]; [addressList addObject:address];
} }
return [[AccountDatacenterInfo alloc] initWithMasterKey:masterKey addressList:addressList]; return [[AccountDatacenterInfo alloc] initWithMasterKey:masterKey ephemeralMainKey:ephemeralMainKey ephemeralMediaKey:ephemeralMediaKey addressList:addressList];
} }
@end @end

View File

@ -36,10 +36,14 @@ public struct AccountDatacenterAddress: Codable {
public struct AccountDatacenterInfo: Codable { public struct AccountDatacenterInfo: Codable {
public let masterKey: AccountDatacenterKey public let masterKey: AccountDatacenterKey
public let ephemeralMainKey: AccountDatacenterKey?
public let ephemeralMediaKey: AccountDatacenterKey?
public let addressList: [AccountDatacenterAddress] public let addressList: [AccountDatacenterAddress]
public init(masterKey: AccountDatacenterKey, addressList: [AccountDatacenterAddress]) { public init(masterKey: AccountDatacenterKey, ephemeralMainKey: AccountDatacenterKey?, ephemeralMediaKey: AccountDatacenterKey?, addressList: [AccountDatacenterAddress]) {
self.masterKey = masterKey self.masterKey = masterKey
self.ephemeralMainKey = ephemeralMainKey
self.ephemeralMediaKey = ephemeralMediaKey
self.addressList = addressList self.addressList = addressList
} }
} }

View File

@ -120,7 +120,7 @@ private func peerAutoremoveSetupEntries(peer: Peer?, presentationData: Presentat
24 * 60 * 60, 24 * 60 * 60,
24 * 60 * 60 * 7 24 * 60 * 60 * 7
] ]
if isDebug || true { if isDebug {
availableValues[1] = 5 availableValues[1] = 5
availableValues[2] = 5 * 60 availableValues[2] = 5 * 60
} }

View File

@ -31,6 +31,7 @@ import PresentationDataUtils
import TelegramIntents import TelegramIntents
import AccountUtils import AccountUtils
import CoreSpotlight import CoreSpotlight
import LightweightAccountData
#if canImport(BackgroundTasks) #if canImport(BackgroundTasks)
import BackgroundTasks import BackgroundTasks
@ -809,8 +810,13 @@ final class SharedApplicationContext {
|> map { _, accounts, _ -> [Account] in |> map { _, accounts, _ -> [Account] in
return accounts.map({ $0.1 }) return accounts.map({ $0.1 })
} }
let _ = (sharedAccountInfos(accountManager: sharedContext.accountManager, accounts: rawAccounts) let storeQueue = Queue()
|> deliverOn(Queue())).start(next: { infos in let _ = (
sharedAccountInfos(accountManager: sharedContext.accountManager, accounts: rawAccounts)
|> then(Signal<StoredAccountInfos, NoError>.complete() |> delay(10.0, queue: storeQueue))
|> restart
|> deliverOn(storeQueue)
).start(next: { infos in
storeAccountsData(rootPath: rootPath, accounts: infos) storeAccountsData(rootPath: rootPath, accounts: infos)
}) })

View File

@ -29,7 +29,23 @@ private func accountInfo(account: Account) -> Signal<StoredAccountInfo, NoError>
let secret: Data? = address.secret let secret: Data? = address.secret
addressList.append(AccountDatacenterAddress(host: host, port: Int32(address.port), isMedia: address.preferForMedia, secret: secret)) addressList.append(AccountDatacenterAddress(host: host, port: Int32(address.port), isMedia: address.preferForMedia, secret: secret))
} }
datacenters[Int32(id)] = AccountDatacenterInfo(masterKey: AccountDatacenterKey(id: authInfo.authKeyId, data: authKey), addressList: addressList)
var ephemeralMainKey: AccountDatacenterKey?
if let ephemeralMainAuthInfo = context.authInfoForDatacenter(withId: id, selector: .ephemeralMain), let ephemeralAuthKey = ephemeralMainAuthInfo.authKey {
ephemeralMainKey = AccountDatacenterKey(id: ephemeralMainAuthInfo.authKeyId, data: ephemeralAuthKey)
}
var ephemeralMediaKey: AccountDatacenterKey?
if let ephemeralMediaAuthInfo = context.authInfoForDatacenter(withId: id, selector: .ephemeralMedia), let ephemeralAuthKey = ephemeralMediaAuthInfo.authKey {
ephemeralMediaKey = AccountDatacenterKey(id: ephemeralMediaAuthInfo.authKeyId, data: ephemeralAuthKey)
}
datacenters[Int32(id)] = AccountDatacenterInfo(
masterKey: AccountDatacenterKey(id: authInfo.authKeyId, data: authKey),
ephemeralMainKey: ephemeralMainKey,
ephemeralMediaKey: ephemeralMediaKey,
addressList: addressList
)
} }
} }
} }
@ -38,12 +54,20 @@ private func accountInfo(account: Account) -> Signal<StoredAccountInfo, NoError>
return combineLatest(peerName, notificationKey) return combineLatest(peerName, notificationKey)
|> map { peerName, notificationKey -> StoredAccountInfo in |> map { peerName, notificationKey -> StoredAccountInfo in
return StoredAccountInfo(id: account.id.int64, primaryId: primaryDatacenterId, isTestingEnvironment: account.testingEnvironment, peerName: peerName, datacenters: datacenters, notificationKey: AccountNotificationKey(id: notificationKey.id, data: notificationKey.data)) return StoredAccountInfo(
id: account.id.int64,
primaryId: primaryDatacenterId,
isTestingEnvironment: account.testingEnvironment,
peerName: peerName,
datacenters: datacenters,
notificationKey: AccountNotificationKey(id: notificationKey.id, data: notificationKey.data)
)
} }
} }
func sharedAccountInfos(accountManager: AccountManager, accounts: Signal<[Account], NoError>) -> Signal<StoredAccountInfos, NoError> { func sharedAccountInfos(accountManager: AccountManager, accounts: Signal<[Account], NoError>) -> Signal<StoredAccountInfos, NoError> {
return combineLatest(accountManager.sharedData(keys: [SharedDataKeys.proxySettings]), accounts) return combineLatest(accountManager.sharedData(keys: [SharedDataKeys.proxySettings]), accounts)
|> take(1)
|> mapToSignal { sharedData, accounts -> Signal<StoredAccountInfos, NoError> in |> mapToSignal { sharedData, accounts -> Signal<StoredAccountInfos, NoError> in
let proxySettings = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings let proxySettings = sharedData.entries[SharedDataKeys.proxySettings] as? ProxySettings
let proxy = proxySettings?.effectiveActiveServer.flatMap { proxyServer -> AccountProxyConnection? in let proxy = proxySettings?.effectiveActiveServer.flatMap { proxyServer -> AccountProxyConnection? in

View File

@ -646,6 +646,7 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode {
} }
private func checkTimer() { private func checkTimer() {
let previousRemainingSeconds = Int(self.remainingSeconds)
if self.timer != nil { if self.timer != nil {
self.remainingSeconds -= 0.5 self.remainingSeconds -= 0.5
} }
@ -653,19 +654,21 @@ final class UndoOverlayControllerNode: ViewControllerTracingNode {
let _ = self.action(.commit) let _ = self.action(.commit)
self.dismiss() self.dismiss()
} else { } else {
if !self.timerTextNode.bounds.size.width.isZero, let snapshot = self.timerTextNode.view.snapshotContentTree() { if Int(self.remainingSeconds) != previousRemainingSeconds || (self.timerTextNode.attributedText?.string ?? "").isEmpty {
self.panelNode.view.insertSubview(snapshot, aboveSubview: self.timerTextNode.view) if !self.timerTextNode.bounds.size.width.isZero, let snapshot = self.timerTextNode.view.snapshotContentTree() {
snapshot.frame = self.timerTextNode.frame self.panelNode.view.insertSubview(snapshot, aboveSubview: self.timerTextNode.view)
self.timerTextNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.12) snapshot.frame = self.timerTextNode.frame
self.timerTextNode.layer.animatePosition(from: CGPoint(x: 0.0, y: -10.0), to: CGPoint(), duration: 0.12, removeOnCompletion: false, additive: true) self.timerTextNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.12)
snapshot.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.12, removeOnCompletion: false) self.timerTextNode.layer.animatePosition(from: CGPoint(x: 0.0, y: -10.0), to: CGPoint(), duration: 0.12, removeOnCompletion: false, additive: true)
snapshot.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: 10.0), duration: 0.12, removeOnCompletion: false, additive: true, completion: { [weak snapshot] _ in snapshot.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.12, removeOnCompletion: false)
snapshot?.removeFromSuperview() snapshot.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: 10.0), duration: 0.12, removeOnCompletion: false, additive: true, completion: { [weak snapshot] _ in
}) snapshot?.removeFromSuperview()
} })
self.timerTextNode.attributedText = NSAttributedString(string: "\(Int(self.remainingSeconds))", font: Font.regular(16.0), textColor: .white) }
if let validLayout = self.validLayout { self.timerTextNode.attributedText = NSAttributedString(string: "\(Int(self.remainingSeconds))", font: Font.regular(16.0), textColor: .white)
self.containerLayoutUpdated(layout: validLayout, transition: .immediate) if let validLayout = self.validLayout {
self.containerLayoutUpdated(layout: validLayout, transition: .immediate)
}
} }
let timer = SwiftSignalKit.Timer(timeout: 0.5, repeat: false, completion: { [weak self] in let timer = SwiftSignalKit.Timer(timeout: 0.5, repeat: false, completion: { [weak self] in
self?.checkTimer() self?.checkTimer()