import { FC } from "react"; import { useDebounce } from "rooks"; import Tippy from "@tippyjs/react"; import FavList from "../FavList"; import Tooltip from "../../../common/component/Tooltip"; import FavIcon from "../../../assets/icons/bookmark.svg"; import { useReadMessageMutation } from "../../../app/services/message"; import User from "../../../common/component/User"; import Layout from "../Layout"; import LoadMore from "../LoadMore"; import { renderMessageFragment } from "../utils"; import useMessageFeed from "../../../common/hook/useMessageFeed"; import { useAppSelector } from "../../../app/store"; type Props = { uid: number; dropFiles?: File[]; }; const DMChat: FC = ({ uid = 0, dropFiles }) => { const { pulling, list: msgIds, appends, hasMore, pullUp } = useMessageFeed({ context: "user", id: uid }); const [updateReadIndex] = useReadMessageMutation(); const updateReadDebounced = useDebounce(updateReadIndex, 300); const { currUser, messageData, footprint, loginUid, selects } = useAppSelector((store) => { return { selects: store.ui.selectMessages[`user_${uid}`], loginUid: store.authData.user?.uid, footprint: store.footprint, currUser: store.users.byId[uid], messageData: store.message }; }); if (!currUser) return null; const readIndex = footprint.readUsers[uid]; const feeds = [...msgIds, ...appends]; return ( } >
  • } header={
    } >
    {hasMore ? : null} {[...feeds].map((mid, idx) => { const curr = messageData[mid]; const prev = idx == 0 ? null : messageData[feeds[idx - 1]]; const read = curr?.from_uid == loginUid || mid <= readIndex; return renderMessageFragment({ selectMode: !!selects, updateReadIndex: updateReadDebounced, read, prev, curr, contextId: uid, context: "user" }); })}
    ); }; export default DMChat;