From 6c478c5a1634b5da9d269c938f67d2ac4d8f03df Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 9 Jan 2014 12:18:37 -0800 Subject: Some more cleanup, but still want to make sure by_user_ids_to_show_and_created_at view is right before issuing pull request. --- Gemfile.lock | 5 ----- users/app/controllers/v1/messages_controller.rb | 5 +++-- users/app/designs/message/by_user_ids_to_show_and_created_at.js | 2 +- users/app/models/message.rb | 2 ++ users/app/models/user.rb | 9 +++------ 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b42ac86..09d3123 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,7 +42,6 @@ PATH leap_web_core (= 0.5.0.rc) rails_warden ruby-srp (~> 0.2.1) - whenever GEM remote: https://rubygems.org/ @@ -89,7 +88,6 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - chronic (0.9.1) client_side_validations (3.2.6) client_side_validations-simple_form (2.1.0) client_side_validations (~> 3.2.5) @@ -257,9 +255,6 @@ GEM warden (1.2.3) rack (>= 1.0) websocket-driver (0.3.1) - whenever (0.8.2) - activesupport (>= 2.3.4) - chronic (>= 0.6.3) xpath (2.0.0) nokogiri (~> 1.3) diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index 371b83e..1b994ca 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -14,8 +14,9 @@ module V1 message = Message.find(params[:id]) if (message and current_user) message.user_ids_to_show.delete(current_user.id) - # is it necessary to keep track of what users have already seen it?: - message.user_ids_have_shown << current_user.id if !message.user_ids_have_shown.include?(current_user.id) #TODO: is it quicker to instead call uniq! after adding? + # is it necessary to keep track of what users have already seen it? + message.user_ids_have_shown << current_user.id if !message.user_ids_have_shown.include?(current_user.id) + # TODO: is it quicker to call uniq! after adding rather than check if it is already included? message.save render json: true else diff --git a/users/app/designs/message/by_user_ids_to_show_and_created_at.js b/users/app/designs/message/by_user_ids_to_show_and_created_at.js index 7bd7c2c..bb6412b 100644 --- a/users/app/designs/message/by_user_ids_to_show_and_created_at.js +++ b/users/app/designs/message/by_user_ids_to_show_and_created_at.js @@ -2,7 +2,7 @@ function (doc) { if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { doc.user_ids_to_show.forEach(function (userIdsToShow) { - emit([userIdsToShow, doc.created_at], 1); + emit([userIdsToShow, doc.created_at], 1); }); } } \ No newline at end of file diff --git a/users/app/models/message.rb b/users/app/models/message.rb index 16a19f4..d9ccee8 100644 --- a/users/app/models/message.rb +++ b/users/app/models/message.rb @@ -6,6 +6,8 @@ class Message < CouchRest::Model::Base property :user_ids_to_show, [String] property :user_ids_have_shown, [String] # is this necessary to store? + timestamps! + design do own_path = Pathname.new(File.dirname(__FILE__)) load_views(own_path.join('..', 'designs', 'message')) diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 71e57f3..44237ff 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -76,12 +76,9 @@ class User < CouchRest::Model::Base def messages(unseen = true) #TODO for now this only shows unseen messages. Will we ever want seen ones? Is it necessary to store? - #Message.by_user_ids_to_show.key(self.id).all # we don't want to emit all the userids associated with a message, so looping through to only emit text and id. - messages = [] - Message.by_user_ids_to_show.key(self.id).each do |message| - messages << [message.id, message.text] - end - messages + + # we don't want to emit all the userids associated with a message, so only emit id and text. + Message.by_user_ids_to_show.key(self.id).map { |message| [message.id, message.text] } end -- cgit v1.2.3