Compare commits

..

2 Commits

Author SHA1 Message Date
CrescentLeaf
8c74eaacb1 updated 2025-12-14 17:44:56 +08:00
CrescentLeaf
db3dca724a 导出更多消息对象 2025-12-14 16:40:02 +08:00
5 changed files with 69 additions and 65 deletions

View File

@@ -7,9 +7,8 @@ import CallbackError from "./CallbackError.ts"
import ApiCallbackMessage from "./ApiCallbackMessage.ts" import ApiCallbackMessage from "./ApiCallbackMessage.ts"
import * as marked from 'marked' import * as marked from 'marked'
import { text } from "node:stream/consumers";
class ChatMention extends BaseClientObject { export class ChatMention extends BaseClientObject {
declare chat_id?: string declare chat_id?: string
declare user_id?: string declare user_id?: string
declare text?: string declare text?: string
@@ -41,7 +40,7 @@ class ChatMention extends BaseClientObject {
type FileType = 'Video' | 'Image' | 'File' type FileType = 'Video' | 'Image' | 'File'
type MentionType = 'ChatMention' | 'UserMention' type MentionType = 'ChatMention' | 'UserMention'
class ChatAttachment extends BaseClientObject { export class ChatAttachment extends BaseClientObject {
declare file_hash: string declare file_hash: string
declare file_name: string declare file_name: string
constructor(client: LingChairClient, { constructor(client: LingChairClient, {

View File

@@ -7,6 +7,7 @@ import GroupSettingsBean from "./bean/GroupSettingsBean.ts"
import JoinRequestBean from "./bean/JoinRequestBean.ts" import JoinRequestBean from "./bean/JoinRequestBean.ts"
import MessageBean from "./bean/MessageBean.ts" import MessageBean from "./bean/MessageBean.ts"
import RecentChatBean from "./bean/RecentChatBean.ts" import RecentChatBean from "./bean/RecentChatBean.ts"
import Message, { ChatAttachment, ChatMention } from "./Message.ts"
import LingChairClient from "./LingChairClient.ts" import LingChairClient from "./LingChairClient.ts"
import CallbackError from "./CallbackError.ts" import CallbackError from "./CallbackError.ts"
@@ -14,10 +15,13 @@ import CallbackError from "./CallbackError.ts"
export { export {
LingChairClient, LingChairClient,
CallbackError, CallbackError,
Chat, Chat,
User, User,
UserMySelf, UserMySelf,
Message,
ChatAttachment,
ChatMention,
UserBean, UserBean,
ChatBean, ChatBean,

View File

@@ -12,6 +12,7 @@ import PreferenceUpdater from "../preference/PreferenceUpdater"
import SwitchPreference from "../preference/SwitchPreference" import SwitchPreference from "../preference/SwitchPreference"
import TextFieldPreference from "../preference/TextFieldPreference" import TextFieldPreference from "../preference/TextFieldPreference"
import * as React from 'react' import * as React from 'react'
import ChatMessageContainer from "./ChatMessageContainer"
interface MduiTabFitSizeArgs extends React.HTMLAttributes<HTMLElement & Tab> { interface MduiTabFitSizeArgs extends React.HTMLAttributes<HTMLElement & Tab> {
value: string value: string
@@ -34,7 +35,7 @@ export default function ChatFragment({
}) { }) {
const nav = useNavigate() const nav = useNavigate()
const [tabItemSelected, setTabItemSelected] = React.useState('None') const [tabItemSelected, setTabItemSelected] = React.useState('Chat')
const tabRef = React.useRef<Tab>() const tabRef = React.useRef<Tab>()
useEventListener(tabRef, 'change', () => { useEventListener(tabRef, 'change', () => {
tabRef.current != null && setTabItemSelected(tabRef.current!.value as string) tabRef.current != null && setTabItemSelected(tabRef.current!.value as string)
@@ -43,8 +44,6 @@ export default function ChatFragment({
const chatPanelRef = React.useRef<HTMLElement>() const chatPanelRef = React.useRef<HTMLElement>()
const inputRef = React.useRef<TextField>() const inputRef = React.useRef<TextField>()
return <div style={{ return <div style={{
width: '100%', width: '100%',
height: '100%', height: '100%',
@@ -73,40 +72,42 @@ export default function ChatFragment({
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
height: "100%", height: "100%",
width: '100%',
overflowX: 'auto', overflowX: 'auto',
}}></mdui-tabs>{ }}>
chatInfo.isMember() ? <> {
<MduiTabFitSize value="Chat">{chatInfo.getTitle()}</MduiTabFitSize> chatInfo.isMember() ? <>
{chatInfo.getType() == 'group' && chatInfo.isAdmin() && <MduiTabFitSize value="NewMemberRequests"></MduiTabFitSize>} <MduiTabFitSize value="Chat">{chatInfo.getTitle()}</MduiTabFitSize>
{chatInfo.getType() == 'group' && <MduiTabFitSize value="GroupMembers"></MduiTabFitSize>} {chatInfo.getType() == 'group' && chatInfo.isAdmin() && <MduiTabFitSize value="NewMemberRequests"></MduiTabFitSize>}
</> {chatInfo.getType() == 'group' && <MduiTabFitSize value="GroupMembers"></MduiTabFitSize>}
: <MduiTabFitSize value="RequestJoin">{chatInfo.getTitle()}</MduiTabFitSize> </>
} : <MduiTabFitSize value="RequestJoin">{chatInfo.getTitle()}</MduiTabFitSize>
{chatInfo.getType() == 'group' && <MduiTabFitSize value="Settings"></MduiTabFitSize>} }
<MduiTabFitSize value="None" style={{ display: 'none' }}></MduiTabFitSize> {chatInfo.getType() == 'group' && <MduiTabFitSize value="Settings"></MduiTabFitSize>}
<div style={{ <div style={{
flexGrow: '1', flexGrow: '1',
}}></div> }}></div>
<mdui-button-icon icon="open_in_new" onClick={() => { <mdui-button-icon icon="open_in_new" onClick={() => {
window.open('/chat?id=' + chatInfo.getId(), '_blank') window.open('/chat?id=' + chatInfo.getId(), '_blank')
}} style={{ }} style={{
alignSelf: 'center', alignSelf: 'center',
marginLeft: '5px', marginLeft: '5px',
marginRight: '5px', marginRight: '5px',
}}></mdui-button-icon> }}></mdui-button-icon>
<mdui-button-icon icon="refresh" onClick={() => { <mdui-button-icon icon="refresh" onClick={() => {
}} style={{ }} style={{
alignSelf: 'center', alignSelf: 'center',
marginLeft: '5px', marginLeft: '5px',
marginRight: '5px', marginRight: '5px',
}}></mdui-button-icon> }}></mdui-button-icon>
<mdui-button-icon icon="info" onClick={() => gotoChatInfo(nav, chatInfo.getId())} style={{ <mdui-button-icon icon="info" onClick={() => gotoChatInfo(nav, chatInfo.getId())} style={{
alignSelf: 'center', alignSelf: 'center',
marginLeft: '5px', marginLeft: '5px',
marginRight: '5px', marginRight: '5px',
}}></mdui-button-icon> }}></mdui-button-icon>
</mdui-tabs>
</mdui-tabs> </mdui-tabs>
<mdui-tab-panel slot="panel" value="RequestJoin" style={{ <mdui-tab-panel slot="panel" value="RequestJoin" style={{
display: tabItemSelected == "RequestJoin" ? "flex" : "none", display: tabItemSelected == "RequestJoin" ? "flex" : "none",
@@ -136,17 +137,7 @@ export default function ChatFragment({
}}> }}>
{/* 这里显示一些提示 */} {/* 这里显示一些提示 */}
</div> </div>
<div style={{ <ChatMessageContainer chatInfo={chatInfo} />
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
alignItems: 'center',
marginBottom: '20px',
paddingTop: "15px",
flexGrow: '1',
}}>
{/* 消息放在这里 */}
</div>
{ {
// 输入框 // 输入框
} }
@@ -301,20 +292,5 @@ export default function ChatFragment({
) )
} }
</mdui-tab-panel> </mdui-tab-panel>
<mdui-tab-panel slot="panel" value="None" style={{
display: tabItemSelected == "None" ? "flex" : "none",
flexDirection: "column",
height: "100%",
}}>
<div style={{
display: 'flex',
width: '100%',
height: '100%',
alignItems: "center",
justifyContent: "center",
}}>
<mdui-circular-progress></mdui-circular-progress>
</div>
</mdui-tab-panel>
</div > </div >
} }

View File

@@ -0,0 +1,24 @@
import { Chat, Message } from 'lingchair-client-protocol'
import * as React from 'react'
export default function ChatMessageContainer({
chatInfo,
}: {
chatInfo: Chat
}) {
const [messages, setMessages] = React.useState<Message[]>()
return (
<div style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
alignItems: 'center',
marginBottom: '20px',
paddingTop: "15px",
flexGrow: '1',
}}>
{messages?.map((v) => v.getText())}
</div>
)
}

View File

@@ -9,7 +9,8 @@ import EffectOnly from "../EffectOnly"
export default function LazyChatFragment({ chatId, openedWithRouter }: { chatId: string, openedWithRouter: boolean }) { export default function LazyChatFragment({ chatId, openedWithRouter }: { chatId: string, openedWithRouter: boolean }) {
return <React.Suspense fallback={<EffectOnly effect={() => { return <React.Suspense fallback={<EffectOnly effect={() => {
const s = showSnackbar({ const s = showSnackbar({
message: '请稍后', message: '请稍后...',
autoCloseDelay: 0,
}) })
return () => { return () => {
s.open = false s.open = false