Improved chat performance. Also show geo data in title.

This commit is contained in:
Martin Edenhofer 2016-01-05 14:47:41 +01:00
parent 037b4ffbd3
commit 325a100a46
5 changed files with 54 additions and 22 deletions

View file

@ -265,6 +265,11 @@ class ChatWindow extends App.Controller
chat = App.Chat.find(@session.chat_id)
@name = "#{chat.displayName()} [##{@session.id}]"
if @session && @session.preferences && @session.preferences.geo_ip
if @session.preferences.geo_ip.country_name
@name += " #{@session.preferences.geo_ip.country_name}"
if @session.preferences.geo_ip.city_name
@name += " #{@session.preferences.geo_ip.city_name}"
@on 'layout-change', @scrollToBottom

View file

@ -63,6 +63,23 @@ class Chat < ApplicationModel
end
def self.agent_state(user_id)
return { state: 'chat_disabled' } if !Setting.get('chat')
assets = {}
Chat.where(active: true).each {|chat|
assets = chat.assets(assets)
}
{
waiting_chat_count: waiting_chat_count,
running_chat_count: running_chat_count,
active_agents: active_agents,
seads_available: seads_available,
seads_total: seads_total,
active: Chat::Agent.state(user_id),
assets: assets,
}
end
def self.agent_state_with_sessions(user_id)
return { state: 'chat_disabled' } if !Setting.get('chat')
assets = {}
Chat.where(active: true).each {|chat|

View file

@ -39,14 +39,24 @@ class Sessions::Event::ChatSessionStart < Sessions::Event::ChatBase
chat_id: chat_session.chat_id,
},
}
chat_session.send_to_recipients(data)
# send to customer
chat_session.send_to_recipients(data, @client_id)
# send to agent
data = {
event: 'chat_session_start',
data: {
session: chat_session.attributes,
},
}
Sessions.send(@client_id, data)
# send state update with sessions to agents
broadcast_agent_state_update
# send position update to other waiting sessions
broadcast_customer_state_update
# send state update to agents
broadcast_agent_state_update
nil
end

View file

@ -16,7 +16,7 @@ class Sessions::Event::ChatStatusAgent < Sessions::Event::ChatBase
}
{
event: 'chat_status_agent',
data: Chat.agent_state(@session['id']),
data: Chat.agent_state_with_sessions(@session['id']),
}
end

View file

@ -58,7 +58,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal('offline', chat.customer_state[:state])
# check agent state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(0, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -78,7 +78,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal('online', chat.customer_state[:state])
# check agent state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(0, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -97,7 +97,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal('online', chat.customer_state[:state])
# check agent state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(1, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -117,7 +117,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal('online', chat.customer_state[:state])
# check agent1 state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(1, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -126,7 +126,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(true, agent_state[:active])
# check agent2 state
agent_state = Chat.agent_state(agent2.id)
agent_state = Chat.agent_state_with_sessions(agent2.id)
assert_equal(1, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -143,7 +143,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal('online', chat.customer_state[:state])
# check agent1 state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(2, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -152,7 +152,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(true, agent_state[:active])
# check agent2 state
agent_state = Chat.agent_state(agent2.id)
agent_state = Chat.agent_state_with_sessions(agent2.id)
assert_equal(2, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -178,7 +178,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal('no_seats_available', chat.customer_state[:state])
# check agent1 state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(6, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -187,7 +187,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(true, agent_state[:active])
# check agent2 state
agent_state = Chat.agent_state(agent2.id)
agent_state = Chat.agent_state_with_sessions(agent2.id)
assert_equal(6, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -203,7 +203,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(5, chat.customer_state[:queue])
# check agent1 state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(5, agent_state[:waiting_chat_count])
assert_equal(1, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -212,7 +212,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(true, agent_state[:active])
# check agent2 state
agent_state = Chat.agent_state(agent2.id)
agent_state = Chat.agent_state_with_sessions(agent2.id)
assert_equal(5, agent_state[:waiting_chat_count])
assert_equal(1, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -228,7 +228,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(5, chat.customer_state[:queue])
# check agent1 state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(5, agent_state[:waiting_chat_count])
assert_equal(1, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -237,7 +237,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(true, agent_state[:active])
# check agent2 state
agent_state = Chat.agent_state(agent2.id)
agent_state = Chat.agent_state_with_sessions(agent2.id)
assert_equal(5, agent_state[:waiting_chat_count])
assert_equal(1, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -253,7 +253,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(5, chat.customer_state[:queue])
# check agent1 state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(5, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -262,7 +262,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(true, agent_state[:active])
# check agent2 state
agent_state = Chat.agent_state(agent2.id)
agent_state = Chat.agent_state_with_sessions(agent2.id)
assert_equal(5, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -277,7 +277,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal('online', chat.customer_state[:state])
# check agent1 state
agent_state = Chat.agent_state(agent1.id)
agent_state = Chat.agent_state_with_sessions(agent1.id)
assert_equal(3, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])
@ -286,7 +286,7 @@ class ChatTest < ActiveSupport::TestCase
assert_equal(true, agent_state[:active])
# check agent2 state
agent_state = Chat.agent_state(agent2.id)
agent_state = Chat.agent_state_with_sessions(agent2.id)
assert_equal(3, agent_state[:waiting_chat_count])
assert_equal(0, agent_state[:running_chat_count])
assert_equal([], agent_state[:active_sessions])