11import { CloseCircleFilled , CloseOutlined } from "@ant-design/icons" ;
22import { Button , Layout , message } from "antd" ;
3- import { FC , forwardRef , ForwardRefRenderFunction , memo , useEffect , useImperativeHandle , useRef , useState } from "react" ;
3+ import { FC , forwardRef , ForwardRefRenderFunction , memo , useEffect , useRef , useState } from "react" ;
44import { base64toFile , contenteditableDivRange , cosUploadNomal , events , im , isSingleCve , move2end } from "../../../../utils" ;
55import { ATSTATEUPDATE , FORWARDANDMERMSG , ISSETDRAFT , MUTILMSG , MUTILMSGCHANGE , REPLAYMSG } from "../../../../constants/events" ;
66import CardMsgModal from "../components/CardMsgModal" ;
@@ -46,9 +46,8 @@ const CveFooter: ForwardRefRenderFunction<any, CveFooterProps> = ({ sendMsg, cur
4646 const appConfig = useSelector ( ( state : RootState ) => state . user . appConfig , shallowEqual ) ;
4747 const { t, i18n } = useTranslation ( ) ;
4848 const suffixRef = useRef < any > ( null ) ;
49- const watingTimer = useRef < NodeJS . Timeout > ( ) ;
5049
51- const [ watingFlag , setWatingFlag ] = useState ( false ) ;
50+ const latestCurcve = useLatest ( curCve ) ;
5251
5352 useEffect ( ( ) => {
5453 events . on ( REPLAYMSG , replyHandler ) ;
@@ -87,29 +86,26 @@ const CveFooter: ForwardRefRenderFunction<any, CveFooterProps> = ({ sendMsg, cur
8786 setMsgContent ( "" ) ;
8887 }
8988 setMutilMsg ( [ ] ) ;
90- robotCheck ( ) ;
9189 return ( ) => {
9290 setDraft ( curCve ) ;
9391 } ;
94- } , [ curCve . conversationID , curCve . draftText , appConfig . robots ] ) ;
92+ } , [ curCve . conversationID , curCve . draftText ] ) ;
9593
96- const robotCheck = ( ) => {
94+ const robotWaitCheck = ( ) => {
9795 let message : MessageItem | undefined = undefined ;
9896 try {
99- message = JSON . parse ( curCve . latestMsg ) ;
97+ message = JSON . parse ( latestCurcve . current . latestMsg ) ;
10098 } catch ( error ) { }
10199 if ( ! message || TipsType . includes ( message . contentType ) ) {
102- updateWatingFlag ( false )
103- return ;
100+ return false ;
104101 }
105-
106102 const isRobotMsg = appConfig . robots . includes ( message . sendID ) ;
107103 const gapTime = Date . now ( ) - message . sendTime ;
108104 const isTimeout = gapTime >= 60000 ;
109105 if ( ! isRobotMsg && ! isTimeout ) {
110- setWatingCounter ( 60000 - gapTime ) ;
106+ return true ;
111107 } else {
112- updateWatingFlag ( false )
108+ return false ;
113109 }
114110 } ;
115111
@@ -397,6 +393,11 @@ const CveFooter: ForwardRefRenderFunction<any, CveFooterProps> = ({ sendMsg, cur
397393 }
398394 if ( e . key === "Enter" && ! e . ctrlKey ) {
399395 e . preventDefault ( ) ;
396+
397+ if ( robotWaitCheck ( ) ) {
398+ message . info ( "等待回复中..." ) ;
399+ return ;
400+ }
400401 if ( latestContent . current && ! latestFlag . current ) {
401402 setFlag ( true ) ;
402403 switchMessage ( replyMsg ? "quote" : atList . length > 0 ? "at" : "text" ) ;
@@ -468,24 +469,6 @@ const CveFooter: ForwardRefRenderFunction<any, CveFooterProps> = ({ sendMsg, cur
468469 typing ( ) ;
469470 } ;
470471
471- const setWatingCounter = ( timeGap = 60000 ) => {
472- if ( watingTimer . current ) {
473- clearTimeout ( watingTimer . current ) ;
474- }
475- setWatingFlag ( true ) ;
476- watingTimer . current = setTimeout ( ( ) => {
477- setWatingFlag ( false ) ;
478- } , timeGap ) ;
479- } ;
480-
481- const updateWatingFlag = ( flag : boolean ) => {
482- if ( flag !== watingFlag ) {
483- setWatingFlag ( flag ) ;
484- }
485- } ;
486-
487- useImperativeHandle ( ref , ( ) => ( { setWatingCounter, updateWatingFlag } ) ) ;
488-
489472 return (
490473 < Footer className = "chat_footer" >
491474 { mutilSelect ? (
@@ -495,8 +478,7 @@ const CveFooter: ForwardRefRenderFunction<any, CveFooterProps> = ({ sendMsg, cur
495478 < ContentEditable
496479 className = "input_div"
497480 style = { { paddingTop : replyMsg ? "32px" : "4px" } }
498- placeholder = { ! watingFlag ? `${ t ( "SendTo" ) } ${ curCve . showName } ` : "等待回复..." }
499- disabled = { watingFlag }
481+ placeholder = { `${ t ( "SendTo" ) } ${ curCve . showName } ` }
500482 ref = { inputRef }
501483 html = { msgContent }
502484 onChange = { onChange }
@@ -512,4 +494,4 @@ const CveFooter: ForwardRefRenderFunction<any, CveFooterProps> = ({ sendMsg, cur
512494 ) ;
513495} ;
514496
515- export default memo ( forwardRef ( CveFooter ) , ( p , n ) => p . curCve . conversationID === n . curCve . conversationID && p . curCve . showName === n . curCve . showName ) ;
497+ export default memo ( forwardRef ( CveFooter ) , ( p , n ) => p . curCve . conversationID === n . curCve . conversationID && p . curCve . showName === n . curCve . showName && p . curCve . latestMsg === n . curCve . latestMsg ) ;
0 commit comments