From 09a679cbddd26c19aa3ea6f512a40ea9ec1cc528 Mon Sep 17 00:00:00 2001 From: overtake Date: Fri, 29 Oct 2021 18:18:02 +0200 Subject: [PATCH] - custom deviceModel name can be transffered from UI --- .../MtProtoKit/MTApiEnvironment.h | 4 +++ .../MtProtoKit/Sources/MTApiEnvironment.m | 35 ++++++++++++++----- .../Sources/Network/Network.swift | 7 ++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTApiEnvironment.h b/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTApiEnvironment.h index c35dfbcb9e..1551b3b75c 100644 --- a/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTApiEnvironment.h +++ b/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTApiEnvironment.h @@ -55,6 +55,8 @@ @property (nonatomic) int32_t apiId; @property (nonatomic, strong, readonly) NSString * _Nullable deviceModel; +@property (nonatomic, strong, readonly) NSDictionary * _Nullable resolvedPlatformName; + @property (nonatomic, strong, readonly) NSString * _Nullable systemVersion; @property (nonatomic, strong) NSString * _Nullable appVersion; @property (nonatomic, strong, readonly) NSString * _Nullable systemLangCode; @@ -81,4 +83,6 @@ - (MTApiEnvironment * _Nonnull)withUpdatedNetworkSettings:(MTNetworkSettings * _Nullable)networkSettings; - (MTApiEnvironment * _Nonnull)withUpdatedSystemCode:(NSData * _Nullable)systemCode; +-(id _Nonnull)initWithResolvedPlatformName:(NSDictionary * _Nullable)resolvedPlatformName; + @end diff --git a/submodules/MtProtoKit/Sources/MTApiEnvironment.m b/submodules/MtProtoKit/Sources/MTApiEnvironment.m index c44a91c866..5ea5e76d05 100644 --- a/submodules/MtProtoKit/Sources/MTApiEnvironment.m +++ b/submodules/MtProtoKit/Sources/MTApiEnvironment.m @@ -427,12 +427,31 @@ static NSData *base64_decode(NSString *str) { @implementation MTApiEnvironment -- (instancetype)init -{ +-(instancetype)init { + self = [self initWithResolvedPlatformName:nil]; + if (self != nil) + { + + } + return self; +} + +-(id _Nonnull)initWithResolvedPlatformName:(NSDictionary * _Nullable)resolvedPlatformName { self = [super init]; if (self != nil) { - _deviceModel = [self platformString]; + if (resolvedPlatformName != nil) { + NSString *model = [self platformString]; + NSString* resolved = resolvedPlatformName[model]; + if (resolved != nil) { + _deviceModel = resolved; + } else { + _deviceModel = model; + } + } else { + _deviceModel = [self platformString]; + } + _resolvedPlatformName = resolvedPlatformName; #if TARGET_OS_IPHONE _systemVersion = [[UIDevice currentDevice] systemVersion]; #else @@ -759,7 +778,7 @@ NSString *suffix = @""; } - (MTApiEnvironment *)withUpdatedLangPackCode:(NSString *)langPackCode { - MTApiEnvironment *result = [[MTApiEnvironment alloc] init]; + MTApiEnvironment *result = [[MTApiEnvironment alloc] initWithResolvedPlatformName:_resolvedPlatformName]; result.apiId = self.apiId; result.appVersion = self.appVersion; @@ -783,7 +802,7 @@ NSString *suffix = @""; } - (instancetype)copyWithZone:(NSZone *)__unused zone { - MTApiEnvironment *result = [[MTApiEnvironment alloc] init]; + MTApiEnvironment *result = [[MTApiEnvironment alloc] initWithResolvedPlatformName:_resolvedPlatformName]; result.apiId = self.apiId; result.appVersion = self.appVersion; @@ -807,7 +826,7 @@ NSString *suffix = @""; } - (MTApiEnvironment *)withUpdatedSocksProxySettings:(MTSocksProxySettings *)socksProxySettings { - MTApiEnvironment *result = [[MTApiEnvironment alloc] init]; + MTApiEnvironment *result = [[MTApiEnvironment alloc] initWithResolvedPlatformName:_resolvedPlatformName]; result.apiId = self.apiId; result.appVersion = self.appVersion; @@ -831,7 +850,7 @@ NSString *suffix = @""; } - (MTApiEnvironment *)withUpdatedNetworkSettings:(MTNetworkSettings *)networkSettings { - MTApiEnvironment *result = [[MTApiEnvironment alloc] init]; + MTApiEnvironment *result = [[MTApiEnvironment alloc] initWithResolvedPlatformName:_resolvedPlatformName]; result.apiId = self.apiId; result.appVersion = self.appVersion; @@ -855,7 +874,7 @@ NSString *suffix = @""; } - (MTApiEnvironment *)withUpdatedSystemCode:(NSData *)systemCode { - MTApiEnvironment *result = [[MTApiEnvironment alloc] init]; + MTApiEnvironment *result = [[MTApiEnvironment alloc] initWithResolvedPlatformName:_resolvedPlatformName]; result.apiId = self.apiId; result.appVersion = self.appVersion; diff --git a/submodules/TelegramCore/Sources/Network/Network.swift b/submodules/TelegramCore/Sources/Network/Network.swift index 438201a3a5..5199bb9f7b 100644 --- a/submodules/TelegramCore/Sources/Network/Network.swift +++ b/submodules/TelegramCore/Sources/Network/Network.swift @@ -406,8 +406,8 @@ public struct NetworkInitializationArguments { public let appData: Signal public let autolockDeadine: Signal public let encryptionProvider: EncryptionProvider - - public init(apiId: Int32, apiHash: String, languagesCategory: String, appVersion: String, voipMaxLayer: Int32, voipVersions: [CallSessionManagerImplementationVersion], appData: Signal, autolockDeadine: Signal, encryptionProvider: EncryptionProvider) { + public let resolvedPlatformName:[String: String]? + public init(apiId: Int32, apiHash: String, languagesCategory: String, appVersion: String, voipMaxLayer: Int32, voipVersions: [CallSessionManagerImplementationVersion], appData: Signal, autolockDeadine: Signal, encryptionProvider: EncryptionProvider, resolvedPlatformName:[String: String]?) { self.apiId = apiId self.apiHash = apiHash self.languagesCategory = languagesCategory @@ -417,6 +417,7 @@ public struct NetworkInitializationArguments { self.appData = appData self.autolockDeadine = autolockDeadine self.encryptionProvider = encryptionProvider + self.resolvedPlatformName = resolvedPlatformName } } #if os(iOS) @@ -431,7 +432,7 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa let serialization = Serialization() - var apiEnvironment = MTApiEnvironment() + var apiEnvironment = MTApiEnvironment(resolvedPlatformName: arguments.resolvedPlatformName) apiEnvironment.apiId = arguments.apiId apiEnvironment.langPack = arguments.languagesCategory