|
@@ -180,7 +180,7 @@ 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 } = useSelector(getState)
|
|
|
const chat = useSelector(getChatMemo)
|
|
|
|
|
|
const handleListItemClick = (i: number, companionId: string) => {
|
|
@@ -193,7 +193,6 @@ const ChatsList = () => {
|
|
|
e.stopPropagation()
|
|
|
dispatch(asyncStartChatById(companionId))
|
|
|
dispatch(actionScroll(true))
|
|
|
- console.log(i,'index','clicked read new messages')
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
@@ -208,7 +207,7 @@ const ChatsList = () => {
|
|
|
dispatch(asyncStartChatById(companionId))
|
|
|
dispatch(actionScroll(true))
|
|
|
}
|
|
|
- if (!chats.find((el) => el.companionId === chat.companionId)) {
|
|
|
+ if (chat.companionId&&!chats.find((el) => el.companionId === chat.companionId)) {
|
|
|
dispatch(actionRemoveChat())
|
|
|
}
|
|
|
if (ref.current) {
|
|
@@ -229,14 +228,15 @@ const ChatsList = () => {
|
|
|
return total !== '0' ? (
|
|
|
<List className={classes.list} component="nav"
|
|
|
aria-label="main mailbox folders">
|
|
|
- {chats.map(({name, lastName, avatarUrl, updatedAt, color,companionId,mute,seen,total,watched,typing,number }, i: number) =>
|
|
|
+ {chats.map(({ name, lastName, avatarUrl, updatedAt, color, companionId, mute, seen, total,
|
|
|
+ watched, typing, number, online, lastMessage }, i: number) =>
|
|
|
<ListItemButton
|
|
|
key={number}
|
|
|
selected={selectedIndex === i}
|
|
|
onClick={() => handleListItemClick(i,companionId)}
|
|
|
>
|
|
|
<ListItemIcon className={classes.listItem_iconAvatar}>
|
|
|
- <StyledBadge overlap="circular" variant={lastOnline[i].online === 'true'?'dot':'standard'}
|
|
|
+ <StyledBadge overlap="circular" variant={online === 'true'?'dot':'standard'}
|
|
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>
|
|
|
<Avatar alt={name} src={avatarUrl?`http://localhost:3000/${avatarUrl}`:undefined}
|
|
|
sx={{ background: color, width: 54, height: 54 }}>
|
|
@@ -250,16 +250,16 @@ const ChatsList = () => {
|
|
|
{mute&&<VolumeOffIcon className={classes.listItemInnerText__icon} fontSize='small' />}</div>}
|
|
|
secondary={typing ? <span className={classes.listItem_typing}>
|
|
|
typing<span className={classes.listItem_dots}>...</span></span> :
|
|
|
- lastMessages[i] ? slicedWord(lastMessages[i].message, 35) :
|
|
|
+ lastMessage ? slicedWord(lastMessage, 35) :
|
|
|
`${firstLetter(name)}${slicedWord(name, 8, 1)} joined Telegram`}/>
|
|
|
<ListItemIcon className={classes.listItem_iconRight}>
|
|
|
<div className={classes.listItem_iconTimeChecked}>
|
|
|
{watched&& <DoneAllIcon style={{ color: '#18bd03' }} fontSize='small' />}
|
|
|
<Typography className={classes.listItem_icon_time} variant="h6" color="initial">
|
|
|
- {lastMessages[i] ? timeStampEU(lastMessages[i].updatedAt) :
|
|
|
- timeStampEU(updatedAt)}</Typography>
|
|
|
+ {timeStampEU(updatedAt)}
|
|
|
+ </Typography>
|
|
|
</div>
|
|
|
- {lastMessages[i] && total > seen ? <button onClick={(e) => handleNewMsgs(e, i,companionId)}
|
|
|
+ {lastMessage && total > seen ? <button onClick={(e) => handleNewMsgs(e, i,companionId)}
|
|
|
className={mute?classes.listItem_iconRightBtnMute:classes.listItem_iconRightBtn}>{total-seen}</button> :
|
|
|
<button className={classes.listItem_iconRightBtnHidden}/>}
|
|
|
</ListItemIcon>
|