2015-11-11 13:10:26 +00:00
|
|
|
class Sessions::Event::ChatSessionClose < Sessions::Event::ChatBase
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
def run
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
if !@data['data'] || !@data['data']['session_id']
|
2015-11-10 14:01:04 +00:00
|
|
|
return {
|
|
|
|
event: 'chat_status_close',
|
|
|
|
data: {
|
|
|
|
state: 'Need session_id.',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
chat_session = Chat::Session.find_by(session_id: @data['data']['session_id'])
|
2015-11-10 14:01:04 +00:00
|
|
|
if !chat_session
|
|
|
|
return {
|
|
|
|
event: 'chat_status_close',
|
|
|
|
data: {
|
|
|
|
state: "No such session id #{data['data']['session_id']}",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
chat_session.state = 'closed'
|
|
|
|
chat_session.save
|
|
|
|
|
|
|
|
# return new session
|
|
|
|
{
|
|
|
|
event: 'chat_status_close',
|
|
|
|
data: {
|
|
|
|
state: 'ok',
|
|
|
|
session_id: chat_session.session_id,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|