-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Introduce new method createCommunicationIdentifier(from raw…
…Id:) (#1312) * [Identifiers] introducing the raw id property in the CommunicationIdentifier protocol * [CommunicationIdentifierHelper] introducing helper to create identifers * [IdentifierSerializerTests] Updating chat unit test as per new rules for raw id * [CHNAGELOG] updating the changelog and the documentation for new methods * [CommunicationIdentifierHelper] As per PR request, Extract out the const strings * [CommunicationIdentifierHelper] As per PR request, Extract out the const strings * [CHANGELOG] updating change log as per pr feedback * [MicrosoftTeamsUserIdentifier] Introducing a new convenience init to promote shared behaviour * [CommunicationIdentifierHelperTests] updating variable names to be more accurate * [CommunicationIdentifierHelperTests] Update unit test to align better with other platforms * [Identifier] mocking out what swift implementation could look like * [CommunicationIdentifier] implement new global method to createCommunicationIdentifier from rawId * [IdentifierFactory] Implemented and tested the Obj-C interface * [Scheme] revert test changes * [Changelog] Update Change log * [Identifiers] Fixing var to be camel case as per PR feedback * [CommnicationIdentifierFactory] marking method as ns_swift_unavailable * [Identifiers] clarify some argument parameters * [Changelog] Update the changelog to provide more detail * [Identifiers] camel case the kind raw value * [CreateCommunicationIdentifier] New tests switch case on IdentifierKind * [Documentation] Updating the documentation for the identifiers * [Identifiers] Update property to be rawValue as per PR feedback
- Loading branch information
Showing
9 changed files
with
760 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
sdk/communication/AzureCommunicationCommon/Source/CommunicationIdentifierFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// -------------------------------------------------------------------------- | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// | ||
// The MIT License (MIT) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the ""Software""), to | ||
// deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
// sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
// IN THE SOFTWARE. | ||
// | ||
// -------------------------------------------------------------------------- | ||
|
||
#ifndef CommunicationIdentifierFactory_h | ||
#define CommunicationIdentifierFactory_h | ||
@class CommunicationIdentifier; | ||
|
||
@interface CommunicationIdentifierFactory : NSObject | ||
+ (id<CommunicationIdentifier>)createCommunicationIdentifier: (NSString *) rawId NS_SWIFT_UNAVAILABLE("Exposed in Swift as createCommunicationIdentifier(from: ) -> CommunicationIdentifier"); | ||
@end | ||
|
||
#endif /* CommunicationIdentifierFactory_h */ |
92 changes: 92 additions & 0 deletions
92
sdk/communication/AzureCommunicationCommon/Source/CommunicationIdentifierFactory.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// -------------------------------------------------------------------------- | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// | ||
// The MIT License (MIT) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the ""Software""), to | ||
// deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
// sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
// IN THE SOFTWARE. | ||
// | ||
// -------------------------------------------------------------------------- | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "AzureCommunicationCommon/AzureCommunicationCommon-Swift.h" | ||
#import "CommunicationIdentifierFactory.h" | ||
|
||
@implementation CommunicationIdentifierFactory | ||
+ (id<CommunicationIdentifier>)createCommunicationIdentifier: (NSString *) rawId { | ||
NSString* phoneNumberPrefix = @"4:"; | ||
NSString* teamUserAnonymousPrefix = @"8:teamsvisitor:"; | ||
NSString* teamUserPublicCloudPrefix = @"8:orgid:"; | ||
NSString* teamUserDODCloudPrefix = @"8:dod:"; | ||
NSString* teamUserGCCHCloudPrefix = @"8:gcch:"; | ||
NSString* acsUser = @"8:acs:"; | ||
NSString* spoolUser = @"8:spool:"; | ||
NSString* dodAcsUser = @"8:dod-acs:"; | ||
NSString* gcchAcsUser = @"8:gcch-acs:"; | ||
|
||
if ([rawId hasPrefix:phoneNumberPrefix]) { | ||
NSString *formattedPhone = [rawId stringByReplacingOccurrencesOfString:phoneNumberPrefix | ||
withString:@""]; | ||
NSString *phoneNumber = [[NSString alloc] initWithFormat:@"+%@", formattedPhone]; | ||
return [[PhoneNumberIdentifier alloc] initWithPhoneNumber:phoneNumber | ||
rawId:rawId]; | ||
} | ||
|
||
NSArray<NSString *> *segments = [rawId componentsSeparatedByString:@":"]; | ||
if (segments.count < 3) { | ||
return [[UnknownIdentifier alloc] initWithIdentifier:rawId]; | ||
} | ||
|
||
NSString *scope = [[NSString alloc] initWithFormat:@"%@:%@:", | ||
[segments objectAtIndex: 0], | ||
[segments objectAtIndex: 1]]; | ||
|
||
NSString *suffix = [[NSString alloc] initWithFormat:@"%@", [rawId stringByReplacingOccurrencesOfString:scope | ||
withString:@""]]; | ||
if ([scope isEqualToString: teamUserAnonymousPrefix]) { | ||
return [[MicrosoftTeamsUserIdentifier alloc] initWithUserId:suffix | ||
isAnonymous:true | ||
rawId:nil | ||
cloudEnvironment:CommunicationCloudEnvironment.Public]; | ||
} else if ([scope isEqualToString: teamUserPublicCloudPrefix]) { | ||
return [[MicrosoftTeamsUserIdentifier alloc] initWithUserId:suffix | ||
isAnonymous:false | ||
rawId:rawId | ||
cloudEnvironment:CommunicationCloudEnvironment.Public]; | ||
} else if ([scope isEqualToString: teamUserDODCloudPrefix]) { | ||
return [[MicrosoftTeamsUserIdentifier alloc] initWithUserId:suffix | ||
isAnonymous:false | ||
rawId:rawId | ||
cloudEnvironment:CommunicationCloudEnvironment.Dod]; | ||
} else if ([scope isEqualToString:teamUserGCCHCloudPrefix]) { | ||
return [[MicrosoftTeamsUserIdentifier alloc] initWithUserId:suffix | ||
isAnonymous:false | ||
rawId:rawId | ||
cloudEnvironment:CommunicationCloudEnvironment.Gcch]; | ||
} else if ([scope isEqualToString:acsUser] || | ||
[scope isEqualToString:spoolUser] || | ||
[scope isEqualToString:dodAcsUser] || | ||
[scope isEqualToString:gcchAcsUser]) { | ||
return [[CommunicationUserIdentifier alloc] initWithIdentifier:rawId]; | ||
} else { | ||
return [[UnknownIdentifier alloc] initWithIdentifier:rawId]; | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.