2021-07-08 13:46:10 -07:00
|
|
|
//
|
|
|
|
|
// MBIMAliasValidationOperation.m
|
|
|
|
|
// MBIMAliasValidationOperation
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 7/8/21.
|
|
|
|
|
// Copyright © 2021 James Magahern. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "MBIMAliasValidationOperation.h"
|
|
|
|
|
|
|
|
|
|
#import "IMCore_ClassDump.h"
|
|
|
|
|
#import "IMFoundation_ClassDump.h"
|
|
|
|
|
|
|
|
|
|
@implementation MBIMAliasValidationOperation
|
|
|
|
|
|
|
|
|
|
+ (void)load { [super load]; }
|
|
|
|
|
|
|
|
|
|
+ (NSString *)endpointName
|
|
|
|
|
{
|
|
|
|
|
return @"validate";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)main
|
|
|
|
|
{
|
|
|
|
|
NSString *address = [self valueForQueryItemWithName:@"address"];
|
|
|
|
|
if ([address length] == 0) {
|
|
|
|
|
self.serverCompletionBlock([[HTTPErrorResponse alloc] initWithErrorCode:401]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString *unformattedAddress = IMStripFormattingFromAddress(address);
|
|
|
|
|
BOOL isEmailAddress = IMStringIsEmail(unformattedAddress);
|
|
|
|
|
|
|
|
|
|
NSString *IDSaddress = isEmailAddress ? IDSCopyIDForEmailAddress(unformattedAddress)
|
|
|
|
|
: IDSCopyIDForPhoneNumber(unformattedAddress);
|
|
|
|
|
|
|
|
|
|
if (!IDSaddress) {
|
|
|
|
|
MBIMLogError(@"Could not get IDS address for: %@", unformattedAddress);
|
|
|
|
|
self.serverCompletionBlock([[HTTPErrorResponse alloc] initWithErrorCode:401]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-08 15:35:29 -07:00
|
|
|
__block IMChat *existingChat = nil;
|
|
|
|
|
dispatch_sync([[self class] sharedIMAccessQueue], ^{
|
|
|
|
|
IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]];
|
|
|
|
|
IMHandle *handle = [iMessageAccount imHandleWithID:unformattedAddress];
|
|
|
|
|
|
|
|
|
|
if (handle) {
|
|
|
|
|
existingChat = [[IMChatRegistry sharedInstance] existingChatForIMHandle:handle];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-07-08 13:46:10 -07:00
|
|
|
IMChatCalculateServiceForSendingNewComposeMaybeForce(
|
2021-07-08 15:35:29 -07:00
|
|
|
@[ IDSaddress ], nil, nil, NO, isEmailAddress, YES, NO, NO, nil,
|
2021-07-08 13:46:10 -07:00
|
|
|
^(BOOL allAddressesiMessageCapable, NSDictionary *availabilityPerRecipient, BOOL checkedServer, NSError *error) {
|
2021-07-08 15:35:29 -07:00
|
|
|
NSMutableDictionary *response = [NSMutableDictionary dictionaryWithDictionary:@{
|
|
|
|
|
@"capable" : @(allAddressesiMessageCapable),
|
|
|
|
|
@"idsAddress" : IDSaddress,
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if ([existingChat guid]) {
|
|
|
|
|
[response setObject:[existingChat guid] forKey:@"existingGuid"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.serverCompletionBlock([MBIMJSONDataResponse responseWithJSONObject:response]);
|
2021-07-08 13:46:10 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|