Just push state updated if chat is enabled.

This commit is contained in:
Martin Edenhofer 2015-12-11 16:28:31 +01:00
parent 6ad0245db6
commit 13d15b1f7d

View file

@ -17,7 +17,7 @@ class App.CustomerChat extends App.Controller
if preferences && preferences.chat && preferences.chat.max_windows if preferences && preferences.chat && preferences.chat.max_windows
@maxChatWindows = parseInt(preferences.chat.max_windows) @maxChatWindows = parseInt(preferences.chat.max_windows)
@pushStateStarted = false @pushStateIntervalOn = undefined
@messageCounter = 0 @messageCounter = 0
@meta = @meta =
active: false active: false
@ -34,9 +34,8 @@ class App.CustomerChat extends App.Controller
App.Collection.loadAssets(data.assets) App.Collection.loadAssets(data.assets)
@meta = data @meta = data
@updateMeta() @updateMeta()
if !@pushStateStarted if @pushStateIntervalOn is undefined
@pushStateStarted = true @startPushState()
@interval(@pushState, 30000, 'pushState')
) )
# add new chat window # add new chat window
@ -61,6 +60,15 @@ class App.CustomerChat extends App.Controller
App.WebSocket.send(event:'chat_status_agent') App.WebSocket.send(event:'chat_status_agent')
) )
startPushState: =>
return if @pushStateIntervalOn
@pushStateIntervalOn = true
@interval(@pushState, 55000, 'pushState')
stopPushState: =>
@pushStateIntervalOn = false
@clearInterval('pushState')
pushState: => pushState: =>
App.WebSocket.send( App.WebSocket.send(
event:'chat_agent_state' event:'chat_agent_state'
@ -113,23 +121,20 @@ class App.CustomerChat extends App.Controller
if state is undefined if state is undefined
return @meta.active return @meta.active
@meta.active = state
# check if min one chat is active # check if min one chat is active
if state if state
@startPushState()
preferences = @Session.get('preferences') preferences = @Session.get('preferences')
if !preferences || !preferences.chat || !preferences.chat.active || _.isEmpty(preferences.chat.active) if !preferences || !preferences.chat || !preferences.chat.active || _.isEmpty(preferences.chat.active)
@notify( @notify(
type: 'error' type: 'error'
msg: App.i18n.translateContent('To be able to chat you need to select min. one chat topic in settings!') msg: App.i18n.translateContent('To be able to chat you need to select min. one chat topic in settings!')
) )
else
@meta.active = state @stopPushState()
@pushState()
# write state
App.WebSocket.send(
event:'chat_agent_state'
data:
active: @meta.active
)
updateNavMenu: => updateNavMenu: =>
delay = -> delay = ->
@ -498,9 +503,10 @@ class ChatWindow extends App.Controller
label: label label: label
time: time time: time
addStatusMessage: (message) -> addStatusMessage: (message, args) ->
@body.append App.view('customer_chat/chat_status_message') @body.append App.view('customer_chat/chat_status_message')
message: message message: message
args: args
@scrollToBottom() @scrollToBottom()