refactor: voice data structure
This commit is contained in:
@@ -16,20 +16,20 @@ import { useAppSelector } from "../../../app/store";
|
||||
import { fromNowTime } from "../../../common/utils";
|
||||
|
||||
interface IProps {
|
||||
type?: "user" | "channel";
|
||||
type?: "dm" | "channel";
|
||||
id: number;
|
||||
mid: number;
|
||||
setDeleteChannelId: (param: number) => void;
|
||||
setInviteChannelId: (param: number) => void;
|
||||
}
|
||||
const Session: FC<IProps> = ({
|
||||
type = "user",
|
||||
type = "dm",
|
||||
id,
|
||||
mid,
|
||||
setDeleteChannelId,
|
||||
setInviteChannelId
|
||||
}) => {
|
||||
const navPath = type == "user" ? `/chat/dm/${id}` : `/chat/channel/${id}`;
|
||||
const navPath = type == "dm" ? `/chat/dm/${id}` : `/chat/channel/${id}`;
|
||||
// const { pathname } = useLocation();
|
||||
const isCurrentPath = useMatch(navPath);
|
||||
const navigate = useNavigate();
|
||||
@@ -46,7 +46,7 @@ const Session: FC<IProps> = ({
|
||||
return { size, type, name, url };
|
||||
});
|
||||
addStageFile(filesData);
|
||||
navigate(type == "user" ? `/chat/dm/${id}` : `/chat/channel/${id}`);
|
||||
navigate(type == "dm" ? `/chat/dm/${id}` : `/chat/channel/${id}`);
|
||||
}
|
||||
},
|
||||
collect: (monitor) => ({
|
||||
@@ -62,24 +62,24 @@ const Session: FC<IProps> = ({
|
||||
mid: number;
|
||||
is_public: boolean;
|
||||
}>();
|
||||
const { messageData, userData, channelData, readIndex, loginUid, mids, muted, voiceInfo } = useAppSelector(
|
||||
const { messageData, userData, channelData, readIndex, loginUid, mids, muted, voiceList } = useAppSelector(
|
||||
(store) => {
|
||||
return {
|
||||
voiceInfo: store.voice.voicing,
|
||||
mids: type == "user" ? store.userMessage.byId[id] : store.channelMessage[id],
|
||||
voiceList: store.voice.list,
|
||||
mids: type == "dm" ? store.userMessage.byId[id] : store.channelMessage[id],
|
||||
loginUid: store.authData.user?.uid || 0,
|
||||
readIndex:
|
||||
type == "user" ? store.footprint.readUsers[id] : store.footprint.readChannels[id],
|
||||
type == "dm" ? store.footprint.readUsers[id] : store.footprint.readChannels[id],
|
||||
messageData: store.message,
|
||||
userData: store.users.byId,
|
||||
channelData: store.channels.byId,
|
||||
muted: type == "user" ? store.footprint.muteUsers[id] : store.footprint.muteChannels[id]
|
||||
muted: type == "dm" ? store.footprint.muteUsers[id] : store.footprint.muteChannels[id]
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const tmp = type == "user" ? userData[id] : channelData[id];
|
||||
const tmp = type == "dm" ? userData[id] : channelData[id];
|
||||
if (!tmp) return;
|
||||
if ("avatar" in tmp) {
|
||||
// user
|
||||
@@ -100,6 +100,7 @@ const Session: FC<IProps> = ({
|
||||
messageData,
|
||||
loginUid
|
||||
});
|
||||
const isVoicing = type == "channel" && voiceList.findIndex(item => item.id == id) > -1;
|
||||
return (
|
||||
<li className="session">
|
||||
<ContextMenu
|
||||
@@ -118,7 +119,7 @@ const Session: FC<IProps> = ({
|
||||
onContextMenu={handleContextMenuEvent}
|
||||
>
|
||||
<div className="flex shrink-0 relative">
|
||||
{type == "user" ? (
|
||||
{type == "dm" ? (
|
||||
<User avatarSize={40} compact interactive={false} uid={id} />
|
||||
) : (
|
||||
<Avatar
|
||||
@@ -130,7 +131,7 @@ const Session: FC<IProps> = ({
|
||||
src={icon}
|
||||
/>
|
||||
)}
|
||||
{type == "channel" && voiceInfo.id == id && <IconVoicing className="-top-0.5 -right-0.5 absolute w-[18px] h-[18px]" />}
|
||||
{isVoicing && <IconVoicing className="-top-0.5 -right-0.5 absolute w-[18px] h-[18px]" />}
|
||||
</div>
|
||||
<div className="w-full flex flex-col justify-between overflow-hidden">
|
||||
<div className="flex items-center justify-between ">
|
||||
|
||||
@@ -6,7 +6,7 @@ import DeleteChannelConfirmModal from "../../settingChannel/DeleteConfirmModal";
|
||||
import InviteModal from "../../../common/component/InviteModal";
|
||||
import { useAppSelector } from "../../../app/store";
|
||||
export interface ChatSession {
|
||||
type: "user" | "channel";
|
||||
type: "dm" | "channel";
|
||||
id: number;
|
||||
mid: number;
|
||||
unread: number;
|
||||
@@ -46,11 +46,11 @@ const SessionList: FC<Props> = ({ tempSession }) => {
|
||||
// console.log("adddd", id);
|
||||
const mids = userMessage[id];
|
||||
if (!mids || mids.length == 0) {
|
||||
return { unreads: 0, id, type: "user" };
|
||||
return { unreads: 0, id, type: "dm" };
|
||||
}
|
||||
// 先转换成数字,再排序
|
||||
const mid = [...mids].sort((a, b) => +a - +b).pop();
|
||||
return { type: "user", id, mid };
|
||||
return { type: "dm", id, mid };
|
||||
});
|
||||
const temps = [...(cSessions as ChatSession[]), ...(uSessions as ChatSession[])].sort((a, b) => {
|
||||
const { mid: aMid = 0 } = a;
|
||||
|
||||
Reference in New Issue
Block a user