From a406f962ea94ec447c327648e2eb82b146efc41f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 6 Jan 2016 14:25:53 +0100 Subject: [PATCH] Improved chat state update. --- .../javascripts/app/controllers/chat.coffee | 23 +++++++++++++++---- app/models/chat.rb | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index 0c63ae240..af460d8ea 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -38,7 +38,7 @@ class App.CustomerChat extends App.Controller App.Collection.loadAssets(data.assets) @meta = data @updateMeta() - if @pushStateIntervalOn is undefined + if data.active is true @startPushState() ) @@ -213,7 +213,14 @@ class App.CustomerChat extends App.Controller msg = 'To be able to chat you need to select min. one chat topic below!' # open modal settings - @settings(settings: msg) + @settings( + errors: + settings: msg + active: @meta.active + ) + + @meta.active = false + @pushState() else @stopPushState() @pushState() @@ -277,10 +284,11 @@ class App.CustomerChat extends App.Controller App.WebSocket.send(event:'chat_session_start') @idleTimeoutStop() - settings: (errors = {}) -> + settings: (params = {}) -> new Setting( windowSpace: @ - errors: errors + errors: params.errors + active: params.active ) idleTimeoutStart: => @@ -646,7 +654,7 @@ class Setting extends App.ControllerModal App.view('customer_chat/setting')( chats: App.Chat.all() preferences: preferences - errors: @errors + errors: @errors || {} ) submit: (e) => @@ -670,6 +678,11 @@ class Setting extends App.ControllerModal ) success: (data, status, xhr) => + if @active is true || @active is false + @windowSpace.meta.active = @active + @windowSpace.pushState() + else + App.WebSocket.send(event:'chat_status_agent') App.User.full( App.Session.get('id'), => diff --git a/app/models/chat.rb b/app/models/chat.rb index a061db3a7..5a117aa44 100644 --- a/app/models/chat.rb +++ b/app/models/chat.rb @@ -178,7 +178,7 @@ optional you can ignore it for dedecated user def self.broadcast_agent_state_update(ignore_user_id = nil) # send broadcast to agents - Chat::Agent.where('active = ? OR updated_at > ?', true, Time.zone.now - 15.minutes).each {|item| + Chat::Agent.where('active = ? OR updated_at > ?', true, Time.zone.now - 8.hours).each {|item| next if item.updated_by_id == ignore_user_id data = { event: 'chat_status_agent',