|
@@ -14,8 +14,10 @@ import AlertInfo from '../../../reusableComponents/AlertInfo'
|
|
|
import DoneAllIcon from '@mui/icons-material/DoneAll';
|
|
|
import { firstLetter, slicedWord, timeStampEU,notification,playNotificationWithoutPermission } from '../../../../helpers'
|
|
|
import { getState } from '../../../../redux/chats/selector'
|
|
|
+import { getChatMemo } from '../../../../redux/chat/selector'
|
|
|
import { asyncGetChats } from '../../../../redux/chats/operations'
|
|
|
import { asyncStartChatById } from '../../../../redux/chat/operations'
|
|
|
+import { actionRemoveChat } from '../../../../redux/chat/action'
|
|
|
import { actionScroll } from '../../../../redux/control/action'
|
|
|
|
|
|
const StyledBadge = styled(Badge)(({ theme }) => ({
|
|
@@ -178,7 +180,8 @@ const ChatsList = () => {
|
|
|
const dispatch = useDispatch()
|
|
|
const ref = useRef<any>(null)
|
|
|
const [selectedIndex, setSelectedIndex] = useState<number>(1);
|
|
|
- const { total, chats , lastMessages,lastOnline } = useSelector(getState)
|
|
|
+ const { total, chats, lastMessages, lastOnline } = useSelector(getState)
|
|
|
+ const chat = useSelector(getChatMemo)
|
|
|
|
|
|
const handleListItemClick = (i: number, companionId: string) => {
|
|
|
dispatch(asyncStartChatById(companionId))
|
|
@@ -204,11 +207,15 @@ const ChatsList = () => {
|
|
|
const handleNotification= (companionId: string) => {
|
|
|
dispatch(asyncStartChatById(companionId))
|
|
|
dispatch(actionScroll(true))
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (!chats.find((el) => el.companionId === chat.companionId)) {
|
|
|
+ dispatch(actionRemoveChat())
|
|
|
+ }
|
|
|
if (ref.current) {
|
|
|
- ref.current.forEach(({total,seen,_id}: any,i:number) => {
|
|
|
+ ref.current.forEach(({total,seen}: any,i:number) => {
|
|
|
const oldDifferent = total - seen
|
|
|
const chat = chats[i]
|
|
|
+ if(chat === undefined) return
|
|
|
const newDifferent = chat.total - chat.seen
|
|
|
if (newDifferent > oldDifferent && !chat.mute) {
|
|
|
playNotificationWithoutPermission('http://localhost:3000/recive.mp3')
|
|
@@ -217,7 +224,7 @@ const ChatsList = () => {
|
|
|
})
|
|
|
}
|
|
|
ref.current = chats
|
|
|
- }, [chats,dispatch])
|
|
|
+ }, [chats,chat,dispatch])
|
|
|
|
|
|
return total !== '0' ? (
|
|
|
<List className={classes.list} component="nav"
|