refactor: unify chat context type

This commit is contained in:
Tristan Yang
2023-05-15 13:26:55 +08:00
parent c6edf3e8b1
commit 110b0891ad
30 changed files with 79 additions and 51 deletions
+2 -2
View File
@@ -31,11 +31,11 @@ const DMChat: FC<Props> = ({ uid = 0, dropFiles }) => {
return (
<Layout
to={uid}
context="user"
context="dm"
dropFiles={dropFiles}
aside={
<ul className="flex flex-col gap-6">
<ServerVersionChecker version="0.3.6" empty={true}>
<ServerVersionChecker version="0.3.7" empty={true}>
<VoiceChat context={`dm`} id={uid} />
</ServerVersionChecker>
<Tooltip tip="Saved Items" placement="left">
+2 -1
View File
@@ -1,8 +1,9 @@
// import { useEffect } from "react";
import { ChatPrefixes } from "../../../app/config";
import { useTranslation } from "react-i18next";
import { ChatContext } from "../../../types/common";
type Props = {
context: "user" | "channel",
context: ChatContext,
name: string
};
const DnDTip = ({ context, name }: Props) => {
@@ -3,9 +3,10 @@ import clsx from 'clsx';
import { useTranslation } from 'react-i18next';
import { useAppSelector } from '../../../app/store';
import getUnreadCount from '../utils';
import { ChatContext } from '../../../types/common';
type Props = {
context: "channel" | "user",
context: ChatContext,
id: number,
scrollToBottom?: () => void
}
@@ -20,7 +21,7 @@ const NewMessageBottomTip = ({ context, id, scrollToBottom }: Props) => {
} = useAppSelector((store) => {
return {
readIndex: context == "channel" ? store.footprint.readChannels[id] : store.footprint.readUsers[id],
mids: context == "user" ? store.userMessage.byId[id] : store.channelMessage[id],
mids: context == "dm" ? store.userMessage.byId[id] : store.channelMessage[id],
selects: store.ui.selectMessages[`${context}_${id}`],
loginUid: store.authData.user?.uid ?? 0,
data: context == "channel" ? store.channels.byId[id] : undefined,
+2 -1
View File
@@ -11,9 +11,10 @@ import IconClose from "../../../assets/icons/close.circle.svg";
import ForwardModal from "../../../common/component/ForwardModal";
import DeleteMessageConfirmModal from "../../../common/component/DeleteMessageConfirm";
import { useAppDispatch, useAppSelector } from "../../../app/store";
import { ChatContext } from "../../../types/common";
type Props = {
context: "user" | "channel";
context: ChatContext;
id: number;
};
const Operations: FC<Props> = ({ context, id }) => {
@@ -12,8 +12,9 @@ import CustomList from './CustomList';
import CustomHeader from './CustomHeader';
import { useDispatch } from 'react-redux';
import { updateHistoryMark } from '../../../../app/slices/footprint';
import { ChatContext } from '../../../../types/common';
type Props = {
context: "user" | "channel",
context: ChatContext,
id: number
}
// const firstMsgIndex = 10000;
@@ -36,8 +37,8 @@ const VirtualMessageFeed = ({ context, id }: Props) => {
footprint
} = useAppSelector((store) => {
return {
historyMid: context == "user" ? store.footprint.historyUsers[id] : store.footprint.historyChannels[id],
mids: context == "user" ? store.userMessage.byId[id] : store.channelMessage[id],
historyMid: context == "dm" ? store.footprint.historyUsers[id] : store.footprint.historyChannels[id],
mids: context == "dm" ? store.userMessage.byId[id] : store.channelMessage[id],
selects: store.ui.selectMessages[`${context}_${id}`],
footprint: store.footprint,
loginUser: store.authData.user,
+4 -3
View File
@@ -19,6 +19,7 @@ import ImagePreview from "../../../common/component/ImagePreview";
import VirtualMessageFeed from "./VirtualMessageFeed";
import DMVoice from "./DMVoicing";
import AddContactTip from "./AddContactTip";
import { ChatContext } from "../../../types/common";
interface Props {
readonly?: boolean;
@@ -27,7 +28,7 @@ interface Props {
users?: ReactElement | null;
voice?: ReactElement | null;
dropFiles?: File[];
context: "channel" | "user";
context: ChatContext;
to: number;
}
@@ -100,8 +101,8 @@ const Layout: FC<Props> = ({
{header}
<div className="w-full h-full flex items-start justify-between relative" >
<div className="rounded-br-2xl flex flex-col absolute bottom-0 w-full h-full" ref={messagesContainer}>
{context == "user" && <DMVoice uid={to} />}
{context == "user" && <AddContactTip uid={to} />}
{context == "dm" && <DMVoice uid={to} />}
{context == "dm" && <AddContactTip uid={to} />}
{/* 消息流 */}
<VirtualMessageFeed key={`${context}_${to}`} context={context} id={to} />
{/* 发送框 */}
+3 -2
View File
@@ -10,6 +10,7 @@ import { updateSelectMessages } from "../../app/slices/ui";
import { useAppSelector } from "../../app/store";
import LinkifyText from "../../common/component/LinkifyText";
import i18n from "../../i18n";
import { ChatContext } from "../../types/common";
export function getUnreadCount({
mids = [],
@@ -122,7 +123,7 @@ type Params = {
prev?: object | null;
curr: object | null;
contextId: number;
context: "user" | "channel";
context: ChatContext;
};
export const renderMessageFragment = ({
readonly = false,
@@ -132,7 +133,7 @@ export const renderMessageFragment = ({
prev,
curr = null,
contextId = 0,
context = "user"
context = "dm"
}: Params) => {
if (!curr) return <div className="w-full h-[1px] invisible"></div>;
let { created_at, mid } = curr;