refactor: unify chat context type

This commit is contained in:
Tristan Yang
2023-05-15 13:26:55 +08:00
parent c6edf3e8b1
commit 110b0891ad
30 changed files with 79 additions and 51 deletions
+2 -1
View File
@@ -10,6 +10,7 @@ import { ChatMessage, ContentTypeKey, UploadFileResponse } from "../../types/mes
import handleChatMessage from "../../common/hook/useStreaming/chat.handler";
import { RootState } from "../store";
import { upsertArchiveMessage } from "../slices/message.archive";
import { ChatContext } from "../../types/common";
export const messageApi = createApi({
reducerPath: "messageApi",
@@ -175,7 +176,7 @@ export const messageApi = createApi({
}
}
}),
loadMoreMessages: builder.query<ChatMessage[], { context?: "channel" | "user", id: number; mid?: number; limit?: number }>({
loadMoreMessages: builder.query<ChatMessage[], { context?: ChatContext, id: number; mid?: number; limit?: number }>({
query: ({ context = "channel", id, mid = "", limit = 100 }) => {
const url = context == "channel" ?
`/group/${id}/history?limit=${limit}${mid ? `&before=${mid}` : ""}`
+2 -1
View File
@@ -3,6 +3,7 @@ import { MuteDTO } from "../../types/message";
import { OG } from "../../types/resource";
import { AutoDeleteMessageSettingDTO, AutoDeleteMsgForGroup, AutoDeleteMsgForUser, AutoDeleteSettingForChannels, AutoDeleteSettingForUsers, PinChat, PinChatTarget } from "../../types/sse";
import { resetAuthData } from "./auth.data";
import { ChatContext } from "../../types/common";
type ChannelAside = "members" | "voice" | "voice_fullscreen" | null;
type DMAside = "voice" | null;
@@ -188,7 +189,7 @@ const footprintSlice = createSlice({
const { key, value } = action.payload;
state.og[key] = value;
},
updateHistoryMark(state, action: PayloadAction<{ type: "channel" | "user", id: number, mid: string, }>) {
updateHistoryMark(state, action: PayloadAction<{ type: ChatContext, id: number, mid: string, }>) {
const { type, id, mid } = action.payload;
if (type == "channel") {
state.historyChannels[id] = mid;
+2 -1
View File
@@ -2,9 +2,10 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { KEY_UID } from "../config";
import { ConnectionState } from "agora-rtc-sdk-ng";
import { resetAuthData } from "./auth.data";
import { ChatContext } from "../../types/common";
export type VoiceBasicInfo = {
context: "channel" | "dm",
context: ChatContext,
from?: number,
id: number,// means to in dm context
}