summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Sørensen <johan@johansorensen.com>2009-06-23 14:11:04 +0200
committerJohan Sørensen <johan@johansorensen.com>2009-06-23 14:12:31 +0200
commit1f3683c6e05f79894bb8efd0f26c534a1ec4f5d3 (patch)
treea9d2d1a101b6b37206fd4084e85451158eda75c1
parent0f93ce1574d8138f3be0f676308341711df93b6b (diff)
downloadgitorious-mainline-outdated-1f3683c6e05f79894bb8efd0f26c534a1ec4f5d3.zip
gitorious-mainline-outdated-1f3683c6e05f79894bb8efd0f26c534a1ec4f5d3.tar.gz
gitorious-mainline-outdated-1f3683c6e05f79894bb8efd0f26c534a1ec4f5d3.tar.bz2
Mark the whole message thread as read whenever it's viewed
This is done in an after_filter so that it'll still be rendered as unread whenever the thread is viewed
-rw-r--r--app/controllers/messages_controller.rb9
-rw-r--r--test/functional/messages_controller_test.rb16
2 files changed, 24 insertions, 1 deletions
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 8302b88..f0644a6 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -17,6 +17,7 @@
#++
class MessagesController < ApplicationController
before_filter :login_required
+ after_filter :mark_thread_as_read, :only => :show
renders_in_global_context
def index
@@ -64,7 +65,6 @@ class MessagesController < ApplicationController
redirect_to :action => :index
end
-
def show
@message = Message.find(params[:id])
unless @message.sender == current_user or @message.recipient == current_user
@@ -125,4 +125,11 @@ class MessagesController < ApplicationController
# Always required.
true
end
+
+ def mark_thread_as_read
+ return unless @message
+ @message.messages_in_thread.each do |msg|
+ msg.read
+ end
+ end
end
diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb
index 49dd58f..3edf363 100644
--- a/test/functional/messages_controller_test.rb
+++ b/test/functional/messages_controller_test.rb
@@ -103,6 +103,22 @@ class MessagesControllerTest < ActionController::TestCase
should_respond_with :success
should_assign_to :message
end
+
+ context "on GET show and marking a thread as read" do
+ setup do
+ @message = messages(:johans_message_to_moe)
+ @reply = @message.build_reply(:body => "thats fine", :sender => users(:mike))
+ @reply.save!
+ assert @message.messages_in_thread.include?(@reply)
+ login_as :moe
+ end
+
+ should "mark the whole thread as read, while preserving markup" do
+ get :show, :id => @message.to_param
+ assert_select "#message_#{@reply.id}.unread"
+ assert @reply.reload.read?, "message wasn't marked read when viewed"
+ end
+ end
context 'On GET to show in XML' do
setup do