2015-11-11 13:10:26 +00:00
|
|
|
class Sessions::Event::ChatAgentState < Sessions::Event::ChatBase
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
def run
|
2015-12-09 13:09:37 +00:00
|
|
|
return super if super
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-25 09:33:39 +00:00
|
|
|
# check if user has permissions
|
2016-08-12 16:39:09 +00:00
|
|
|
return if !permission_check('chat.agent', 'chat')
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2019-11-12 16:06:42 +00:00
|
|
|
chat_user = User.lookup(id: @session['id'])
|
|
|
|
|
2015-12-09 13:09:37 +00:00
|
|
|
Chat::Agent.state(@session['id'], @payload['data']['active'])
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2019-11-12 16:06:42 +00:00
|
|
|
chat_ids = Chat.agent_active_chat_ids(chat_user)
|
|
|
|
|
2015-11-15 10:01:48 +00:00
|
|
|
# broadcast new state to agents
|
2019-11-12 16:06:42 +00:00
|
|
|
Chat.broadcast_agent_state_update(chat_ids, @session['id'])
|
2015-11-15 10:01:48 +00:00
|
|
|
|
2015-11-10 14:01:04 +00:00
|
|
|
{
|
|
|
|
event: 'chat_agent_state',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
|
|
|
state: 'ok',
|
2015-12-09 13:09:37 +00:00
|
|
|
active: @payload['data']['active'],
|
2015-11-10 14:01:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2015-12-09 13:09:37 +00:00
|
|
|
|
2015-11-10 14:01:04 +00:00
|
|
|
end
|