Private
Public Access
1
0
Files
Kordophone/kordophone/Bridge/Operations/MBIMAliasValidationOperation.m

70 lines
2.3 KiB
Objective-C

//
// 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;
}
__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];
}
});
IMChatCalculateServiceForSendingNewComposeMaybeForce(
@[ IDSaddress ], nil, nil, NO, isEmailAddress, YES, NO, NO, nil,
^(BOOL allAddressesiMessageCapable, NSDictionary *availabilityPerRecipient, BOOL checkedServer, NSError *error) {
NSMutableDictionary *response = [NSMutableDictionary dictionaryWithDictionary:@{
@"capable" : @(allAddressesiMessageCapable),
@"idsAddress" : IDSaddress,
}];
if ([existingChat guid]) {
[response setObject:[existingChat guid] forKey:@"existingGuid"];
}
self.serverCompletionBlock([MBIMJSONDataResponse responseWithJSONObject:response]);
});
}
@end