|
@@ -22,6 +22,7 @@ import { getChat } from '../../../../redux/chat/selector'
|
|
|
import { getScroll } from '../../../../redux/control/selector'
|
|
|
import { actionScroll } from '../../../../redux/control/action'
|
|
|
import { asyncGetMessagesById } from '../../../../redux/messages/operations'
|
|
|
+import { asyncGetChatById } from "../../../../redux/chat/operations";
|
|
|
import { seenChat } from "../../../../api-data";
|
|
|
import { timeStampFilter,prodBaseURL } from "../../../../helpers";
|
|
|
const debounce = require('lodash.debounce');
|
|
@@ -78,7 +79,7 @@ const ChatBar = () => {
|
|
|
const dispatch = useDispatch()
|
|
|
const messages = useSelector(getMessagesMemo)
|
|
|
const userNumber = useSelector(getNumber)
|
|
|
- const { companionId,total,seen } = useSelector(getChat)
|
|
|
+ const { companionId,total,seen,mute } = useSelector(getChat)
|
|
|
const scroll = useSelector(getScroll)
|
|
|
const [isArrow, setIsArrow] = useState<boolean>(false)
|
|
|
const [isNew, setIsNew] = useState<{new:number,mute:boolean}>({new:0,mute:false})
|
|
@@ -91,9 +92,10 @@ const ChatBar = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- const handleScroll = useCallback(({ target:{scrollHeight,scrollTop,clientHeight} }: any) => {
|
|
|
- const different = scrollHeight - Math.trunc(scrollTop)
|
|
|
- if (total !== seen&&clientHeight - different < 50) seenChat(companionId)
|
|
|
+ const handleScroll = useCallback(({ target:{scrollHeight,scrollTop,clientHeight}}: any) => {
|
|
|
+ const different = scrollHeight - Math.floor(scrollTop)
|
|
|
+ const reached = different - clientHeight
|
|
|
+ if (total !== seen&&reached < 10) seenChat(companionId)
|
|
|
setIsArrow(different === clientHeight ? false : true)
|
|
|
}, [total,seen, companionId])
|
|
|
|
|
@@ -104,24 +106,28 @@ const ChatBar = () => {
|
|
|
dispatch(asyncGetMessagesById(companionId, handleScrollTo))
|
|
|
dispatch(actionScroll(false))
|
|
|
}
|
|
|
- }, [dispatch,scroll, companionId])
|
|
|
-
|
|
|
+ }, [dispatch, scroll, companionId])
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
dispatch(asyncGetMessagesById(companionId, handleScrollTo))
|
|
|
const handleReset = () => {
|
|
|
+ dispatch(asyncGetChatById(companionId))
|
|
|
dispatch(asyncGetMessagesById(companionId, null))
|
|
|
- const arr: any = localStorage.getItem('isNew')
|
|
|
- if(arr) setIsNew(JSON.parse(arr))
|
|
|
}
|
|
|
const idInterval = setInterval(handleReset, 3000);
|
|
|
return () => clearInterval(idInterval);
|
|
|
}, [dispatch, companionId]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ setIsNew({ new:total-seen,mute})
|
|
|
+ }, [total,seen,mute]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- const scrollHeight = divRef.current.scrollHeight
|
|
|
- const clientHeight = divRef.current.clientHeight
|
|
|
- if(total !== seen&&scrollHeight === clientHeight) seenChat(companionId)
|
|
|
- }, [total,seen, companionId]);
|
|
|
+ if (divRef.current) {
|
|
|
+ const { scrollHeight, clientHeight } = divRef.current
|
|
|
+ if(total !== seen&&scrollHeight === clientHeight) seenChat(companionId)
|
|
|
+ }
|
|
|
+ }, [total,seen,companionId]);
|
|
|
|
|
|
return (
|
|
|
<div className={classes.container} >
|
|
@@ -234,7 +240,7 @@ const ChatBar = () => {
|
|
|
}) : <AlertInfo name='You do not have messages yet!' />}
|
|
|
</div>
|
|
|
</div>
|
|
|
- <SendMessage isArrow={isArrow} handleScrollTo={handleScrollTo}/>
|
|
|
+ <SendMessage isArrow={isArrow} />
|
|
|
</div>
|
|
|
);
|
|
|
}
|