Fixed typing issues.

This commit is contained in:
Martin Edenhofer 2015-11-25 15:08:55 +01:00
parent 526a1eed81
commit 6dbb5cb078
2 changed files with 13 additions and 18 deletions

View file

@ -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

View file

@ -209,24 +209,16 @@ 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 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
onTypingEnd: =>
@isTyping = false
onSubmit: (event) =>
event.preventDefault()
@sendMessage()
@ -256,8 +248,6 @@ do($ = window.jQuery, window) ->
@input.val('')
@scrollToBottom()
@isTyping = false
# send message event
@send 'chat_session_message',
content: message