Class: Doodle::ChatController

Inherits:
ApplicationController show all
Defined in:
app/controllers/doodle/chat_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#auth_params, #authenticate, #authenticate_user

Instance Method Details

#chat_join_service(protocol, user) ⇒ Object



51
52
53
# File 'app/controllers/doodle/chat_controller.rb', line 51

def chat_join_service(protocol, user)
  @chat_join_service ||= Chat::JoinService.new(user, protocol)
end

#finalizeObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/doodle/chat_controller.rb', line 33

def finalize
  protocol = protocol_finder_service.find_by_conversation(params.require(:conversation_id))

  if protocol.blank?
    render json: { text: "Protocol isn't found"}, status: 422
  else

    protocol_finalizer_service(protocol).call
    chat_join_service(protocol, protocol.user).out(protocol.channel.name) if params.require(:login)

    render json: { id: protocol.id, text: "Protocol finalized with success" }
  end
end

#has_protocols?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
# File 'app/controllers/doodle/chat_controller.rb', line 7

def has_protocols?
  protocols = protocol_finder_service.waiting_on_user_channels(@user)

  render json: { has_protocols: protocols.count }, status: 200
end

#nextObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/doodle/chat_controller.rb', line 13

def next
  if @user.blank?
    render json: { error: 'Dont found this analyst' }
  else
    protocol = protocol_finder_service.next_for_user(@user)

    if protocol.blank?
      render json: { error: 'Dont found protocols for this channel' }
    else
      join_service = chat_join_service(protocol, @user)
      if join_service.break_limit? && protocol.blank?
        render json: { error: 'Analyst already have limit of protocols in progress' }, status: 422
      else
        join_service.join(protocol.channel_id)
        render json: { conversation: protocol.conversation_id }, status: 200
      end
    end
  end
end

#protocol_finalizer_service(protocol) ⇒ Object



47
48
49
# File 'app/controllers/doodle/chat_controller.rb', line 47

def protocol_finalizer_service(protocol)
  @protcol_finalizer_service ||= Protocol::FinalizerService.new(protocol)
end

#protocol_finder_serviceObject



55
56
57
# File 'app/controllers/doodle/chat_controller.rb', line 55

def protocol_finder_service
  @finder_service ||= Protocol::FinderService.new
end