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

Push Notification GA release #1335

Merged
merged 10 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -135,8 +135,6 @@
E034C0F2282B4D4300E3F985 /* PushNotificationEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E034C0F0282B4D4300E3F985 /* PushNotificationEvent.swift */; };
E034C0F4282B4F1900E3F985 /* CryptoUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = E034C0F3282B4F1900E3F985 /* CryptoUtils.swift */; };
E034C0F5282B4F1900E3F985 /* CryptoUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = E034C0F3282B4F1900E3F985 /* CryptoUtils.swift */; };
E03DAFC428075EE000389C43 /* URLSettingsUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03DAFC328075EE000389C43 /* URLSettingsUtil.swift */; };
E03DAFC528075EE800389C43 /* URLSettingsUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03DAFC328075EE000389C43 /* URLSettingsUtil.swift */; };
E03DAFD4280763C600389C43 /* PushNotificationClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03DAFD3280763C600389C43 /* PushNotificationClient.swift */; };
E03DAFD5280763C600389C43 /* PushNotificationClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03DAFD3280763C600389C43 /* PushNotificationClient.swift */; };
E03DAFD82807660700389C43 /* RegistrarClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E03DAFD72807660700389C43 /* RegistrarClient.swift */; };
Expand Down Expand Up @@ -222,6 +220,8 @@
E04440DD28077C0400A6DA24 /* test_setRegistration_ReturnsSuccess.json in Resources */ = {isa = PBXBuildFile; fileRef = E04440DC28077C0400A6DA24 /* test_setRegistration_ReturnsSuccess.json */; };
E04440E028077C0C00A6DA24 /* test_StopPushNotifications_ReturnsSuccess.json in Resources */ = {isa = PBXBuildFile; fileRef = E04440DE28077C0C00A6DA24 /* test_StopPushNotifications_ReturnsSuccess.json */; };
E04440E128077C0C00A6DA24 /* test_StartPushNotifications_ReturnsSuccess.json in Resources */ = {isa = PBXBuildFile; fileRef = E04440DF28077C0C00A6DA24 /* test_StartPushNotifications_ReturnsSuccess.json */; };
E058442C28A6DDFA007D7E0A /* IdentityUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = E058442B28A6DDFA007D7E0A /* IdentityUtil.swift */; };
E058442D28A6DDFA007D7E0A /* IdentityUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = E058442B28A6DDFA007D7E0A /* IdentityUtil.swift */; };
E0C134EE284E677900FC388B /* PushNotificationKeyHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0C134ED284E677900FC388B /* PushNotificationKeyHandler.swift */; };
E0C134EF284E677900FC388B /* PushNotificationKeyHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0C134ED284E677900FC388B /* PushNotificationKeyHandler.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -380,7 +380,6 @@
E034C0ED282B4D1D00E3F985 /* PushNotificationBaseEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationBaseEvent.swift; sourceTree = "<group>"; };
E034C0F0282B4D4300E3F985 /* PushNotificationEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationEvent.swift; sourceTree = "<group>"; };
E034C0F3282B4F1900E3F985 /* CryptoUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptoUtils.swift; sourceTree = "<group>"; };
E03DAFC328075EE000389C43 /* URLSettingsUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSettingsUtil.swift; sourceTree = "<group>"; };
E03DAFD3280763C600389C43 /* PushNotificationClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationClient.swift; sourceTree = "<group>"; };
E03DAFD72807660700389C43 /* RegistrarClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrarClient.swift; sourceTree = "<group>"; };
E03DAFDA2807661A00389C43 /* RegistrarSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrarSettings.swift; sourceTree = "<group>"; };
Expand All @@ -393,6 +392,7 @@
E04440DC28077C0400A6DA24 /* test_setRegistration_ReturnsSuccess.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test_setRegistration_ReturnsSuccess.json; sourceTree = "<group>"; };
E04440DE28077C0C00A6DA24 /* test_StopPushNotifications_ReturnsSuccess.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test_StopPushNotifications_ReturnsSuccess.json; sourceTree = "<group>"; };
E04440DF28077C0C00A6DA24 /* test_StartPushNotifications_ReturnsSuccess.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test_StartPushNotifications_ReturnsSuccess.json; sourceTree = "<group>"; };
E058442B28A6DDFA007D7E0A /* IdentityUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentityUtil.swift; sourceTree = "<group>"; };
E0C134ED284E677900FC388B /* PushNotificationKeyHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationKeyHandler.swift; sourceTree = "<group>"; };
FCF18D210ADF02D5CBA71786 /* Pods-AzureCommunicationChatUnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AzureCommunicationChatUnitTests.release.xcconfig"; path = "Target Support Files/Pods-AzureCommunicationChatUnitTests/Pods-AzureCommunicationChatUnitTests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -697,8 +697,8 @@
E03DAFC228075E8800389C43 /* NotificationUtils */ = {
isa = PBXGroup;
children = (
E03DAFC328075EE000389C43 /* URLSettingsUtil.swift */,
E034C0F3282B4F1900E3F985 /* CryptoUtils.swift */,
E058442B28A6DDFA007D7E0A /* IdentityUtil.swift */,
);
path = NotificationUtils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1078,13 +1078,13 @@
E04440B2280775EB00A6DA24 /* ChatParticipant.swift in Sources */,
817A92C127BC3A7000D2268E /* TrouterSettingsUnitTest.swift in Sources */,
E04440CC2807776500A6DA24 /* ChatParticipantInternal.swift in Sources */,
E058442D28A6DDFA007D7E0A /* IdentityUtil.swift in Sources */,
E04440A52807759B00A6DA24 /* DeleteChatThreadOptions.swift in Sources */,
E04440A02807758700A6DA24 /* SendTypingNotificationOptions.swift in Sources */,
E04440BB2807772400A6DA24 /* CommunicationUserIdentifierModel.swift in Sources */,
E04440B6280775FF00A6DA24 /* AzureCommunicationChatClientOptions.swift in Sources */,
E04440D8280777D800A6DA24 /* TrouterEvent.swift in Sources */,
E04440B5280775F700A6DA24 /* CreateChatThreadResult.swift in Sources */,
E03DAFC528075EE800389C43 /* URLSettingsUtil.swift in Sources */,
E04440D12807777900A6DA24 /* CreateChatThreadRequestInternal.swift in Sources */,
E04440CD2807776800A6DA24 /* CommunicationIdentifierModelInternal.swift in Sources */,
E04440D22807777D00A6DA24 /* ChatParticipantsCollection.swift in Sources */,
Expand Down Expand Up @@ -1172,9 +1172,9 @@
E03DAFE42807667200389C43 /* RegistrarTransportSettings.swift in Sources */,
D17F8AAD26B0A480005648EA /* CommunicationErrorResponse.swift in Sources */,
D17F8AAE26B0A480005648EA /* AddChatParticipantsRequestInternal.swift in Sources */,
E03DAFC428075EE000389C43 /* URLSettingsUtil.swift in Sources */,
E034C0F4282B4F1900E3F985 /* CryptoUtils.swift in Sources */,
D17F8AAF26B0A480005648EA /* Enumerations.swift in Sources */,
E058442C28A6DDFA007D7E0A /* IdentityUtil.swift in Sources */,
D17F8AB026B0A480005648EA /* PhoneNumberIdentifierModel.swift in Sources */,
D17F8AB126B0A480005648EA /* AddChatParticipantsResult.swift in Sources */,
D17F8AB226B0A480005648EA /* ChatMessageReadReceiptsCollection.swift in Sources */,
Expand Down Expand Up @@ -1385,7 +1385,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.3.0-beta.1;
MARKETING_VERSION = "1.3.0-beta.1";
NEW_SETTING = "";
PRODUCT_BUNDLE_IDENTIFIER = com.azure.communication.AzureCommunicationChat;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -1420,7 +1420,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.3.0-beta.1;
MARKETING_VERSION = "1.3.0-beta.1";
NEW_SETTING = "";
PRODUCT_BUNDLE_IDENTIFIER = com.azure.communication.AzureCommunicationChat;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
//
// --------------------------------------------------------------------------

import AzureCommunicationCommon
import AzureCore
import Foundation
import Trouter

Expand Down Expand Up @@ -68,3 +70,66 @@ func isGcch(id: String) -> Bool {
let gcchAcsUserPrefix = "gcch-acs:"
return (id.starts(with: gcchTeamsUserPrefix) || id.starts(with: gcchAcsUserPrefix))
}

/// Parses out the id/phone number portion of a user id.
/// - Parameters:
/// - id: The string id.
/// - prefix: The id prefix.
/// - Returns: The part of the id after the prefix that corresponds to the user id or phone number of a user.
private func parse(id: String, prefix: String) -> String {
let index = id.index(id.startIndex, offsetBy: prefix.count)
return String(id.suffix(from: index))
}

/// Constructs a CommunicationIdentifier from a string id.
/// - Parameter id: The string id.
/// - Returns: The CommunicationIdentifier.
internal func getIdentifier(from id: String) -> CommunicationIdentifier {
let publicTeamsUserPrefix = "8:orgid:"
let dodTeamsUserPrefix = "8:dod:"
let gcchTeamsUserPrefix = "8:gcch:"
let teamsVisitorUserPrefix = "8:teamsvisitor:"
let phoneNumberPrefix = "4:"
let acsUserPrefix = "8:acs:"
let spoolUserPrefix = "8:spool:"
let dodAcsUserPrefix = "8:dod-acs:"
let gcchAcsUserPrefix = "8:gcch-acs:"

if id.starts(with: publicTeamsUserPrefix) {
return MicrosoftTeamsUserIdentifier(
userId: parse(id: id, prefix: publicTeamsUserPrefix),
isAnonymous: false,
rawId: id,
cloudEnvironment: CommunicationCloudEnvironment.Public
)
} else if id.starts(with: dodTeamsUserPrefix) {
return MicrosoftTeamsUserIdentifier(
userId: parse(id: id, prefix: dodTeamsUserPrefix),
isAnonymous: false,
rawId: id,
cloudEnvironment: CommunicationCloudEnvironment.Dod
)
} else if id.starts(with: gcchTeamsUserPrefix) {
return MicrosoftTeamsUserIdentifier(
userId: parse(id: id, prefix: gcchTeamsUserPrefix),
isAnonymous: false,
rawId: id,
cloudEnvironment: CommunicationCloudEnvironment.Gcch
)
} else if id.starts(with: teamsVisitorUserPrefix) {
return MicrosoftTeamsUserIdentifier(
userId: parse(id: id, prefix: teamsVisitorUserPrefix),
isAnonymous: true
)
} else if id.starts(with: phoneNumberPrefix) {
return PhoneNumberIdentifier(
phoneNumber: parse(id: id, prefix: phoneNumberPrefix),
rawId: id
)
} else if id.starts(with: acsUserPrefix) || id.starts(with: spoolUserPrefix) || id
.starts(with: dodAcsUserPrefix) || id.starts(with: gcchAcsUserPrefix) {
return CommunicationUserIdentifier(id)
} else {
return UnknownIdentifier(id)
}
}
angellan-msft marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class PushNotificationChatMessageEvent {
/// Chat thread id.
public var threadId: String
/// Sender Id
public var senderId: String
public var sender: CommunicationIdentifier
/// Recipient Id
public var recipientId: String
public var recipient: CommunicationIdentifier
/// Sender display name.
public var senderDisplayName: String?
/// The timestamp when the message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.
Expand All @@ -66,17 +66,17 @@ public class PushNotificationChatMessageEvent {
messageId: String,
type: ChatMessageType,
threadId: String,
senderId: String,
recipientId: String,
sender: CommunicationIdentifier,
recipient: CommunicationIdentifier,
senderDisplayName: String? = nil,
originalArrivalTime: Iso8601Date? = nil,
version: String
) {
self.messageId = messageId
self.type = type
self.threadId = threadId
self.senderId = senderId
self.recipientId = recipientId
self.sender = sender
self.recipient = recipient
self.senderDisplayName = senderDisplayName
self.originalArrivalTime = originalArrivalTime
self.version = version
Expand Down Expand Up @@ -113,8 +113,8 @@ public class PushNotificationChatMessageReceivedEvent: PushNotificationChatMessa
messageId: pushNotificationMessageReceivedPayload.messageId,
type: ChatMessageType(pushNotificationMessageReceivedPayload.messageType),
threadId: pushNotificationMessageReceivedPayload.groupId,
senderId: pushNotificationMessageReceivedPayload.senderId,
recipientId: pushNotificationMessageReceivedPayload.recipientId,
sender: getIdentifier(from: pushNotificationMessageReceivedPayload.senderId),
recipient: getIdentifier(from: pushNotificationMessageReceivedPayload.recipientId),
senderDisplayName: pushNotificationMessageReceivedPayload.senderDisplayName,
originalArrivalTime: Iso8601Date(string: pushNotificationMessageReceivedPayload.originalArrivalTime),
version: pushNotificationMessageReceivedPayload.version
Expand Down
Loading