Class: CustomerServiceIm::MessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/customer_service_im/messages_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_200, #render_401, #render_422, #render_500

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/customer_service_im/messages_controller.rb', line 11

def create
  @message = Message.new(message_params.merge( user: logged_user, receiver_type: "Staff" ))

  if @message.save

    render_200 message: @message
  else
    render_422 errors: @message.errors
  end
end

#indexObject



7
8
9
# File 'app/controllers/customer_service_im/messages_controller.rb', line 7

def index
  @messages = @conversation.messages.order("created_at desc")
end

#readObject



40
41
42
43
44
45
46
# File 'app/controllers/customer_service_im/messages_controller.rb', line 40

def read
  if @message.read!
    render_200 message: @message
  else
    render_422 errors: @message.errors
  end
end

#receiveObject



32
33
34
35
36
37
38
# File 'app/controllers/customer_service_im/messages_controller.rb', line 32

def receive
  if @message.received!
    render_200 message: @message
  else
    render_422 @message.errors
  end
end

#replyObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/customer_service_im/messages_controller.rb', line 22

def reply
  @message = Message.new(message_params.merge( staff: logged_user, receiver_type: "User" ))

  if @message.save
    render_200 message: @message
  else
    render_422 errors: @message.errors
  end
end