summaryrefslogtreecommitdiff
path: root/users/app/controllers/v1/messages_controller.rb
blob: 90986e278422805ff6fbac9414df42b400783b95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module V1
  class MessagesController < ApplicationController

    skip_before_filter :verify_authenticity_token
    before_filter :require_token

    respond_to :json

    def index
      render json: (current_user ? current_user.messages : [] )
    end

    def update
      message = Message.find(params[:id])
      if (message and current_user)
        message.user_ids_to_show.delete(current_user.id)
        # is it necessary to keep track of what users have already seen it?
        message.user_ids_have_shown << current_user.id if !message.user_ids_have_shown.include?(current_user.id)
        # TODO: is it quicker to call uniq! after adding rather than check if it is already included?
        message.save
        render json: true
      else
        render json: false
      end
    end

  end
end