refactor: virtual message feed
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import localforage from "localforage";
|
||||
import clearTable from "./clear.handler";
|
||||
interface Params {
|
||||
payload: any;
|
||||
@@ -5,7 +6,7 @@ interface Params {
|
||||
operation: string;
|
||||
}
|
||||
export default async function handler({ operation, data = {}, payload }: Params) {
|
||||
const table = window.CACHE["footprint"];
|
||||
const table = window.CACHE["footprint"] as typeof localforage;;
|
||||
if (operation.startsWith("reset")) {
|
||||
clearTable("footprint");
|
||||
return;
|
||||
@@ -20,7 +21,14 @@ export default async function handler({ operation, data = {}, payload }: Params)
|
||||
case "updateAfterMid":
|
||||
{
|
||||
const afterMid = payload;
|
||||
await table?.setItem("afterMid", afterMid);
|
||||
// console.log("local after mid", afterMid, data);
|
||||
table.getItem("afterMid").then((val) => {
|
||||
const storedNum = Number(val ?? 0);
|
||||
if (storedNum < afterMid) {
|
||||
table?.setItem("afterMid", afterMid);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
break;
|
||||
case "updateMute":
|
||||
|
||||
@@ -160,9 +160,10 @@ export const messageApi = createApi({
|
||||
},
|
||||
async onQueryStarted(params, { dispatch, getState, queryFulfilled }) {
|
||||
const { data: messages } = await queryFulfilled;
|
||||
const fromHistory = true;
|
||||
if (messages?.length) {
|
||||
messages.forEach((msg) => {
|
||||
handleChatMessage(msg, dispatch, getState() as RootState);
|
||||
handleChatMessage(msg, dispatch, getState() as RootState, fromHistory);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,11 @@ const footprintSlice = createSlice({
|
||||
state.usersVersion = action.payload;
|
||||
},
|
||||
updateAfterMid(state, action: PayloadAction<number>) {
|
||||
state.afterMid = action.payload;
|
||||
const newMid = action.payload;
|
||||
// 如果新mid小于已有的afterMid,则不必更新
|
||||
if (state.afterMid < newMid) {
|
||||
state.afterMid = action.payload;
|
||||
}
|
||||
},
|
||||
updateAutoDeleteSetting(state, action: PayloadAction<AutoDeleteMessageSettingDTO>) {
|
||||
const payload = action.payload;
|
||||
|
||||
Reference in New Issue
Block a user