Skip to content

Commit 62d7971

Browse files
[onFetchProfile] Add onFetchProfile for CallWithChat composite (#5729)
* Add onFetchProfile for CallWithChat Composite * minor * ARB comments * Add test * Change files
1 parent f1100e0 commit 62d7971

9 files changed

Lines changed: 467 additions & 23 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "minor",
3+
"area": "feature",
4+
"workstream": "Add onFetchProfile in CallWithChat Composite",
5+
"comment": "Add onFetchProfile for CallWithChat Composite",
6+
"packageName": "@azure/communication-react",
7+
"email": "97124699+prabhjot-msft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "minor",
3+
"area": "feature",
4+
"workstream": "Add onFetchProfile in CallWithChat Composite",
5+
"comment": "Add onFetchProfile for CallWithChat Composite",
6+
"packageName": "@azure/communication-react",
7+
"email": "97124699+prabhjot-msft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}

common/config/babel/features.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ module.exports = {
2020
// Demo feature. Used in live-documentation of conditional compilation. Do not use in production code.
2121
"in-progress-beta-feature-demo",
2222
// Feature for remote UFD
23-
"remote-ufd"
23+
"remote-ufd",
24+
// Feature for on fetch profile
25+
"on-fetch-profile"
2426
],
2527
beta: [
2628
"call-readiness",

packages/communication-react/review/beta/communication-react.api.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export type AzureCommunicationChatAdapterArgs = {
311311
displayName: string;
312312
credential: CommunicationTokenCredential;
313313
threadId: string;
314+
chatAdapterOptions?: ChatAdapterOptions;
314315
};
315316

316317
// @public
@@ -2039,6 +2040,11 @@ export interface CaptionsSettingsModalStrings {
20392040
// @public
20402041
export type ChatAdapter = ChatAdapterThreadManagement & AdapterState<ChatAdapterState> & Disposable_2 & ChatAdapterSubscribers;
20412042

2043+
// @public
2044+
export type ChatAdapterOptions = {
2045+
onFetchProfile?: OnFetchChatProfileCallback;
2046+
};
2047+
20422048
// @public
20432049
export type ChatAdapterState = ChatAdapterUiState & ChatCompositeClientState;
20442050

@@ -2266,6 +2272,11 @@ export type ChatParticipantListSelector = (state: ChatClientState, props: ChatBa
22662272
participants: ParticipantListParticipant[];
22672273
};
22682274

2275+
// @public
2276+
export type ChatProfile = {
2277+
displayName?: string;
2278+
};
2279+
22692280
// @public
22702281
export type ChatReturnProps<Component extends (props: any) => JSX.Element> = GetChatSelector<Component> extends (state: ChatClientState, props: any) => any ? ReturnType<GetChatSelector<Component>> & Common<ChatHandlers, Parameters<Component>[0]> : never;
22712282

@@ -2821,10 +2832,10 @@ export const createAzureCommunicationCallWithChatAdapter: ({ userId, displayName
28212832
export const createAzureCommunicationCallWithChatAdapterFromClients: ({ callClient, callAgent, callLocator, chatClient, chatThreadClient, callAdapterOptions }: AzureCommunicationCallWithChatAdapterFromClientArgs) => Promise<CallWithChatAdapter>;
28222833

28232834
// @public
2824-
export const createAzureCommunicationChatAdapter: ({ endpoint: endpointUrl, userId, displayName, credential, threadId }: AzureCommunicationChatAdapterArgs) => Promise<ChatAdapter>;
2835+
export const createAzureCommunicationChatAdapter: ({ endpoint: endpointUrl, userId, displayName, credential, threadId, chatAdapterOptions }: AzureCommunicationChatAdapterArgs) => Promise<ChatAdapter>;
28252836

28262837
// @public
2827-
export function createAzureCommunicationChatAdapterFromClient(chatClient: StatefulChatClient, chatThreadClient: ChatThreadClient): Promise<ChatAdapter>;
2838+
export function createAzureCommunicationChatAdapterFromClient(chatClient: StatefulChatClient, chatThreadClient: ChatThreadClient, chatAdapterOptions?: ChatAdapterOptions): Promise<ChatAdapter>;
28282839

28292840
// @public
28302841
export type CreateDefaultCallingHandlers = (callClient: StatefulCallClient, callAgent: CallAgent | undefined, deviceManager: StatefulDeviceManager | undefined, call: Call | undefined, options?: CallingHandlersOptions) => CallingHandlers;
@@ -4299,6 +4310,9 @@ export type NotificationTarget = 'assignedBreakoutRoomOpened' | 'assignedBreakou
42994310
// @public
43004311
export type NotificationType = keyof NotificationStackStrings;
43014312

4313+
// @public
4314+
export type OnFetchChatProfileCallback = (userId: string, defaultProfile?: ChatProfile) => Promise<ChatProfile | undefined>;
4315+
43024316
// @public
43034317
export type OnFetchProfileCallback = (userId: string, defaultProfile?: Profile) => Promise<Profile | undefined>;
43044318

packages/react-composites/src/composites/CallWithChatComposite/adapter/AzureCommunicationCallWithChatAdapter.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import {
4949
MessageDeletedListener
5050
} from '../../ChatComposite';
5151
import { ResourceDetails } from '../../ChatComposite';
52+
/* @conditional-compile-remove(on-fetch-profile) */
53+
import type { ChatAdapterOptions } from '../../ChatComposite';
5254
import { CallWithChatAdapter, CallWithChatEvent, ChatInitializedListener } from './CallWithChatAdapter';
5355
import {
5456
callWithChatAdapterStateFromBackingStates,
@@ -1242,6 +1244,10 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
12421244
});
12431245

12441246
const chatThreadAdapter = _createChatThreadAdapterInner(locator, callAdapter);
1247+
/* @conditional-compile-remove(on-fetch-profile) */
1248+
const chatAdapterOptions: ChatAdapterOptions = {
1249+
onFetchProfile: callAdapterOptions?.onFetchProfile
1250+
};
12451251
if (chatThreadAdapter.isCallInfoRequired()) {
12461252
const callWithChatAdapter = new AzureCommunicationCallWithChatAdapter(await callAdapter);
12471253
const chatAdapterPromise = _createLazyAzureCommunicationChatAdapterInner(
@@ -1250,7 +1256,9 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
12501256
displayName,
12511257
credential,
12521258
chatThreadAdapter.getChatThreadPromise(),
1253-
'CallWithChat' as _TelemetryImplementationHint
1259+
'CallWithChat' as _TelemetryImplementationHint,
1260+
/* @conditional-compile-remove(on-fetch-profile) */
1261+
chatAdapterOptions
12541262
);
12551263
callWithChatAdapter.setChatAdapterPromise(chatAdapterPromise);
12561264
callWithChatAdapter.setCreateChatAdapterCallback((threadId: string) =>
@@ -1260,7 +1268,9 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
12601268
displayName,
12611269
credential,
12621270
threadId,
1263-
'CallWithChat' as _TelemetryImplementationHint
1271+
'CallWithChat' as _TelemetryImplementationHint,
1272+
/* @conditional-compile-remove(on-fetch-profile) */
1273+
chatAdapterOptions
12641274
)
12651275
);
12661276
return callWithChatAdapter;
@@ -1271,7 +1281,9 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
12711281
displayName,
12721282
credential,
12731283
chatThreadAdapter.getChatThread(),
1274-
'CallWithChat' as _TelemetryImplementationHint
1284+
'CallWithChat' as _TelemetryImplementationHint,
1285+
/* @conditional-compile-remove(on-fetch-profile) */
1286+
chatAdapterOptions
12751287
);
12761288

12771289
const callWithChatAdapter = new AzureCommunicationCallWithChatAdapter(await callAdapter, await chatAdapter);
@@ -1282,7 +1294,9 @@ export const createAzureCommunicationCallWithChatAdapter = async ({
12821294
displayName,
12831295
credential,
12841296
threadId,
1285-
'CallWithChat' as _TelemetryImplementationHint
1297+
'CallWithChat' as _TelemetryImplementationHint,
1298+
/* @conditional-compile-remove(on-fetch-profile) */
1299+
chatAdapterOptions
12861300
)
12871301
);
12881302
return callWithChatAdapter;

packages/react-composites/src/composites/ChatComposite/adapter/AzureCommunicationChatAdapter.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,44 @@ describe('Error is reflected in state and events', () => {
179179
});
180180
});
181181

182+
/* @conditional-compile-remove(on-fetch-profile) */
183+
describe('Adapter is created with chatAdapterOptions', () => {
184+
it('should create adapter with onFetchProfile option', async () => {
185+
const token = {
186+
getToken: jest.fn(),
187+
dispose: jest.fn()
188+
};
189+
190+
ChatClientMock.mockImplementation((): ChatClient => {
191+
return new StubChatClient(new StubChatThreadClient()) as unknown as ChatClient;
192+
});
193+
194+
const onFetchProfile = jest.fn();
195+
const adapter = await createAzureCommunicationChatAdapter({
196+
endpoint: 'stubEndpointUrl',
197+
userId: { communicationUserId: 'stubUserId' },
198+
displayName: 'stubDisplayName',
199+
credential: token,
200+
threadId: 'stubThreadId',
201+
chatAdapterOptions: { onFetchProfile }
202+
});
203+
204+
expect(adapter).toBeDefined();
205+
});
206+
207+
it('should create adapter with chatAdapterOptions', async () => {
208+
const statefulChatClient = createStatefulChatClientMock(new StubChatThreadClient());
209+
const threadClient = statefulChatClient.getChatThreadClient('threadId');
210+
const onFetchProfile = jest.fn();
211+
212+
const adapter = await createAzureCommunicationChatAdapterFromClient(statefulChatClient, threadClient, {
213+
onFetchProfile
214+
});
215+
216+
expect(adapter).toBeDefined();
217+
});
218+
});
219+
182220
const createChatAdapterWithStubs = async (
183221
chatClient: StubChatClient,
184222
fakeToken?: CommunicationTokenCredential

0 commit comments

Comments
 (0)