diff options
author | Azul <azul@leap.se> | 2014-02-10 14:23:38 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2014-02-10 14:23:38 +0100 |
commit | bd867c51c4d9e3d4c6b4c55d326eb9b13b89288b (patch) | |
tree | 9c03e20ec93093e9bb2ec47e982bdfcaec5c055e /users/app/models/message.rb | |
parent | bcdde2f6bfb4ed3a1535bd2e50ab47529a9141e2 (diff) |
minor: move some logic from message controller into model
Diffstat (limited to 'users/app/models/message.rb')
-rw-r--r-- | users/app/models/message.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/users/app/models/message.rb b/users/app/models/message.rb index d9ccee8..7c05e06 100644 --- a/users/app/models/message.rb +++ b/users/app/models/message.rb @@ -13,4 +13,18 @@ class Message < CouchRest::Model::Base load_views(own_path.join('..', 'designs', 'message')) end + def mark_as_read_by(user) + user_ids_to_show.delete(user.id) + # is it necessary to keep track of what users have already seen it? + user_ids_have_shown << user.id unless read_by?(user) + # TODO: is it quicker to call uniq! after adding rather than check if it is already included? + end + + def read_by?(user) + user_ids_have_shown.include?(user.id) + end + + def unread_by?(user) + user_ids_to_shown.include?(user.id) + end end |