forked from Ivasoft/mattermost-mobile
Fix typing (#6243)
* Fix typing * Do not consider if it is shown to avoid race conditions Co-authored-by: Daniel Espino <danielespino@MacBook-Pro-de-Daniel.local>
This commit is contained in:
committed by
GitHub
parent
414a8e91e0
commit
e6aaa586ad
@@ -47,6 +47,7 @@ function Typing({
|
||||
}: Props) {
|
||||
const typingHeight = useSharedValue(0);
|
||||
const typing = useRef<Array<{id: string; now: number; username: string}>>([]);
|
||||
const timeoutToDisappear = useRef<NodeJS.Timeout>();
|
||||
const [refresh, setRefresh] = useState(0);
|
||||
|
||||
const theme = useTheme();
|
||||
@@ -71,6 +72,10 @@ function Typing({
|
||||
|
||||
typing.current = typing.current.filter(({id}) => id !== msg.userId);
|
||||
typing.current.push({id: msg.userId, now: msg.now, username: msg.username});
|
||||
if (timeoutToDisappear.current) {
|
||||
clearTimeout(timeoutToDisappear.current);
|
||||
timeoutToDisappear.current = undefined;
|
||||
}
|
||||
setRefresh(Date.now());
|
||||
}, [channelId, rootId]);
|
||||
|
||||
@@ -85,7 +90,20 @@ function Typing({
|
||||
}
|
||||
|
||||
typing.current = typing.current.filter(({id, now}) => id !== msg.userId && now !== msg.now);
|
||||
setRefresh(Date.now());
|
||||
|
||||
if (timeoutToDisappear.current) {
|
||||
clearTimeout(timeoutToDisappear.current);
|
||||
timeoutToDisappear.current = undefined;
|
||||
}
|
||||
|
||||
if (typing.current.length === 0) {
|
||||
timeoutToDisappear.current = setTimeout(() => {
|
||||
setRefresh(Date.now());
|
||||
timeoutToDisappear.current = undefined;
|
||||
}, 500);
|
||||
} else {
|
||||
setRefresh(Date.now());
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user