Mark all unread post-related notifications as read, if one of this gets opened

This commit is contained in:
movilla 2012-12-24 00:13:32 +01:00
parent 4587a926ad
commit c1b858a877
3 changed files with 11 additions and 11 deletions

View file

@ -18,6 +18,7 @@
* Add simple background for unread messages/conversations mobile. [#3724](https://github.com/diaspora/diaspora/pull/3724) * Add simple background for unread messages/conversations mobile. [#3724](https://github.com/diaspora/diaspora/pull/3724)
* Add flash warning to conversation mobile, unification of flash warning with login and register mobile, and add support for flash warning to Opera browser. [#3686](https://github.com/diaspora/diaspora/pull/3686) * Add flash warning to conversation mobile, unification of flash warning with login and register mobile, and add support for flash warning to Opera browser. [#3686](https://github.com/diaspora/diaspora/pull/3686)
* Add progress percentage to upload images. [#3740](https://github.com/diaspora/diaspora/pull/3740) * Add progress percentage to upload images. [#3740](https://github.com/diaspora/diaspora/pull/3740)
* Mark all unread post-related notifications as read, if one of this gets opened. [#3787](https://github.com/diaspora/diaspora/pull/3787)
## Bug Fixes ## Bug Fixes

View file

@ -25,7 +25,7 @@ class PostsController < ApplicationController
end end
def show def show
mark_corresponding_notification_read if user_signed_in? mark_corresponding_notifications_read if user_signed_in?
respond_to do |format| respond_to do |format|
format.html{ gon.post = PostPresenter.new(@post, current_user); render 'posts/show' } format.html{ gon.post = PostPresenter.new(@post, current_user); render 'posts/show' }
@ -104,10 +104,10 @@ class PostsController < ApplicationController
request.format = :html if request.format == 'application/html+xml' request.format = :html if request.format == 'application/html+xml'
end end
def mark_corresponding_notification_read def mark_corresponding_notifications_read
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @post.id, :unread => true).first Notification.where(recipient_id: current_user.id, target_id: @post.id, unread: true).each do |n|
notification.unread = false n.unread = false
notification.save n.save!
end end
end end
end end

View file

@ -40,15 +40,14 @@ describe PostsController do
response.should be_success response.should be_success
end end
it 'marks a corresponding notification as read' do it 'marks a corresponding notifications as read' do
# Ensure that it doesn't mark a read notification as read FactoryGirl.create(:notification, :recipient => alice, :target => @message, :unread => true)
FactoryGirl.create(:notification, :recipient => alice, :target => @message, :unread => false)
note = FactoryGirl.create(:notification, :recipient => alice, :target => @message, :unread => true) note = FactoryGirl.create(:notification, :recipient => alice, :target => @message, :unread => true)
expect { expect {
get :show, :id => @message.id get :show, :id => @message.id
note.reload note.reload
}.to change(note, :unread).from(true).to(false) }.to change(Notification.where(:unread => true), :count).by(-2)
end end
it 'succeeds with a AS/photo' do it 'succeeds with a AS/photo' do