Update notification service

This commit is contained in:
Ali 2021-02-19 19:07:31 +04:00
parent c2ef0d70a7
commit 2d2f434b20
8 changed files with 72 additions and 10 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

@ -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