refactor: voice operations

This commit is contained in:
Tristan Yang
2023-05-17 17:32:33 +08:00
parent d931bf8daa
commit c0c1dc8bf5
13 changed files with 312 additions and 163 deletions
+9 -2
View File
@@ -24,7 +24,7 @@ import {
} from "@/types/server";
import { Channel } from "@/types/channel";
import { ContentTypeKey } from "@/types/message";
import { upsertVoiceList } from "../slices/voice";
import { updateCallInfo, upsertVoiceList } from "../slices/voice";
const defaultExpireDuration = 2 * 24 * 60 * 60;
@@ -119,8 +119,9 @@ export const serverApi = createApi({
}),
getAgoraChannels: builder.query<AgoraVoicingListResponse, { page_no: number, page_size: number }>({
query: (param = { page_no: 0, page_size: 100 }) => ({ url: `/admin/agora/channel/${param.page_no}/${param.page_size}` }),
async onQueryStarted(data, { dispatch, queryFulfilled }) {
async onQueryStarted(data, { dispatch, queryFulfilled, getState }) {
try {
const { voice: { callingFrom }, authData } = getState() as RootState;
const { data: resp } = await queryFulfilled;
const { success } = resp;
if (success) {
@@ -136,6 +137,12 @@ export const serverApi = createApi({
};
});
dispatch(upsertVoiceList(arr));
const hasMyself = arr.some(data => data.context === "dm" && data.id == authData?.user?.uid);
const sendByMe = callingFrom && callingFrom === authData?.user?.uid;
// reset dm call setting
if (callingFrom && !sendByMe && !hasMyself) {
dispatch(updateCallInfo({ from: 0, to: 0, calling: false }));
}
}
} catch {
console.error("get voice list error");