-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathuseActivityKeysOfSendStatus.ts
More file actions
30 lines (24 loc) · 1020 Bytes
/
useActivityKeysOfSendStatus.ts
File metadata and controls
30 lines (24 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { hooks } from 'botframework-webchat-api';
import { useMemo } from 'react';
import type { SendStatus } from '../../types/internal/SendStatus';
import isPresentational from './isPresentational';
const { useGetActivityByKey, useSendStatusByActivityKey } = hooks;
/**
* Returns the set of keys of outgoing non-presentational activities that currently
* have the given send status.
*
* Presentational activities (e.g. `event` or `typing`) are excluded to reduce noise.
*/
export default function useActivityKeysOfSendStatus(status: SendStatus): Set<string> {
const [sendStatusByActivityKey] = useSendStatusByActivityKey();
const getActivityByKey = useGetActivityByKey();
return useMemo<Set<string>>(() => {
const keys = new Set<string>();
for (const [key, sendStatus] of sendStatusByActivityKey) {
if (sendStatus === status && !isPresentational(getActivityByKey(key))) {
keys.add(key);
}
}
return keys;
}, [getActivityByKey, sendStatusByActivityKey, status]);
}