feat: remove session realtime
This commit is contained in:
@@ -60,7 +60,7 @@ const userMsgSlice = createSlice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeUserSession(state, action) {
|
removeUserSession(state, action: PayloadAction<number | number[]>) {
|
||||||
const ids = Array.isArray(action.payload) ? action.payload : [action.payload];
|
const ids = Array.isArray(action.payload) ? action.payload : [action.payload];
|
||||||
state.ids = state.ids.filter((id) => ids.findIndex((i) => i == id) == -1);
|
state.ids = state.ids.filter((id) => ids.findIndex((i) => i == id) == -1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import { useAppDispatch, useAppSelector } from "../../../app/store";
|
|||||||
import { ServerEvent, UsersStateEvent } from "../../../types/sse";
|
import { ServerEvent, UsersStateEvent } from "../../../types/sse";
|
||||||
import { useRenewMutation } from "../../../app/services/auth";
|
import { useRenewMutation } from "../../../app/services/auth";
|
||||||
import { getLocalAuthData } from "../../utils";
|
import { getLocalAuthData } from "../../utils";
|
||||||
|
import { removeUserSession } from "../../../app/slices/message.user";
|
||||||
|
import { removeChannelSession } from "../../../app/slices/message.channel";
|
||||||
|
|
||||||
const getQueryString = (params: { [key: string]: string }) => {
|
const getQueryString = (params: { [key: string]: string }) => {
|
||||||
const sp = new URLSearchParams();
|
const sp = new URLSearchParams();
|
||||||
@@ -155,6 +157,10 @@ export default function useStreaming() {
|
|||||||
if (uid === loginUid && action === "update") {
|
if (uid === loginUid && action === "update") {
|
||||||
dispatch(updateLoginUser(omitBy(rest, isNull)));
|
dispatch(updateLoginUser(omitBy(rest, isNull)));
|
||||||
}
|
}
|
||||||
|
if (action === "delete") {
|
||||||
|
// 同时删掉对应的聊天记录
|
||||||
|
dispatch(removeUserSession(uid));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -265,8 +271,11 @@ export default function useStreaming() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "kick_from_group":
|
case "kick_from_group": {
|
||||||
dispatch(removeChannel(data.gid));
|
dispatch(removeChannel(data.gid));
|
||||||
|
// 同时清掉channel聊天记录
|
||||||
|
dispatch(removeChannelSession(data.gid));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "pinned_message_updated":
|
case "pinned_message_updated":
|
||||||
dispatch(updatePinMessage(data));
|
dispatch(updatePinMessage(data));
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { useState, useEffect, memo } from "react";
|
import { useState, useEffect, memo } from "react";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import Tippy from "@tippyjs/react";
|
import Tippy from "@tippyjs/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
|
|
||||||
import PinList from "./PinList";
|
import PinList from "./PinList";
|
||||||
import FavList from "../FavList";
|
import FavList from "../FavList";
|
||||||
import { updateRememberedNavs } from "../../../app/slices/ui";
|
import { updateRememberedNavs } from "../../../app/slices/ui";
|
||||||
@@ -11,9 +13,7 @@ import Layout from "../Layout";
|
|||||||
import IconFav from "../../../assets/icons/bookmark.svg";
|
import IconFav from "../../../assets/icons/bookmark.svg";
|
||||||
import IconPeople from "../../../assets/icons/people.svg";
|
import IconPeople from "../../../assets/icons/people.svg";
|
||||||
import IconPin from "../../../assets/icons/pin.svg";
|
import IconPin from "../../../assets/icons/pin.svg";
|
||||||
|
|
||||||
import { useAppSelector } from "../../../app/store";
|
import { useAppSelector } from "../../../app/store";
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import GoBackNav from "../../../common/component/GoBackNav";
|
import GoBackNav from "../../../common/component/GoBackNav";
|
||||||
import Members from "./Members";
|
import Members from "./Members";
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -23,6 +23,7 @@ type Props = {
|
|||||||
function ChannelChat({ cid = 0, dropFiles = [] }: Props) {
|
function ChannelChat({ cid = 0, dropFiles = [] }: Props) {
|
||||||
const { t } = useTranslation("chat");
|
const { t } = useTranslation("chat");
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [membersVisible, setMembersVisible] = useState(true);
|
const [membersVisible, setMembersVisible] = useState(true);
|
||||||
|
|
||||||
@@ -37,6 +38,12 @@ function ChannelChat({ cid = 0, dropFiles = [] }: Props) {
|
|||||||
data: store.channels.byId[cid],
|
data: store.channels.byId[cid],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
useEffect(() => {
|
||||||
|
if (!data) {
|
||||||
|
// channel不存在了 回首页
|
||||||
|
navigate("/chat");
|
||||||
|
}
|
||||||
|
}, [data]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(updateRememberedNavs());
|
dispatch(updateRememberedNavs());
|
||||||
return () => {
|
return () => {
|
||||||
@@ -48,6 +55,7 @@ function ChannelChat({ cid = 0, dropFiles = [] }: Props) {
|
|||||||
setMembersVisible((prev) => !prev);
|
setMembersVisible((prev) => !prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (!data) return null;
|
if (!data) return null;
|
||||||
const { name, description, is_public, members = [], owner } = data;
|
const { name, description, is_public, members = [], owner } = data;
|
||||||
const memberIds = is_public ? userIds : members.slice(0).sort((n) => (n == owner ? -1 : 0));
|
const memberIds = is_public ? userIds : members.slice(0).sort((n) => (n == owner ? -1 : 0));
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { FC } from "react";
|
import { FC, useEffect } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import Tippy from "@tippyjs/react";
|
import Tippy from "@tippyjs/react";
|
||||||
import FavList from "../FavList";
|
import FavList from "../FavList";
|
||||||
import Tooltip from "../../../common/component/Tooltip";
|
import Tooltip from "../../../common/component/Tooltip";
|
||||||
@@ -12,11 +13,18 @@ type Props = {
|
|||||||
dropFiles?: File[];
|
dropFiles?: File[];
|
||||||
};
|
};
|
||||||
const DMChat: FC<Props> = ({ uid = 0, dropFiles }) => {
|
const DMChat: FC<Props> = ({ uid = 0, dropFiles }) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
const { currUser } = useAppSelector((store) => {
|
const { currUser } = useAppSelector((store) => {
|
||||||
return {
|
return {
|
||||||
currUser: store.users.byId[uid],
|
currUser: store.users.byId[uid],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
useEffect(() => {
|
||||||
|
if (!currUser) {
|
||||||
|
// user不存在了 回首页
|
||||||
|
navigate("/chat");
|
||||||
|
}
|
||||||
|
}, [currUser]);
|
||||||
if (!currUser) return null;
|
if (!currUser) return null;
|
||||||
return (
|
return (
|
||||||
<Layout
|
<Layout
|
||||||
|
|||||||
Reference in New Issue
Block a user