Skip to content

Commit f008412

Browse files
committed
Clean up
1 parent 0f54313 commit f008412

10 files changed

Lines changed: 190 additions & 300 deletions

packages/acs-chat-adapter/src/ACSChatAdapter.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ ACSChatAdapter.defaultProps = {
170170
userProfiles: {}
171171
};
172172

173-
// TODO: Since ACS do not provide profile data, we should have a mapProfile function to convert userId -> (avatar image, initials, name).
174173
ACSChatAdapter.propTypes = {
175174
children: PropTypes.func.isRequired,
176175
endpointURL: PropTypes.string.isRequired,

packages/acs-chat-adapter/src/composers/ACSChatMessagesComposer.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import createDebug from '../utils/debug';
99
import styleConsole from '../utils/styleConsole';
1010
import useACSChatThreadSelector from '../hooks/useACSChatThreadSelector';
1111
import useACSClients from '../hooks/useACSClients';
12-
import useDebounced from '../hooks/useDebounced';
1312
import usePrevious from '../hooks/usePrevious';
1413
import warn from '../utils/warn';
1514

@@ -76,24 +75,12 @@ const ACSChatMessageComposer: FC = ({ children }) => {
7675
}
7776
}
7877

79-
// const context = useMemo(
80-
// () => ({
81-
// chatMessages,
82-
// connectivityStatus
83-
// }),
84-
// [chatMessages, connectivityStatus]
85-
// );
86-
87-
// TODO: Remove useDebounced.
88-
// eslint-disable-next-line no-magic-numbers
89-
const debouncedChatMessages = useDebounced(chatMessages, 1000);
90-
9178
const context = useMemo(
9279
() => ({
93-
chatMessages: debouncedChatMessages,
80+
chatMessages,
9481
connectivityStatus
9582
}),
96-
[connectivityStatus, debouncedChatMessages]
83+
[chatMessages, connectivityStatus]
9784
);
9885

9986
return <ACSChatMessagesContext.Provider value={context}>{children}</ACSChatMessagesContext.Provider>;

packages/acs-chat-adapter/src/composers/ACSClientsComposer.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ const ACSDeclarativesComposer: FC<{ children: any; endpointURL: string; threadId
5353
const chatClient = useMemo(() => new ChatClient(endpointURL, credentials), [credentials, endpointURL]);
5454

5555
const declarativeChatClient = useMemo(
56-
// TODO: Type ChatClient from @azure/communication-chat is not compatible with @azure/acs-chat-declarative.
5756
// TODO: What to do with "displayName" and "userId"?
58-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59-
() => chatClientDeclaratify(chatClient as any, { displayName: '', userId: '' }),
57+
() => chatClientDeclaratify(chatClient, { displayName: '', userId: '' }),
6058
[chatClient]
6159
);
6260

@@ -71,9 +69,7 @@ const ACSDeclarativesComposer: FC<{ children: any; endpointURL: string; threadId
7169
(async function () {
7270
const declarativeChatThreadClient = await declarativeChatClient.getChatThreadClient(threadId);
7371

74-
// TODO: Fix the typing. Declarative SDK should export the type DeclarativeChatThreadClient.
75-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
76-
abortController.signal.aborted || setDeclarativeChatThreadClient(declarativeChatThreadClient as any);
72+
abortController.signal.aborted || setDeclarativeChatThreadClient(declarativeChatThreadClient);
7773
})();
7874

7975
return () => abortController.abort();

packages/acs-chat-adapter/src/composers/ActivitiesComposer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1] }] */
22
/* eslint complexity: "off" */
33

4-
import { ReadBy, updateMetadata } from 'botframework-webchat-core';
4+
import { ReadBy } from 'botframework-webchat-core';
55
import PropTypes from 'prop-types';
66
import React, { FC, useCallback, useMemo, useRef } from 'react';
77
import updateIn from 'simple-update-in';
@@ -134,7 +134,7 @@ const ActivitiesComposer2: FC<{ children: any; userProfiles: UserProfiles }> = (
134134
const activities = useMemoAll<Activity, Activity[]>(
135135
useCallback(
136136
(key, chatMessage, readBy, trackingNumber) =>
137-
updateMetadata(convert(chatMessage), {
137+
convert(chatMessage, {
138138
key,
139139
readBy,
140140
trackingNumber

packages/acs-chat-adapter/src/converters/createACSMessageToWebChatActivityConverter.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
/* eslint complexity: ["error", 30] */
22

3-
import { EventActivity, MessageActivity, updateMetadata } from 'botframework-webchat-core';
3+
import { EventActivity, MessageActivity, ReadBy, updateMetadata } from 'botframework-webchat-core';
44

55
import ACSChatMessage from '../types/ACSChatMessage';
66
import Activity from '../types/Activity';
77
import createDebug from '../utils/debug';
8-
import styleConsole from '../utils/styleConsole';
98
import UserProfiles from '../types/UserProfiles';
109

1110
let debug;
1211

13-
// TODO: Verify this logic with ACS team to see if this is correct.
14-
// function isOthersUserId(userId: string) {
15-
// return userId.startsWith('8:');
16-
// }
17-
1812
// "threadId" is undefined for messages from others, so we prefer to use the "threadId" from setup.
1913
export default function createACSMessageToWebChatActivityConverter({
2014
threadId,
@@ -24,39 +18,32 @@ export default function createACSMessageToWebChatActivityConverter({
2418
threadId: string;
2519
userId: string;
2620
userProfiles: UserProfiles;
27-
}): (chatMessage: ACSChatMessage) => Activity {
21+
}): (acsChatMessage: ACSChatMessage, metadata: { key: string; readBy: ReadBy; trackingNumber: string }) => Activity {
2822
debug ||
2923
(debug = createDebug('util:acsMessageToWebChatActivity', {
3024
backgroundColor: 'lightgray',
3125
color: 'black'
3226
}));
3327

34-
return acsChatMessage => {
28+
return (
29+
acsChatMessage: ACSChatMessage,
30+
metadata: { key: string; readBy: ReadBy; trackingNumber: string }
31+
): Activity => {
3532
const now = new Date();
3633
const { clientMessageId, content, createdOn, id, sender, senderDisplayName, status, type } = acsChatMessage;
3734

3835
// TODO: Checks with ACS team to see if this is a good strategy to find out "user.kind".
39-
const who: 'others' | 'self' | 'service' = sender
40-
? sender.communicationUserId && sender.communicationUserId !== userId
41-
? 'others'
42-
: 'self'
43-
: 'service';
36+
const who: 'others' | 'self' | 'service' = !sender
37+
? 'service'
38+
: sender.communicationUserId && sender.communicationUserId !== userId
39+
? 'others'
40+
: 'self';
4441

4542
const communicationUserId = who === 'self' ? userId : who === 'service' ? undefined : sender.communicationUserId;
4643

47-
const userProfile = who === 'others' || who === 'self' ? userProfiles[communicationUserId || userId] : undefined;
44+
const userProfile = who === 'others' || who === 'self' ? userProfiles[communicationUserId] : undefined;
4845

49-
// TODO: Assert data if it met our expectation.
50-
if (who === 'self') {
51-
// Assertion: to work properly, every activity must contains an ID during their lifetime, and this ID must not be changed during any moment of its life.
52-
if (!clientMessageId && !id) {
53-
// TODO: Check if conversation history contains "clientMessageId".
54-
// TODO: After the message is sent and echoed back from ACS, the "clientMessageId" is gone.
55-
// This is crucial for the operation of Web Chat, because, if we can't reference the same message, we will be creating new DOM elements.
56-
// Creating new DOM elements will hurt accessibility (ARIA live region).
57-
debug('🔥🔥🔥 %cFor all self messages, "clientMessageId" and/or "id" must be set.%c', ...styleConsole('red'));
58-
}
59-
}
46+
// TODO: Add assertions here to make sure the data met our expectation.
6047

6148
const senderName = (userProfile || {}).name || senderDisplayName;
6249

@@ -83,8 +70,10 @@ export default function createACSMessageToWebChatActivityConverter({
8370
} as any,
8471
{
8572
avatarInitials: (userProfile || {}).initials,
86-
key: clientMessageId || id,
73+
key: metadata.key,
74+
readBy: metadata.readBy,
8775
senderName,
76+
trackingNumber: metadata.trackingNumber,
8877
who
8978
}
9079
);
@@ -117,9 +106,6 @@ export default function createACSMessageToWebChatActivityConverter({
117106
...activityContent
118107
},
119108
{
120-
// deliveryStatus: createdOn ? undefined : 'sending' // If it contains "createdOn", it's sent.
121-
122-
// 'delivered' | 'sending' | 'seen' | 'failed'
123109
deliveryStatus: status === 'failed' ? 'error' : status === 'sending' ? status : undefined
124110
}
125111
);

packages/acs-chat-adapter/src/hooks/useACSReadReceiptsWithFetchAndSubscribe.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)