summaryrefslogtreecommitdiff
path: root/users/app/controllers/v1
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2014-02-10 12:44:08 +0100
committerazul <azul@riseup.net>2014-02-10 12:44:08 +0100
commitbcdde2f6bfb4ed3a1535bd2e50ab47529a9141e2 (patch)
tree6748d5170cb2a3ed387f2bf8f26bacbbc46df7d1 /users/app/controllers/v1
parent38474e94e3bfaeb40fb87bf2a9b8b1fbe546bc05 (diff)
parent7e0573f3347dca6323eae05127849431ecbceb77 (diff)
Merge pull request #134 from jessib/feature/messages_api
Feature/messages api
Diffstat (limited to 'users/app/controllers/v1')
-rw-r--r--users/app/controllers/v1/messages_controller.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb
new file mode 100644
index 0000000..1b994ca
--- /dev/null
+++ b/users/app/controllers/v1/messages_controller.rb
@@ -0,0 +1,28 @@
+module V1
+ class MessagesController < ApplicationController
+
+ skip_before_filter :verify_authenticity_token
+ before_filter :authorize
+
+ 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