Broadcast agent state update after closing or adding a chat session.
This commit is contained in:
parent
87712a5b34
commit
7f3ff9a4c9
1 changed files with 11 additions and 8 deletions
|
@ -7,8 +7,9 @@ class Chat < ApplicationModel
|
||||||
def customer_state(session_id = nil)
|
def customer_state(session_id = nil)
|
||||||
return { state: 'chat_disabled' } if !Setting.get('chat')
|
return { state: 'chat_disabled' } if !Setting.get('chat')
|
||||||
|
|
||||||
|
# reconnect
|
||||||
if session_id
|
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
|
user = nil
|
||||||
if chat_session && chat_session.user_id
|
if chat_session && chat_session.user_id
|
||||||
chat_user = User.find(chat_session.user_id)
|
chat_user = User.find(chat_session.user_id)
|
||||||
|
@ -22,8 +23,9 @@ class Chat < ApplicationModel
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if chat_session
|
||||||
session = Chat.session_state(session_id)
|
session = Chat.session_state(session_id)
|
||||||
if session
|
if session && !session.empty?
|
||||||
return {
|
return {
|
||||||
state: 'reconnect',
|
state: 'reconnect',
|
||||||
session: session,
|
session: session,
|
||||||
|
@ -31,6 +33,7 @@ class Chat < ApplicationModel
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - 2.minutes).count > 0
|
if Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - 2.minutes).count > 0
|
||||||
if active_chat_count >= max_queue
|
if active_chat_count >= max_queue
|
||||||
|
|
Loading…
Reference in a new issue