Skip to content

Commit

Permalink
fixed 2 bugs (#25860)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR


### Issues associated with this PR


### Describe the problem that is addressed by this PR


### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
juntuchen-msft committed May 12, 2023
1 parent fb734dc commit 6d27a62
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export class CallConnection {
targetParticipant: CommunicationIdentifier,
options: GetParticipantOptions = {}
): Promise<CallParticipant> {
const rawId: string = communicationIdentifierModelConverter(targetParticipant).rawId || "";
if (!rawId) throw Error("Invalid targetParticipant");
let rawId: string | undefined = communicationIdentifierModelConverter(targetParticipant).rawId;
rawId = rawId === undefined ? "" : rawId;

const result = await this.callConnection.getParticipant(this.callConnectionId, rawId, options);
const callParticipant: CallParticipant = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ import {
isCommunicationUserIdentifier,
isPhoneNumberIdentifier,
isUnknownIdentifier,
SerializedCommunicationIdentifier,
isMicrosoftTeamsUserIdentifier,
MicrosoftTeamsUserIdentifier,
} from "@azure/communication-common";
import {
CallParticipantInternal,
CommunicationIdentifierModel,
CommunicationIdentifierModelKind,
CommunicationUserIdentifierModel,
KnownCommunicationCloudEnvironmentModel,
KnownCommunicationIdentifierModelKind,
PhoneNumberIdentifierModel,
CommunicationUserIdentifierModel,
} from "../generated/src";
import { CallParticipant } from "../models/models";

Expand Down Expand Up @@ -96,6 +100,19 @@ export function communicationIdentifierConverter(
return phoneNumberIdentifier;
}

if (
kind === KnownCommunicationIdentifierModelKind.MicrosoftTeamsUser &&
identifierModel.microsoftTeamsUser !== undefined
) {
const microsoftTeamsUserIdentifier: MicrosoftTeamsUserIdentifier = {
rawId: rawId,
microsoftTeamsUserId: identifierModel.microsoftTeamsUser.userId,
isAnonymous: identifierModel.microsoftTeamsUser.isAnonymous,
cloud: identifierModel.microsoftTeamsUser.cloud as KnownCommunicationCloudEnvironmentModel,
};
return microsoftTeamsUserIdentifier;
}

const unknownIdentifier: UnknownIdentifier = {
id: rawId ? rawId : "",
};
Expand All @@ -106,32 +123,36 @@ export function communicationIdentifierConverter(
export function communicationIdentifierModelConverter(
identifier: CommunicationIdentifier
): CommunicationIdentifierModel {
const serializedIdentifier: SerializedCommunicationIdentifier =
serializeCommunicationIdentifier(identifier);
if (isCommunicationUserIdentifier(identifier)) {
const communicationUserIdentifierModel: CommunicationIdentifierModel = {
rawId: identifier.communicationUserId,
kind: KnownCommunicationIdentifierModelKind.CommunicationUser,
communicationUser: {
id: identifier.communicationUserId,
},
...serializedIdentifier,
};
return communicationUserIdentifierModel;
}

if (isPhoneNumberIdentifier(identifier)) {
const phoneNumberIdentifierModel: CommunicationIdentifierModel = {
rawId: identifier.rawId,
kind: KnownCommunicationIdentifierModelKind.PhoneNumber,
phoneNumber: {
value: identifier.phoneNumber,
},
...serializedIdentifier,
};
return phoneNumberIdentifierModel;
}

if (isMicrosoftTeamsUserIdentifier(identifier)) {
const microsoftTeamsUserIdentifierModel: CommunicationIdentifierModel = {
kind: KnownCommunicationIdentifierModelKind.MicrosoftTeamsUser,
...serializedIdentifier,
};
return microsoftTeamsUserIdentifierModel;
}

if (isUnknownIdentifier(identifier)) {
const unknownIdentifierModel: CommunicationIdentifierModel = {
rawId: identifier.id,
kind: KnownCommunicationIdentifierModelKind.Unknown,
...serializedIdentifier,
};
return unknownIdentifierModel;
}
Expand Down

0 comments on commit 6d27a62

Please sign in to comment.