Skip to content

Commit

Permalink
[Feature] Introduce new method createCommunicationIdentifier(from raw…
Browse files Browse the repository at this point in the history
…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
JoshuaLai authored Aug 24, 2022
1 parent 0c8ffcb commit 5106cff
Show file tree
Hide file tree
Showing 9 changed files with 760 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ class IdentifierSerializerTests: XCTestCase {
try serializePhoneNumber(expectedId: testRawId)
}

func test_SerializePhoneNumber_ExpectedIdNil() throws {
try serializePhoneNumber(expectedId: nil)
}

func serializePhoneNumber(expectedId: String?) throws {
let model = try IdentifierSerializer
.serialize(identifier: PhoneNumberIdentifier(phoneNumber: testPhoneNumber, rawId: expectedId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
1D2E7F7024E4589100447964 /* Identifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2E7F6F24E4589100447964 /* Identifiers.swift */; };
1DE4DB7724C0FE8300631921 /* AutoRefreshTokenCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DE4DB7624C0FE8300631921 /* AutoRefreshTokenCredential.swift */; };
1DE4DB7924C1063E00631921 /* ThreadSafeRefreshableAccessTokenCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DE4DB7824C1063E00631921 /* ThreadSafeRefreshableAccessTokenCache.swift */; };
881EB016287DCB8500DFF928 /* CommunicationIdentifierFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 881EB015287DCB8500DFF928 /* CommunicationIdentifierFactory.m */; };
881EB019287E02A600DFF928 /* CommunicationIdentifierFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 881EB018287E02A600DFF928 /* CommunicationIdentifierFactoryTests.m */; };
882F28D425A632CA009689E3 /* CommunicationTokenRefreshOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 882F28D325A632CA009689E3 /* CommunicationTokenRefreshOptions.swift */; };
8856CEAC253A376D00044559 /* CommunicationAccessToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8856CEAB253A376D00044559 /* CommunicationAccessToken.swift */; };
8856CEE5253E3AEF00044559 /* ObjCCommunicationTokenCredentialTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8856CEE4253E3AEF00044559 /* ObjCCommunicationTokenCredentialTests.m */; };
88CC8C35254750260028977C /* ObjCCommunicationTokenCredentialAsyncTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88CC8C34254750260028977C /* ObjCCommunicationTokenCredentialAsyncTests.m */; };
88F1F570254A07BC00876BC4 /* ObjCTokenParserTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F1F56F254A07BC00876BC4 /* ObjCTokenParserTests.m */; };
88F6458928B3EFE200415333 /* CreateCommunicationIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88F6458828B3EFE200415333 /* CreateCommunicationIdentifier.swift */; };
C1ABE73016C6539A7175199B /* Pods_AzureCommunicationCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D532B0F56C67A1E89941A6D6 /* Pods_AzureCommunicationCommon.framework */; };
CE28995B2826981CCEAD9A96 /* Pods_AzureCommunicationCommonTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65876B73FED970EE674191B8 /* Pods_AzureCommunicationCommonTests.framework */; };
D112634825B7969B00F437C6 /* (null) in Sources */ = {isa = PBXBuildFile; };
Expand Down Expand Up @@ -55,12 +58,16 @@
502AF53063897B96B7E24DD5 /* Pods-AzureCommunicationCommonTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AzureCommunicationCommonTests.debug.xcconfig"; path = "Target Support Files/Pods-AzureCommunicationCommonTests/Pods-AzureCommunicationCommonTests.debug.xcconfig"; sourceTree = "<group>"; };
65876B73FED970EE674191B8 /* Pods_AzureCommunicationCommonTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AzureCommunicationCommonTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7AB0952825BF895B0026A2A5 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
881EB015287DCB8500DFF928 /* CommunicationIdentifierFactory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CommunicationIdentifierFactory.m; sourceTree = "<group>"; };
881EB017287DDB8700DFF928 /* CommunicationIdentifierFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommunicationIdentifierFactory.h; sourceTree = "<group>"; };
881EB018287E02A600DFF928 /* CommunicationIdentifierFactoryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CommunicationIdentifierFactoryTests.m; sourceTree = "<group>"; };
882F28D325A632CA009689E3 /* CommunicationTokenRefreshOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunicationTokenRefreshOptions.swift; sourceTree = "<group>"; };
8856CEAB253A376D00044559 /* CommunicationAccessToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunicationAccessToken.swift; sourceTree = "<group>"; };
8856CEE3253E3AEF00044559 /* AzureCommunicationCommonTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AzureCommunicationCommonTests-Bridging-Header.h"; sourceTree = "<group>"; };
8856CEE4253E3AEF00044559 /* ObjCCommunicationTokenCredentialTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ObjCCommunicationTokenCredentialTests.m; sourceTree = "<group>"; };
88CC8C34254750260028977C /* ObjCCommunicationTokenCredentialAsyncTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ObjCCommunicationTokenCredentialAsyncTests.m; sourceTree = "<group>"; };
88F1F56F254A07BC00876BC4 /* ObjCTokenParserTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ObjCTokenParserTests.m; sourceTree = "<group>"; };
88F6458828B3EFE200415333 /* CreateCommunicationIdentifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateCommunicationIdentifier.swift; sourceTree = "<group>"; };
CC958AD71D0F5F2AAAF8CD78 /* Pods-AzureCommunicationCommon.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AzureCommunicationCommon.debug.xcconfig"; path = "Target Support Files/Pods-AzureCommunicationCommon/Pods-AzureCommunicationCommon.debug.xcconfig"; sourceTree = "<group>"; };
D1A42CF725CCA1C100408C0F /* CommunicationTokenCredential.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommunicationTokenCredential.swift; sourceTree = "<group>"; };
D532B0F56C67A1E89941A6D6 /* Pods_AzureCommunicationCommon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AzureCommunicationCommon.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -124,6 +131,8 @@
1DC3550524D9F02D0095ABD9 /* Supporting Files */,
1D2E7F6F24E4589100447964 /* Identifiers.swift */,
F1540EBC25BF893C0056B087 /* CommunicationCloudEnvironment.swift */,
881EB015287DCB8500DFF928 /* CommunicationIdentifierFactory.m */,
881EB017287DDB8700DFF928 /* CommunicationIdentifierFactory.h */,
);
path = Source;
sourceTree = "<group>";
Expand All @@ -138,6 +147,8 @@
8856CEE3253E3AEF00044559 /* AzureCommunicationCommonTests-Bridging-Header.h */,
88F1F56F254A07BC00876BC4 /* ObjCTokenParserTests.m */,
F1540EC025BFD6910056B087 /* CommunicationIdentifierTest.swift */,
881EB018287E02A600DFF928 /* CommunicationIdentifierFactoryTests.m */,
88F6458828B3EFE200415333 /* CreateCommunicationIdentifier.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -243,7 +254,7 @@
TargetAttributes = {
0A3A5EB72316DB1E00473FDA = {
CreatedOnToolsVersion = 10.3;
LastSwiftMigration = 1030;
LastSwiftMigration = 1340;
};
0A3A5EC02316DB1E00473FDA = {
CreatedOnToolsVersion = 10.3;
Expand Down Expand Up @@ -357,6 +368,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
881EB016287DCB8500DFF928 /* CommunicationIdentifierFactory.m in Sources */,
F183A5EB24AF9D9000F0E0D5 /* CommunicationTokenCredentialProviding.swift in Sources */,
1D2E7F7024E4589100447964 /* Identifiers.swift in Sources */,
8856CEAC253A376D00044559 /* CommunicationAccessToken.swift in Sources */,
Expand All @@ -376,9 +388,11 @@
buildActionMask = 2147483647;
files = (
88F1F570254A07BC00876BC4 /* ObjCTokenParserTests.m in Sources */,
88F6458928B3EFE200415333 /* CreateCommunicationIdentifier.swift in Sources */,
8856CEE5253E3AEF00044559 /* ObjCCommunicationTokenCredentialTests.m in Sources */,
F1540EC125BFD6910056B087 /* CommunicationIdentifierTest.swift in Sources */,
1D07222D24C8FB0F00C2EF4E /* CommunicationTokenCredentialTests.swift in Sources */,
881EB019287E02A600DFF928 /* CommunicationIdentifierFactoryTests.m in Sources */,
88CC8C35254750260028977C /* ObjCCommunicationTokenCredentialAsyncTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
9 changes: 9 additions & 0 deletions sdk/communication/AzureCommunicationCommon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Release History

## 1.1.0 (upcoming)
### New Features
- Introduce new `createCommunicationIdentifier(from: )` to translate between a CommunicationIdentifier and its underlying canonical rawId representation. Developers can now use the rawId as an encoded format for identifiers to store in their databases or as stable keys in general.
- Introduce new `rawId` getter property in the `CommunicationIdentifier` protocol to return rawId representation.
- Introduce new `kind` getter property in the `CommunicationIdentifier` protocol to return string representation of the kind of identifer developers are woking with.

### Key Bug Fixes
- Previously `rawId` was an optional property in `PhoneNumberIdentifier`. Updated the `rawId` to be required, and always corresponds with the phone number. This will cause compilation errors.

## 1.0.3 (2022-03-10)
### New Features
- Update `AzureCore` dependency to beta 15.
Expand Down
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 */
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
Loading

0 comments on commit 5106cff

Please sign in to comment.