refactor: after mid

This commit is contained in:
Tristan Yang
2023-03-16 17:37:49 +08:00
parent 8cb2415519
commit a5f520dd36
2 changed files with 11 additions and 4 deletions
@@ -9,6 +9,7 @@ import { ContentTypes } from "../../../app/config";
import { ChatEvent } from "../../../types/sse"; import { ChatEvent } from "../../../types/sse";
import { AppDispatch } from "../../../app/store"; import { AppDispatch } from "../../../app/store";
type CurrentState = { type CurrentState = {
afterMid: number,
ready: boolean; ready: boolean;
loginUid: number; loginUid: number;
readUsers: { readUsers: {
@@ -47,8 +48,12 @@ const handler = (data: ChatEvent, dispatch: AppDispatch, currState: CurrentState
switch (type) { switch (type) {
case "normal": case "normal":
case "reply": case "reply":
{
if (currState.afterMid < mid) {
// 更新after_mid // 更新after_mid
dispatch(updateAfterMid(mid)); dispatch(updateAfterMid(mid));
}
}
break; break;
} }
} }
+4 -2
View File
@@ -1,5 +1,8 @@
import { useEffect, useState, useCallback } from "react"; import { useEffect, useState, useCallback } from "react";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import dayjs from "dayjs";
import { isNull, omitBy } from "lodash";
import BASE_URL from "../../../app/config"; import BASE_URL from "../../../app/config";
import { setReady } from "../../../app/slices/ui"; import { setReady } from "../../../app/slices/ui";
import { import {
@@ -21,9 +24,7 @@ import { resetAuthData, updateLoginUser } from "../../../app/slices/auth.data";
import chatMessageHandler from "./chat.handler"; import chatMessageHandler from "./chat.handler";
import { useAppDispatch, useAppSelector } from "../../../app/store"; import { useAppDispatch, useAppSelector } from "../../../app/store";
import { ServerEvent, UsersStateEvent } from "../../../types/sse"; import { ServerEvent, UsersStateEvent } from "../../../types/sse";
import { isNull, omitBy } from "lodash";
import { useRenewMutation } from "../../../app/services/auth"; import { useRenewMutation } from "../../../app/services/auth";
import dayjs from "dayjs";
import { getLocalAuthData } from "../../utils"; import { getLocalAuthData } from "../../utils";
const getQueryString = (params: { [key: string]: string }) => { const getQueryString = (params: { [key: string]: string }) => {
@@ -272,6 +273,7 @@ export default function useStreaming() {
break; break;
case "chat": { case "chat": {
chatMessageHandler(data, dispatch, { chatMessageHandler(data, dispatch, {
afterMid,
ready, ready,
loginUid, loginUid,
readUsers, readUsers,