diff options
author | jessib <jessib@riseup.net> | 2013-12-24 12:23:04 -0800 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-12-24 12:36:42 -0800 |
commit | e4390e2ee5b2df20038f12865db462cf1e208ee6 (patch) | |
tree | 459db7c00d99d4182a4793a22623364cb931b2a6 /users/app | |
parent | a9ff52501e9c04edacd250dd94ee3f3ad28cd73d (diff) |
Add API tests and some refactoring of messages so we can get a user's messages within the webapp.
Diffstat (limited to 'users/app')
-rw-r--r-- | users/app/controllers/v1/messages_controller.rb | 10 | ||||
-rw-r--r-- | users/app/models/user.rb | 12 |
2 files changed, 14 insertions, 8 deletions
diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index a4e9aec..fa98042 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -6,14 +6,8 @@ module V1 # for now, will not pass unseen, so unseen will always be true def user_messages(unseen = true) - user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [params[:user_id], false]).all : UserMessage.by_user_id(:key => params[:user_id]).all - - messages = [] - user_messages.each do |um| - messages << Message.find(um.message.id) - end - - render json: messages + user = User.find(params[:user_id]) + render json: (user ? user.messages : [] ) end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 720f5a9..fe3a127 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -72,6 +72,18 @@ class User < CouchRest::Model::Base Ticket.for_user(self).limit(count).all #defaults to having most recent updated first end + def messages(unseen = true) + + user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [self.id, false]).all : UserMessage.by_user_id(:key => self.id).all + + messages = [] + user_messages.each do |um| + messages << Message.find(um.message.id) + end + messages + + end + # DEPRECATED # # Please set the key on the identity directly |