summaryrefslogtreecommitdiff
path: root/users/app/models
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-24 12:23:04 -0800
committerjessib <jessib@riseup.net>2013-12-24 12:36:42 -0800
commite4390e2ee5b2df20038f12865db462cf1e208ee6 (patch)
tree459db7c00d99d4182a4793a22623364cb931b2a6 /users/app/models
parenta9ff52501e9c04edacd250dd94ee3f3ad28cd73d (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/models')
-rw-r--r--users/app/models/user.rb12
1 files changed, 12 insertions, 0 deletions
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