trabajo-afectivo/lib/sessions/event/chat_status_agent.rb

24 lines
643 B
Ruby
Raw Normal View History

class Sessions::Event::ChatStatusAgent < Sessions::Event::ChatBase
2015-11-10 14:01:04 +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
return if !role_permission_check('Agent', 'chat')
2015-11-10 14:01:04 +00:00
# renew timestamps
state = Chat::Agent.state(@session['id'])
Chat::Agent.state(@session['id'], state)
2015-11-10 14:01:04 +00:00
# update recipients of existing sessions
2016-06-30 20:04:48 +00:00
Chat::Session.where(state: 'running', user_id: @session['id']).order('created_at ASC').each { |chat_session|
chat_session.add_recipient(@client_id, true)
}
2015-11-10 14:01:04 +00:00
{
event: 'chat_status_agent',
data: Chat.agent_state_with_sessions(@session['id']),
2015-11-10 14:01:04 +00:00
}
end
end