2015-11-11 13:10:26 +00:00
|
|
|
class Sessions::Event::ChatStatusAgent < Sessions::Event::ChatBase
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2019-11-21 07:47:05 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
a agent requests a the current state of all chat sessions
|
|
|
|
|
|
|
|
payload
|
|
|
|
|
|
|
|
{
|
|
|
|
event: 'chat_status_agent',
|
|
|
|
data: {},
|
|
|
|
}
|
|
|
|
|
|
|
|
return is sent as message back to peer
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# renew timestamps
|
2015-11-11 13:10:26 +00:00
|
|
|
state = Chat::Agent.state(@session['id'])
|
|
|
|
Chat::Agent.state(@session['id'], state)
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
# update recipients of existing sessions
|
2019-04-07 15:23:03 +00:00
|
|
|
Chat::Session.where(state: 'running', user_id: @session['id']).order(created_at: :asc).each do |chat_session|
|
2015-11-11 13:10:26 +00:00
|
|
|
chat_session.add_recipient(@client_id, true)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-11-10 14:01:04 +00:00
|
|
|
{
|
|
|
|
event: 'chat_status_agent',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: Chat.agent_state_with_sessions(@session['id']),
|
2015-11-10 14:01:04 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|