每10秒删除最后一项聊天记录
This commit is contained in:
parent
bbc57b5185
commit
58facc62ea
|
|
@ -1,18 +1,22 @@
|
|||
import styles from '@/page/Meeting/ChatSmallWindow/index.module.scss'
|
||||
import { Input } from 'antd';
|
||||
import { useEffect, useState } from "react";
|
||||
import { storage } from '@/utils';
|
||||
const ChatSmallWindow: React.FC = () => {
|
||||
const [inputValue, setInputValue] = useState<string>('')
|
||||
const [chatLists, setChatLists] = useState<any>([])
|
||||
const userInfo = JSON.parse(storage.getItem('user') as string)
|
||||
const channel = new BroadcastChannel('meeting_channel');
|
||||
useEffect(() => {
|
||||
let time: NodeJS.Timeout;
|
||||
time = setInterval(() => {
|
||||
setChatLists((res: any) => {
|
||||
return res.length ? res.slice(0, -1) : res
|
||||
})
|
||||
}, 10000)
|
||||
channel.onmessage = function (event) {
|
||||
const { type, chatList } = event.data;
|
||||
const { type, chatListIten } = event.data;
|
||||
switch (type) {
|
||||
case 'chatList':
|
||||
setChatLists(chatList.reverse())
|
||||
case 'chatListIten':
|
||||
setChatLists((newChatList: any) => [chatListIten, ...newChatList])
|
||||
setTimeout(() => {
|
||||
const chatSmallWindowView = document.getElementById('chatSmallWindowView') as HTMLElement;
|
||||
if (chatSmallWindowView) {
|
||||
|
|
@ -22,6 +26,9 @@ const ChatSmallWindow: React.FC = () => {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
clearTimeout(time)
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -509,6 +509,10 @@ const Meeting: React.FC = () => {
|
|||
setNoViewChatList(storageNoViewChatList)
|
||||
}
|
||||
setChatList((newChatList: any) => [...newChatList, item])
|
||||
channel.postMessage({
|
||||
type: 'chatListIten',
|
||||
chatListIten: item,
|
||||
});
|
||||
setStatusList((res: any) => {
|
||||
if (!res.userChatList) {
|
||||
api.open({
|
||||
|
|
@ -1673,12 +1677,17 @@ const Meeting: React.FC = () => {
|
|||
roomNum: state.channelId,
|
||||
msg: msg,
|
||||
})
|
||||
setChatList((newChatList: any) => [...newChatList, {
|
||||
let item = {
|
||||
uid: userInfo.uid,
|
||||
userName: userInfo.userName,
|
||||
message: msg,
|
||||
timestamp: +new Date()
|
||||
}])
|
||||
}
|
||||
setChatList((newChatList: any) => [...newChatList, item])
|
||||
channel.postMessage({
|
||||
type: 'chatListIten',
|
||||
chatListIten: item,
|
||||
});
|
||||
setTextMsg('');
|
||||
chatScrollBotton()
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue