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

30 lines
615 B
Ruby
Raw Normal View History

class Sessions::Event::ChatSessionInit < Sessions::Event::ChatBase
2015-11-10 14:01:04 +00:00
def run
return if !check_chat_exists
2015-11-10 14:01:04 +00:00
# create chat session
chat_session = Chat::Session.create(
chat_id: @data['data']['chat_id'],
2015-11-10 14:01:04 +00:00
name: '',
state: 'waiting',
preferences: {
participants: [@client_id],
2015-11-10 14:01:04 +00:00
},
)
# send broadcast to agents
2015-11-13 14:15:44 +00:00
broadcast_agent_state_update
2015-11-10 14:01:04 +00:00
# return new session
{
event: 'chat_session_queue',
2015-11-10 14:01:04 +00:00
data: {
state: 'queue',
position: Chat.waiting_chat_count,
session_id: chat_session.session_id,
},
}
end
end