refactor: archive message
This commit is contained in:
Vendored
+5
-1
@@ -28,7 +28,11 @@ const tables = [
|
||||
},
|
||||
{
|
||||
storeName: "messageFile",
|
||||
description: "store file message list refs"
|
||||
description: "store file message list"
|
||||
},
|
||||
{
|
||||
storeName: "messageArchive",
|
||||
description: "store archive message"
|
||||
},
|
||||
{
|
||||
storeName: "messageReaction",
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import clearTable from "./clear.handler";
|
||||
interface Params {
|
||||
payload: any;
|
||||
operation: string;
|
||||
}
|
||||
export default async function handler({ operation, payload = {} }: Params) {
|
||||
const table = window.CACHE["messageArchive"];
|
||||
if (operation.startsWith("reset")) {
|
||||
clearTable("messageArchive");
|
||||
return;
|
||||
}
|
||||
switch (operation) {
|
||||
case "upsertArchiveMessage":
|
||||
{
|
||||
const { filePath, data } = payload;
|
||||
console.log("archive message indexDB opt", payload);
|
||||
if (filePath) {
|
||||
await table?.setItem(filePath, data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import dmMsgHandler from "./handler.dm.msg";
|
||||
import serverHandler from "./handler.server";
|
||||
import messageHandler from "./handler.message";
|
||||
import fileMessageHandler from "./handler.file.msg";
|
||||
import archiveMessageHandler from "./handler.archive.msg";
|
||||
import reactionHandler from "./handler.reaction";
|
||||
import UIHandler from "./handler.ui";
|
||||
import footprintHandler from "./handler.footprint";
|
||||
@@ -20,6 +21,7 @@ const operations = [
|
||||
"userMessage",
|
||||
"reactionMessage",
|
||||
"fileMessage",
|
||||
"archiveMessage",
|
||||
"message",
|
||||
"ui",
|
||||
"footprint",
|
||||
@@ -35,7 +37,7 @@ listenerMiddleware.startListening({
|
||||
predicate: (action) => {
|
||||
const { type = "" } = action;
|
||||
const [prefix] = type.split("/");
|
||||
// console.log("operation", type, operations.includes(prefix));
|
||||
// console.log("operation", type);
|
||||
return operations.includes(prefix);
|
||||
// console.log("listener predicate", action, currentState, previousState);
|
||||
// return true;
|
||||
@@ -102,6 +104,14 @@ listenerMiddleware.startListening({
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "archiveMessage":
|
||||
{
|
||||
await archiveMessageHandler({
|
||||
operation,
|
||||
payload
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "message":
|
||||
{
|
||||
await messageHandler({
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Archive, FavoriteArchive, OG } from "../../types/resource";
|
||||
import { ChatMessage, ContentTypeKey, UploadFileResponse } from "../../types/message";
|
||||
import handleChatMessage from "../../common/hook/useStreaming/chat.handler";
|
||||
import { RootState } from "../store";
|
||||
import { upsertArchiveMessage } from "../slices/message.archive";
|
||||
|
||||
export const messageApi = createApi({
|
||||
reducerPath: "messageApi",
|
||||
@@ -85,9 +86,17 @@ export const messageApi = createApi({
|
||||
}),
|
||||
|
||||
getArchiveMessage: builder.query<Archive, string>({
|
||||
query: (file_path) => ({
|
||||
url: `/resource/archive?file_path=${encodeURIComponent(file_path)}`
|
||||
})
|
||||
query: (filePath) => ({
|
||||
url: `/resource/archive?file_path=${encodeURIComponent(filePath)}`
|
||||
}),
|
||||
async onQueryStarted(filePath, { dispatch, queryFulfilled }) {
|
||||
try {
|
||||
const { data } = await queryFulfilled;
|
||||
dispatch(upsertArchiveMessage({ filePath, data }));
|
||||
} catch (err) {
|
||||
console.log("get archive error", err);
|
||||
}
|
||||
}
|
||||
}),
|
||||
pinMessage: builder.mutation<void, { gid: number; mid: number }>({
|
||||
query: ({ gid, mid }) => ({
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
// import { ContentTypes } from "../config";
|
||||
// import { normalizeFileMessage } from "../../common/utils";
|
||||
// import { ContentType } from "../../types/message";
|
||||
import { Archive } from "../../types/resource";
|
||||
export interface State {
|
||||
[key: string]: Archive;
|
||||
}
|
||||
const initialState: State = {
|
||||
};
|
||||
|
||||
const messageArchiveSlice = createSlice({
|
||||
name: "archiveMessage",
|
||||
initialState,
|
||||
reducers: {
|
||||
resetArchiveMessage() {
|
||||
return initialState;
|
||||
},
|
||||
fillArchiveMessage(state, action) {
|
||||
return Object.assign({ ...initialState }, action.payload);
|
||||
},
|
||||
upsertArchiveMessage(state, action: PayloadAction<{ filePath: string, data: Archive }>) {
|
||||
const { filePath, data } = action.payload;
|
||||
state[filePath] = data;
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
export const {
|
||||
resetArchiveMessage,
|
||||
fillArchiveMessage,
|
||||
upsertArchiveMessage
|
||||
} = messageArchiveSlice.actions;
|
||||
|
||||
export default messageArchiveSlice.reducer;
|
||||
@@ -13,6 +13,7 @@ import channelMsgReducer from "./slices/message.channel";
|
||||
import userMsgReducer from "./slices/message.user";
|
||||
import favoritesReducer from "./slices/favorites";
|
||||
import fileMsgReducer from "./slices/message.file";
|
||||
import archiveMsgReducer from "./slices/message.archive";
|
||||
import messageReducer from "./slices/message";
|
||||
import { authApi } from "./services/auth";
|
||||
import { userApi } from "./services/user";
|
||||
@@ -32,6 +33,7 @@ const reducer = combineReducers({
|
||||
userMessage: userMsgReducer,
|
||||
channelMessage: channelMsgReducer,
|
||||
fileMessage: fileMsgReducer,
|
||||
archiveMessage: archiveMsgReducer,
|
||||
message: messageReducer,
|
||||
[authApi.reducerPath]: authApi.reducer,
|
||||
[messageApi.reducerPath]: messageApi.reducer,
|
||||
|
||||
Reference in New Issue
Block a user