Class: CustomerServiceIm::ConversationsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_200, #render_401, #render_422, #render_500

Instance Method Details

#all_messages_readObject



36
37
38
39
# File 'app/controllers/customer_service_im/conversations_controller.rb', line 36

def all_messages_read
  @conversation.all_messages_read!
  head :no_content
end

#createObject



14
15
16
17
18
19
20
21
22
# File 'app/controllers/customer_service_im/conversations_controller.rb', line 14

def create
  @conversation = Conversation.new(user: logged_user)

  if @conversation.save
    render :show
  else
    render_500 errors: @conversation.errors
  end
end

#indexObject



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

def index
  @conversations = Conversation.order('last_messaged_on desc')
  @total_count = @conversations.size
end

#messagesObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/customer_service_im/conversations_controller.rb', line 24

def messages
  @messages = @conversation.messages
                           .order('created_at desc')
                           .id_less_then(params[:min_id])
                           .tap do |records|
                             @total_count = records.size
                           end
                           .page(params[:page] || 1)
                           .per(params[:per] || 8)
                           .reverse
end

#showObject



12
# File 'app/controllers/customer_service_im/conversations_controller.rb', line 12

def show; end