-
Notifications
You must be signed in to change notification settings - Fork 342
/
Copy pathuseGroupAck.ts
31 lines (26 loc) · 1.01 KB
/
useGroupAck.ts
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
31
import { useEvent } from '../../hooks/useEvent';
import { updateAck } from '../../model/converse';
import { isConversePanel } from '../../utils/panel-helper';
import { chatActions } from '../slices';
import { useAppDispatch, useAppSelector } from './useAppSelector';
import { useGroupInfo } from './useGroup';
/**
* 群组级别的已读管理
*/
export function useGroupAck(groupId: string) {
const groupInfo = useGroupInfo(groupId);
const lastMessageMap = useAppSelector((state) => state.chat.lastMessageMap);
const dispatch = useAppDispatch();
const markGroupAllAck = useEvent(() => {
const conversePanels = (groupInfo?.panels ?? []).filter(isConversePanel);
for (const converse of conversePanels) {
const converseId = converse.id;
const lastMessageId = lastMessageMap[converseId];
if (converseId && lastMessageId) {
dispatch(chatActions.setConverseAck({ converseId, lastMessageId }));
updateAck(converseId, lastMessageId);
}
}
});
return { markGroupAllAck };
}