diff options
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 |