From 7f3ff9a4c9cd4d91e3a9f412b2ed28681a23eff9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 12 Nov 2015 23:58:35 +0100 Subject: [PATCH] Broadcast agent state update after closing or adding a chat session. --- app/models/chat.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/models/chat.rb b/app/models/chat.rb index 5c5f7ad2d..d730e2927 100644 --- a/app/models/chat.rb +++ b/app/models/chat.rb @@ -7,8 +7,9 @@ class Chat < ApplicationModel def customer_state(session_id = nil) return { state: 'chat_disabled' } if !Setting.get('chat') + # reconnect if session_id - chat_session = Chat::Session.find_by(session_id: session_id) + chat_session = Chat::Session.find_by(session_id: session_id, state: %w(waiting running)) user = nil if chat_session && chat_session.user_id chat_user = User.find(chat_session.user_id) @@ -22,13 +23,15 @@ class Chat < ApplicationModel } end - session = Chat.session_state(session_id) - if session - return { - state: 'reconnect', - session: session, - agent: user, - } + if chat_session + session = Chat.session_state(session_id) + if session && !session.empty? + return { + state: 'reconnect', + session: session, + agent: user, + } + end end end