From bd867c51c4d9e3d4c6b4c55d326eb9b13b89288b Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Feb 2014 14:23:38 +0100 Subject: minor: move some logic from message controller into model --- users/app/models/message.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'users/app/models') 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 -- cgit v1.2.3 From e3577906891f9ab0edd987544e3432f354bc1721 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Feb 2014 19:41:02 +0100 Subject: fix unread_by? to check user_ids_to_show, remove TODO uniq! is probably not any faster than just checking include? --- users/app/models/message.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'users/app/models') diff --git a/users/app/models/message.rb b/users/app/models/message.rb index 7c05e06..424f094 100644 --- a/users/app/models/message.rb +++ b/users/app/models/message.rb @@ -17,7 +17,6 @@ class Message < CouchRest::Model::Base 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) @@ -25,6 +24,6 @@ class Message < CouchRest::Model::Base end def unread_by?(user) - user_ids_to_shown.include?(user.id) + user_ids_to_show.include?(user.id) end end -- cgit v1.2.3