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.5 KiB
Mathematica
Raw Permalink Normal View History

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