From 6dbb5cb0789dbf8b215538986c04e424c1ff89ff Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 25 Nov 2015 15:08:55 +0100 Subject: [PATCH] Fixed typing issues. --- .../javascripts/app/controllers/chat.coffee | 7 +++++- public/assets/chat/chat.coffee | 24 ++++++------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index ce2df2dc0..702908b3a 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -233,6 +233,7 @@ class ChatWindow extends App.Controller @lastTimestamp @lastAddedType @isTyping = false + @isAgentTyping = false @resetUnreadMessages() @on 'layout-change', @scrollToBottom @@ -319,6 +320,10 @@ class ChatWindow extends App.Controller ENTERKEY = 13 if event.keyCode isnt TABKEY && event.keyCode isnt ENTERKEY + + # send typing start event only every 1.4 seconds + return if @isAgentTyping && @isAgentTyping > new Date(new Date().getTime() - 1400) + @isAgentTyping = new Date() App.WebSocket.send( event:'chat_session_typing' data: @@ -413,7 +418,7 @@ class ChatWindow extends App.Controller @scrollToBottom() # clear old delay, set new - @delay(@removeWritingLoader, 1800, 'typing') + @delay(@removeWritingLoader, 2000, 'typing') removeWritingLoader: => @isTyping = false diff --git a/public/assets/chat/chat.coffee b/public/assets/chat/chat.coffee index a999c8968..cfe3df641 100644 --- a/public/assets/chat/chat.coffee +++ b/public/assets/chat/chat.coffee @@ -209,23 +209,15 @@ do($ = window.jQuery, window) -> sessionStorage.setItem 'unfinished_message', @input.val() - @onTypingStart() + @onTyping() - onTypingStart: -> + onTyping: -> - clearTimeout(@isTypingTimeout) if @isTypingTimeout - - # fire typingEnd after 5 seconds - @isTypingTimeout = setTimeout @onTypingEnd, 1500 - - # send typing start event - if !@isTyping - @isTyping = true - @send 'chat_session_typing', - session_id: @sessionId - - onTypingEnd: => - @isTyping = false + # send typing start event only every 1.5 seconds + return if @isTyping && @isTyping > new Date(new Date().getTime() - 1500) + @isTyping = new Date() + @send 'chat_session_typing', + session_id: @sessionId onSubmit: (event) => event.preventDefault() @@ -256,8 +248,6 @@ do($ = window.jQuery, window) -> @input.val('') @scrollToBottom() - @isTyping = false - # send message event @send 'chat_session_message', content: message