mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: reduce socket.emits for typing
if textarea changess between empty/full emit right away
This commit is contained in:
@@ -331,9 +331,22 @@ define('forum/chats', [
|
|||||||
|
|
||||||
textarea.on('focus', () => textarea.val() && emitTyping(true));
|
textarea.on('focus', () => textarea.val() && emitTyping(true));
|
||||||
textarea.on('blur', () => emitTyping(false));
|
textarea.on('blur', () => emitTyping(false));
|
||||||
textarea.on('input', utils.throttle(function () {
|
let timeoutid = 0;
|
||||||
|
let hasText = !!textarea.val();
|
||||||
|
textarea.on('input', function () {
|
||||||
|
const _hasText = !!textarea.val();
|
||||||
|
if (_hasText !== hasText) {
|
||||||
|
clearTimeout(timeoutid);
|
||||||
|
timeoutid = 0;
|
||||||
|
hasText = _hasText;
|
||||||
|
emitTyping(hasText);
|
||||||
|
} else if (!timeoutid) {
|
||||||
|
timeoutid = setTimeout(() => {
|
||||||
emitTyping(!!textarea.val());
|
emitTyping(!!textarea.val());
|
||||||
}, 2500, true));
|
timeoutid = 0;
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Chats.addActionHandlers = function (element, roomId) {
|
Chats.addActionHandlers = function (element, roomId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user