Broadcast agent state update after closing or adding a chat session.

This commit is contained in:
Martin Edenhofer 2015-11-12 23:56:56 +01:00
parent e2d7821e1f
commit 87712a5b34
3 changed files with 27 additions and 2 deletions

View file

@ -23,4 +23,16 @@ class Sessions::Event::ChatBase
false
end
def broadcast_agent_state_update
# send broadcast to agents
Chat::Agent.where(active: true).each {|item|
data = {
event: 'chat_status_agent',
data: Chat.agent_state(item.updated_by_id),
}
Sessions.send_to(item.updated_by_id, data)
}
end
end

View file

@ -26,8 +26,14 @@ class Sessions::Event::ChatSessionClose < Sessions::Event::ChatBase
realname = User.find(@session['id']).fullname
end
# notify about "leaving"
if @session && chat_session.user_id == @session['id']
# check count of participents
participents_count = 0
if chat_session.preferences[:participents]
participents_count = chat_session.preferences[:participents].count
end
# notify about "closing"
if participents_count < 2 || (@session && chat_session.user_id == @session['id'])
message = {
event: 'chat_session_closed',
data: {
@ -39,6 +45,11 @@ class Sessions::Event::ChatSessionClose < Sessions::Event::ChatBase
# close session if host is closing it
chat_session.state = 'closed'
chat_session.save
# set state update to all agents
broadcast_agent_state_update
# notify about "leaving"
else
message = {
event: 'chat_session_left',

View file

@ -53,6 +53,8 @@ class Sessions::Event::ChatSessionStart < Sessions::Event::ChatBase
local_chat_session.send_to_recipients(data)
}
broadcast_agent_state_update
nil
end
end