@azure/communication-react
Version:
React library for building modern communication user experiences utilizing Azure Communication Services
59 lines • 2.07 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createIdentifierFromRawId, getIdentifierRawId, isCommunicationUserIdentifier, isMicrosoftTeamsUserIdentifier, isPhoneNumberIdentifier, isUnknownIdentifier } from '@azure/communication-common';
/**
* A string representation of a {@link @azure/communication-common#CommunicationIdentifier}.
*
* This string representation of CommunicationIdentifier is guaranteed to be stable for
* a unique Communication user. Thus,
* - it can be used to persist a user's identity in external databases.
* - it can be used as keys into a Map to store data for the user.
*
* @public
*/
export const toFlatCommunicationIdentifier = (identifier) => {
return getIdentifierRawId(identifier);
};
/**
* Reverse operation of {@link toFlatCommunicationIdentifier}.
*
* @public
*/
export const fromFlatCommunicationIdentifier = (id) => {
// if the id passed is a phone number we need to build the rawId to pass in
const rawId = id.indexOf('+') === 0 ? '4:' + id : id;
return createIdentifierFromRawId(rawId);
};
/**
* Returns a CommunicationIdentifier.
* @internal
*/
export const _toCommunicationIdentifier = (id) => {
if (typeof id === 'string') {
return fromFlatCommunicationIdentifier(id);
}
return id;
};
/**
* Check if an object is identifier.
*
* @internal
*/
export const _isValidIdentifier = (identifier) => {
return isCommunicationUserIdentifier(identifier) || isPhoneNumberIdentifier(identifier) || isMicrosoftTeamsUserIdentifier(identifier) || isUnknownIdentifier(identifier);
};
/**
* Check if given identifier is a Microsoft Teams user.
*
* @internal
* @param rawId - The rawId of the identifier.
* @returns True if the identifier is a Microsoft Teams user. False otherwise.
*/
export const _isIdentityMicrosoftTeamsUser = (rawId) => {
if (!rawId) {
return false;
}
const identifier = _toCommunicationIdentifier(rawId);
return isMicrosoftTeamsUserIdentifier(identifier);
};
//# sourceMappingURL=identifier.js.map