import { $, Tab, TextField } from "mdui" import useEventListener from "../../utils/useEventListener" import useEffectRef from "../../utils/useEffectRef" import isMobileUI from "../../utils/isMobileUI" import { Chat } from "lingchair-client-protocol" import Preference from "../preference/Preference" import PreferenceHeader from "../preference/PreferenceHeader" import PreferenceLayout from "../preference/PreferenceLayout" import PreferenceUpdater from "../preference/PreferenceUpdater" import SwitchPreference from "../preference/SwitchPreference" import TextFieldPreference from "../preference/TextFieldPreference" import * as React from 'react' import ChatMessageContainer from "./ChatMessageContainer" import AppStateContext from "../app-state/AppStateContext" import ChatPanel, { ChatPanelRef } from "./ChatPanel" interface MduiTabFitSizeArgs extends React.HTMLAttributes { value: string } function MduiTabFitSize({ children, ...props }: MduiTabFitSizeArgs) { return {children} } export default function ChatFragment({ chatInfo, openedInDialog, }: { chatInfo: Chat openedInDialog: boolean }) { const AppState = React.useContext(AppStateContext) const [tabItemSelected, setTabItemSelected] = React.useState('Chat') const tabRef = React.useRef() useEventListener(tabRef, 'change', () => { tabRef.current != null && setTabItemSelected(tabRef.current!.value as string) }) const chatPanelRef = React.useRef() const inputRef = React.useRef() const chatPagePanelRef = React.useRef() async function performSendMessage() { await chatInfo.sendMessageOrThrow(inputRef.current!.value) inputRef.current!.value = '' } return (
((ref) => { $(ref.current!.shadowRoot).append(``) $(tabRef.current!.shadowRoot).append(``) ; (!isMobileUI()) && $(tabRef.current!.shadowRoot).append(``) }, [])} style={{ position: 'sticky', display: "flex", flexDirection: "column", }}> { openedInDialog && AppState.closeChat()} style={{ alignSelf: 'center', marginLeft: '5px', marginRight: '5px', }}> } { chatInfo.isMember() ? <> {chatInfo.getTitle()} {chatInfo.getType() == 'group' && chatInfo.isAdmin() && 加入请求} {chatInfo.getType() == 'group' && 群组成员} : {chatInfo.getTitle()} } {chatInfo.getType() == 'group' && 设置}
{ window.open('/chat?id=' + chatInfo.getId(), '_blank') }} style={{ alignSelf: 'center', marginLeft: '5px', marginRight: '5px', }}> { }} style={{ alignSelf: 'center', marginLeft: '5px', marginRight: '5px', }}> AppState.openChatInfo(chatInfo.getId())} style={{ alignSelf: 'center', marginLeft: '5px', marginRight: '5px', }}>
{/* 非群成员 */}
{ const scrollTop = (e.target as HTMLDivElement).scrollTop if (scrollTop == 0) { // 加载更多 chatPagePanelRef.current?.setOffset(chatPagePanelRef.current.getOffset() + 15) } }}>
{/* 这里显示一些提示 */}
{ // 输入框 }
{ // 文件拽入 }}> { if (inputRef.current?.value.trim() == '') { // 清空缓存的文件 } }} onKeyDown={(event: KeyboardEvent) => { if (event.ctrlKey && event.key == 'Enter') { // 发送消息 performSendMessage() } }} onPaste={(event: ClipboardEvent) => { for (const item of event.clipboardData?.items || []) { if (item.kind == 'file') { event.preventDefault() const file = item.getAsFile() as File // 添加文件 } } }} style={{ marginRight: '10px', marginTop: '3px', marginBottom: '3px', }}> { // 添加文件 }}>
{ chatInfo.getType() == 'group' && {/* */} } { chatInfo.getType() == 'group' && {/* {chatInfo.isAdmin() && } */} }
{ // 群组设置? } { chatInfo.getType() == 'private' && (
未制作
) }
) }