Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Introduce new method createCommunicationIdentifier(from rawId:) #1312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
37c84ff
[Identifiers] introducing the raw id property in the CommunicationIde…
JoshuaLai May 5, 2022
4fb093f
[CommunicationIdentifierHelper] introducing helper to create identifers
JoshuaLai May 5, 2022
974a42d
[IdentifierSerializerTests] Updating chat unit test as per new rules …
JoshuaLai May 5, 2022
d3105c1
[CHNAGELOG] updating the changelog and the documentation for new methods
JoshuaLai May 5, 2022
1b77645
[CommunicationIdentifierHelper] As per PR request, Extract out the co…
JoshuaLai May 9, 2022
2709ce7
[CommunicationIdentifierHelper] As per PR request, Extract out the co…
JoshuaLai May 9, 2022
dc47ec4
[CHANGELOG] updating change log as per pr feedback
JoshuaLai May 16, 2022
fef42ff
[MicrosoftTeamsUserIdentifier] Introducing a new convenience init to …
JoshuaLai May 18, 2022
dc60280
[CommunicationIdentifierHelperTests] updating variable names to be mo…
JoshuaLai May 18, 2022
e85f9e1
[CommunicationIdentifierHelperTests] Update unit test to align better…
JoshuaLai May 18, 2022
0eed6f8
[Identifier] mocking out what swift implementation could look like
JoshuaLai Jun 28, 2022
a86e02e
[CommunicationIdentifier] implement new global method to createCommun…
JoshuaLai Jul 11, 2022
01defac
[IdentifierFactory] Implemented and tested the Obj-C interface
JoshuaLai Jul 12, 2022
6033723
[Scheme] revert test changes
JoshuaLai Jul 12, 2022
226f69f
[Changelog] Update Change log
JoshuaLai Jul 12, 2022
5a7633a
[Identifiers] Fixing var to be camel case as per PR feedback
JoshuaLai Jul 15, 2022
6962814
[CommnicationIdentifierFactory] marking method as ns_swift_unavailable
JoshuaLai Jul 15, 2022
87d7f52
[Identifiers] clarify some argument parameters
JoshuaLai Jul 15, 2022
4054ca8
[Changelog] Update the changelog to provide more detail
JoshuaLai Jul 18, 2022
da817bd
[Identifiers] camel case the kind raw value
JoshuaLai Jul 20, 2022
bf75f0a
Merge branch 'feature/swift_createCommunicationIdentifier' of github.…
JoshuaLai Jul 20, 2022
49e6ae9
[CreateCommunicationIdentifier] New tests switch case on IdentifierKind
JoshuaLai Aug 22, 2022
70f3f32
[Documentation] Updating the documentation for the identifiers
JoshuaLai Aug 22, 2022
91db571
[Identifiers] Update property to be rawValue as per PR feedback
JoshuaLai Aug 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -56,12 +59,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 @@ -126,6 +133,8 @@
1DC3550524D9F02D0095ABD9 /* Supporting Files */,
1D2E7F6F24E4589100447964 /* Identifiers.swift */,
F1540EBC25BF893C0056B087 /* CommunicationCloudEnvironment.swift */,
881EB015287DCB8500DFF928 /* CommunicationIdentifierFactory.m */,
881EB017287DDB8700DFF928 /* CommunicationIdentifierFactory.h */,
);
path = Source;
sourceTree = "<group>";
Expand All @@ -140,6 +149,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 @@ -245,7 +256,7 @@
TargetAttributes = {
0A3A5EB72316DB1E00473FDA = {
CreatedOnToolsVersion = 10.3;
LastSwiftMigration = 1030;
LastSwiftMigration = 1340;
};
0A3A5EC02316DB1E00473FDA = {
CreatedOnToolsVersion = 10.3;
Expand Down Expand Up @@ -359,6 +370,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 @@ -378,9 +390,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");
JoshuaLai marked this conversation as resolved.
Show resolved Hide resolved
@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