2015-11-11 13:10:26 +00:00
|
|
|
class Sessions::Event::ChatSessionTyping < 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_session_typing',
|
|
|
|
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_session_typing',
|
|
|
|
data: {
|
2015-11-12 15:16:01 +00:00
|
|
|
state: "No such session id #{@data['data']['session_id']}",
|
2015-11-10 14:01:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
user_id = nil
|
2015-11-11 13:10:26 +00:00
|
|
|
if @session
|
|
|
|
user_id = @session['id']
|
2015-11-10 14:01:04 +00:00
|
|
|
end
|
|
|
|
message = {
|
|
|
|
event: 'chat_session_typing',
|
|
|
|
data: {
|
|
|
|
session_id: chat_session.session_id,
|
|
|
|
user_id: user_id,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
# send to participents
|
2015-11-11 13:10:26 +00:00
|
|
|
chat_session.send_to_recipients(message, @client_id)
|
2015-11-10 14:01:04 +00:00
|
|
|
|
|
|
|
# send chat_session_init to agent
|
|
|
|
{
|
|
|
|
event: 'chat_session_typing',
|
|
|
|
data: {
|
|
|
|
session_id: chat_session.session_id,
|
|
|
|
self_written: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|