Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
6 changes: 5 additions & 1 deletion common/config/babel/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ module.exports = {
// feature for tracking the callParticipantsLocator
"call-participants-locator",
// Feature for RTT
"rtt"
"rtt",
Comment thread
prabhjot-msft marked this conversation as resolved.
// Feature for together mode
"together-mode",
// Feature for on fetch profile
"on-fetch-profile"
],
stable: [
// Demo feature. Used in live-documentation of conditional compilation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ export const createAzureCommunicationCallWithChatAdapterFromClients: ({ callClie
export const createAzureCommunicationChatAdapter: ({ endpoint: endpointUrl, userId, displayName, credential, threadId }: AzureCommunicationChatAdapterArgs) => Promise<ChatAdapter>;

// @public
export function createAzureCommunicationChatAdapterFromClient(chatClient: StatefulChatClient, chatThreadClient: ChatThreadClient): Promise<ChatAdapter>;
export function createAzureCommunicationChatAdapterFromClient(chatClient: StatefulChatClient, chatThreadClient: ChatThreadClient, onFetchProfile?: OnFetchChatProfileCallback): Promise<ChatAdapter>;

// @public
export type CreateDefaultCallingHandlers = (callClient: StatefulCallClient, callAgent: CallAgent | undefined, deviceManager: StatefulDeviceManager | undefined, call: Call | undefined, options?: CallingHandlersOptions) => CallingHandlers;
Expand Down Expand Up @@ -4272,6 +4272,9 @@ export type NotificationTarget = /* @conditional-compile-remove(breakout-rooms)
// @public
export type NotificationType = keyof NotificationStackStrings;

// @public
export type OnFetchChatProfileCallback = (userId: string, defaultProfile?: Profile_2) => Promise<Profile_2 | undefined>;

// @public
export type OnFetchProfileCallback = (userId: string, defaultProfile?: Profile) => Promise<Profile | undefined>;

Expand Down Expand Up @@ -4514,6 +4517,11 @@ export type Profile = {
displayName?: string;
};

// @public
Comment thread
prabhjot-msft marked this conversation as resolved.
Outdated
export type Profile_2 = {
displayName?: string;
};

// @public
export type RaisedHand = {
raisedHandOrderPosition: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,8 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
displayName,
credential,
chatThreadAdapter.getChatThreadPromise(),
'CallWithChat' as _TelemetryImplementationHint
'CallWithChat' as _TelemetryImplementationHint,
callAdapterOptions?.onFetchProfile
);
callWithChatAdapter.setChatAdapterPromise(chatAdapterPromise);
/* @conditional-compile-remove(breakout-rooms) */
Expand All @@ -1281,7 +1282,8 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
displayName,
credential,
threadId,
'CallWithChat' as _TelemetryImplementationHint
'CallWithChat' as _TelemetryImplementationHint,
callAdapterOptions?.onFetchProfile
)
);
return callWithChatAdapter;
Expand All @@ -1292,7 +1294,8 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
displayName,
credential,
chatThreadAdapter.getChatThread(),
'CallWithChat' as _TelemetryImplementationHint
'CallWithChat' as _TelemetryImplementationHint,
callAdapterOptions?.onFetchProfile
);

const callWithChatAdapter = new AzureCommunicationCallWithChatAdapter(await callAdapter, await chatAdapter);
Expand All @@ -1304,7 +1307,8 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
displayName,
credential,
threadId,
'CallWithChat' as _TelemetryImplementationHint
'CallWithChat' as _TelemetryImplementationHint,
callAdapterOptions?.onFetchProfile
)
);
return callWithChatAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ import { _isValidIdentifier } from '@internal/acs-ui-common';
import { TEAMS_LIMITATION_LEARN_MORE, UNSUPPORTED_CHAT_THREAD_TYPE } from '../../common/constants';
/* @conditional-compile-remove(file-sharing-acs) */
import { MessageOptions } from '@internal/acs-ui-common';
/* @conditional-compile-remove(on-fetch-profile) */
import { createProfileStateModifier } from './OnFetchProfileCallback';
/* @conditional-compile-remove(on-fetch-profile) */
import type { OnFetchChatProfileCallback } from './OnFetchProfileCallback';

/**
* @private
*/
export type AdapterStateModifier = (state: ChatAdapterState) => ChatAdapterState;

/**
* Context of Chat, which is a centralized context for all state updates
Expand All @@ -50,8 +59,15 @@ export class ChatContext {
private emitter: EventEmitter = new EventEmitter();
private state: ChatAdapterState;
private threadId: string;

constructor(clientState: ChatClientState, threadId: string) {
/* @conditional-compile-remove(on-fetch-profile) */
private displayNameModifier: AdapterStateModifier | undefined;

constructor(
clientState: ChatClientState,
threadId: string,
/* @conditional-compile-remove(on-fetch-profile) */
onFetchProfile?: OnFetchChatProfileCallback
) {
const thread = clientState.threads[threadId];
this.threadId = threadId;
if (!thread) {
Expand All @@ -63,6 +79,12 @@ export class ChatContext {
thread,
latestErrors: clientState.latestErrors
};
/* @conditional-compile-remove(on-fetch-profile) */
this.displayNameModifier = onFetchProfile
? createProfileStateModifier(onFetchProfile, () => {
this.setState(this.getState());
})
: undefined;
}

public onStateChange(handler: (_uiState: ChatAdapterState) => void): void {
Expand All @@ -75,6 +97,8 @@ export class ChatContext {

public setState(state: ChatAdapterState): void {
this.state = state;
/* @conditional-compile-remove(on-fetch-profile) */
this.state = this.displayNameModifier ? this.displayNameModifier(state) : state;
this.emitter.emit('stateChanged', this.state);
}

Expand Down Expand Up @@ -116,11 +140,15 @@ export class AzureCommunicationChatAdapter implements ChatAdapter {
private handlers: ChatHandlers;
private emitter: EventEmitter = new EventEmitter();

constructor(chatClient: StatefulChatClient, chatThreadClient: ChatThreadClient) {
constructor(
chatClient: StatefulChatClient,
chatThreadClient: ChatThreadClient,
onFetchProfile?: OnFetchChatProfileCallback
) {
this.bindAllPublicMethods();
this.chatClient = chatClient;
this.chatThreadClient = chatThreadClient;
this.context = new ChatContext(chatClient.getState(), chatThreadClient.threadId);
this.context = new ChatContext(chatClient.getState(), chatThreadClient.threadId, onFetchProfile);

const onStateChange = (clientState: ChatClientState): void => {
// unsubscribe when the instance gets disposed
Expand Down Expand Up @@ -505,7 +533,9 @@ export const _createAzureCommunicationChatAdapterInner = async (
displayName: string,
credential: CommunicationTokenCredential,
threadId: string,
telemetryImplementationHint: _TelemetryImplementationHint = 'Chat'
telemetryImplementationHint: _TelemetryImplementationHint = 'Chat',
/* @conditional-compile-remove(on-fetch-profile) */
onFetchProfile?: OnFetchChatProfileCallback
): Promise<ChatAdapter> => {
if (!_isValidIdentifier(userId)) {
throw new Error('Provided userId is invalid. Please provide valid identifier object.');
Expand All @@ -524,7 +554,7 @@ export const _createAzureCommunicationChatAdapterInner = async (
const chatThreadClient = await chatClient.getChatThreadClient(threadId);
await chatClient.startRealtimeNotifications();

const adapter = await createAzureCommunicationChatAdapterFromClient(chatClient, chatThreadClient);
const adapter = await createAzureCommunicationChatAdapterFromClient(chatClient, chatThreadClient, onFetchProfile);

return adapter;
};
Expand All @@ -540,7 +570,9 @@ export const _createLazyAzureCommunicationChatAdapterInner = async (
displayName: string,
credential: CommunicationTokenCredential,
threadId: Promise<string>,
telemetryImplementationHint: _TelemetryImplementationHint = 'Chat'
telemetryImplementationHint: _TelemetryImplementationHint = 'Chat',
/* @conditional-compile-remove(on-fetch-profile) */
onFetchProfile?: OnFetchChatProfileCallback
): Promise<ChatAdapter> => {
if (!_isValidIdentifier(userId)) {
throw new Error('Provided userId is invalid. Please provide valid identifier object.');
Expand All @@ -566,7 +598,7 @@ export const _createLazyAzureCommunicationChatAdapterInner = async (
const chatThreadClient = await chatClient.getChatThreadClient(threadId);
await chatClient.startRealtimeNotifications();

const adapter = await createAzureCommunicationChatAdapterFromClient(chatClient, chatThreadClient);
const adapter = await createAzureCommunicationChatAdapterFromClient(chatClient, chatThreadClient, onFetchProfile);

return adapter;
});
Expand Down Expand Up @@ -696,9 +728,11 @@ export const useAzureCommunicationChatAdapter = (
*/
export async function createAzureCommunicationChatAdapterFromClient(
chatClient: StatefulChatClient,
chatThreadClient: ChatThreadClient
chatThreadClient: ChatThreadClient,
/* @conditional-compile-remove(on-fetch-profile) */
onFetchProfile?: OnFetchChatProfileCallback
): Promise<ChatAdapter> {
return new AzureCommunicationChatAdapter(chatClient, chatThreadClient);
return new AzureCommunicationChatAdapter(chatClient, chatThreadClient, onFetchProfile);
}

const isChatError = (e: Error): e is ChatError => {
Expand Down
Loading
Loading