1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-02 09:27:55 +01:00
Telegram/Share/TGShareMtSerialization.m

72 lines
2.4 KiB
Mathematica
Raw Normal View History

2015-10-01 18:19:52 +02:00
#import "TGShareMtSerialization.h"
#import "ApiLayer38.h"
#import <MTProtoKit/MTExportedAuthorizationData.h>
#import <MTProtoKit/MTDatacenterAddress.h>
@implementation TGShareMtSerialization
- (NSUInteger)currentLayer
{
return 39;
}
- (id)parseMessage:(NSData *)data
{
return [Api38__Environment parseObject:data];
}
- (MTExportAuthorizationResponseParser)exportAuthorization:(int32_t)datacenterId data:(__autoreleasing NSData **)data
{
Api38_FunctionContext *exportAuthorization = [Api38 auth_exportAuthorizationWithDcId:@(datacenterId)];
if (data)
*data = exportAuthorization.payload;
return ^MTExportedAuthorizationData *(NSData *data) {
id response = exportAuthorization.responseParser(data);
if ([response isKindOfClass:[Api38_auth_ExportedAuthorization class]])
{
Api38_auth_ExportedAuthorization *exportedAuthorization = response;
return [[MTExportedAuthorizationData alloc] initWithAuthorizationBytes:exportedAuthorization.bytes authorizationId:[exportedAuthorization.pid intValue]];
}
return nil;
};
}
- (NSData *)importAuthorization:(int32_t)authId bytes:(NSData *)bytes
{
Api38_FunctionContext *importAuthorization = [Api38 auth_importAuthorizationWithPid:@(authId) bytes:bytes];
return importAuthorization.payload;
}
- (MTRequestDatacenterAddressListParser)requestDatacenterAddressList:(int32_t)datacenterId data:(__autoreleasing NSData **)data
{
Api38_FunctionContext *getConfig = [Api38 help_getConfig];
if (data)
*data = getConfig.payload;
return ^MTDatacenterAddressListData *(NSData *data) {
id response = getConfig.responseParser(data);
if ([response isKindOfClass:[Api38_Config class]])
{
NSMutableArray *addressList = [[NSMutableArray alloc] init];
for (Api38_DcOption *dcOption in ((Api38_Config *)response).dcOptions)
{
if ([dcOption.pid intValue] == datacenterId)
{
MTDatacenterAddress *address = [[MTDatacenterAddress alloc] initWithIp:dcOption.ipAddress port:(uint16_t)[dcOption.port intValue] preferForMedia:[dcOption.flags intValue] & (1 << 1)];
[addressList addObject:address];
}
}
return [[MTDatacenterAddressListData alloc] initWithAddressList:addressList];
}
return nil;
};
}
@end