diff --git a/Changelog.md b/Changelog.md index 1eff2d964c8c8a27f2e2ab6e03163f2eea6f5c3b..a4a9d2e2dc3f4cb62746eb5c825654644aed4e49 100644 --- a/Changelog.md +++ b/Changelog.md @@ -33,6 +33,7 @@ * Add Terms of Service as an option for podmins, includes base template [#5104](https://github.com/diaspora/diaspora/pull/5104) * Add rake task to send a mail to all users [#5111](https://github.com/diaspora/diaspora/pull/5111) * Expose which services are configured in /statistics.json [#5121](https://github.com/diaspora/diaspora/pull/5121) +* In filtered notification views, replace "Mark all as read" with "Mark shown as read" [#5122](https://github.com/diaspora/diaspora/pull/5122) # 0.4.0.1 diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 85e951436467b78e16e0d6bb4de09e7cb992f114..4354093bc3805745b92b9349cd14a12e33eddeb6 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -65,13 +65,22 @@ class NotificationsController < ApplicationController end def read_all - Notification.where(:recipient_id => current_user.id).update_all(:unread => false) + current_type = Notification.types[params[:type]] + notifications = Notification.where(:recipient_id => current_user.id) + notifications = notifications.where(:type => current_type) if params[:type] + notifications.update_all(:unread => false) respond_to do |format| - format.html { redirect_to stream_path } - format.mobile{ redirect_to stream_path} + if current_user.unread_notifications.count > 0 + format.html { redirect_to notifications_path } + format.mobile { redirect_to notifications_path } + else + format.html { redirect_to stream_path } + format.mobile { redirect_to stream_path } + end format.xml { render :xml => {}.to_xml } format.json { render :json => {}.to_json } end + end end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 9f91e69461319fb29cbc3d9a28cc35de61c6d6eb..19033fe7ac930aa5f7e94899d7611f4f1a403795 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -36,8 +36,11 @@ = t('.show_all') %a.btn.btn-default{ :class => ('active' if params[:show] == 'unread'), :href => '/notifications?show=unread' + (params[:type] ? '&type=' + params[:type] : '') } = t('.show_unread') - %a.btn.btn-default{:href => notifications_read_all_path, :class => ('disabled' unless @unread_notification_count > 0)} - = t('.mark_all_as_read') + %a.btn.btn-default{:href => read_all_notifications_path(:type => params[:type] ), :class => ('disabled' unless @unread_notification_count > 0)} + -if params[:type] + = t('.mark_all_shown_as_read') + -else + = t('.mark_all_as_read') - @group_days.each do |day, notes| .day_group.row-fluid .date.span2 diff --git a/app/views/notifications/index.mobile.haml b/app/views/notifications/index.mobile.haml index cee20a7488d45ba7dbdbf07e7e6f2fe09b483557..498ee29a402e5681da08bcc01735aafb9a2aab04 100644 --- a/app/views/notifications/index.mobile.haml +++ b/app/views/notifications/index.mobile.haml @@ -2,8 +2,10 @@ = t('.notifications') .right - = link_to t('.mark_all_as_read'), notifications_read_all_path, :class => 'btn' - + -if params[:type] + = link_to t('.mark_all_shown_as_read'), read_all_notifications_path(:type => params[:type] ), :class => 'btn' + -else + = link_to t('.mark_all_as_read'), read_all_notifications_path, :class => 'btn' %ul.notifications - @group_days.each do |day, notes| %li diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index e768e649018e3e242f7b16af06848c2241f58b59..fa2c84b8a5291861174183001e9233d1e6796d43 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -709,6 +709,7 @@ en: index: notifications: "Notifications" mark_all_as_read: "Mark all as read" + mark_all_shown_as_read: "Mark all shown as read" mark_read: "Mark read" mark_unread: "Mark unread" show_all: "show all" diff --git a/config/routes.rb b/config/routes.rb index 240b4ddde13f521b709e2b4fb859097f73380936..519a731f4add1f97ac0008b176ac67c048b197f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,9 +79,12 @@ Diaspora::Application.routes.draw do delete 'visibility' => 'conversation_visibilities#destroy' end - get 'notifications/read_all' => 'notifications#read_all' resources :notifications, :only => [:index, :update] do + collection do + get :read_all + end end + resources :tags, :only => [:index] diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 5b2e37452e80685890db1383483a0e9e969cb823..adb739df5bbfd71f2686d419721266371dc7143b 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -42,33 +42,6 @@ describe NotificationsController do end end - describe "#read_all" do - it 'marks all notifications as read' do - request.env["HTTP_REFERER"] = "I wish I were spelled right" - FactoryGirl.create(:notification, :recipient => alice) - FactoryGirl.create(:notification, :recipient => alice) - - Notification.where(:unread => true).count.should == 2 - get :read_all - Notification.where(:unread => true).count.should == 0 - end - it "should redirect to the stream in the html version" do - FactoryGirl.create(:notification, :recipient => alice) - get :read_all, :format => :html - response.should redirect_to(stream_path) - end - it "should redirect to the stream in the mobile version" do - FactoryGirl.create(:notification, :recipient => alice) - get :read_all, :format => :mobile - response.should redirect_to(stream_path) - end - it "should return a dummy value in the json version" do - FactoryGirl.create(:notification, :recipient => alice) - get :read_all, :format => :json - response.should_not be_redirect - end - end - describe '#index' do before do @post = FactoryGirl.create(:status_message) @@ -137,4 +110,51 @@ describe NotificationsController do end end end + + describe "#read_all" do + it 'marks all notifications as read' do + request.env["HTTP_REFERER"] = "I wish I were spelled right" + FactoryGirl.create(:notification, :recipient => alice) + FactoryGirl.create(:notification, :recipient => alice) + + Notification.where(:unread => true).count.should == 2 + get :read_all + Notification.where(:unread => true).count.should == 0 + end + it 'marks all notifications in the current filter as read' do + request.env["HTTP_REFERER"] = "I wish I were spelled right" + FactoryGirl.create(:notification, :recipient => alice) + eve.share_with(alice.person, eve.aspects.first) + Notification.where(:unread => true).count.should == 2 + get :read_all, "type" => "started_sharing" + Notification.where(:unread => true).count.should == 1 + end + it "should redirect back in the html version if it has > 0 notifications" do + FactoryGirl.create(:notification, :recipient => alice) + eve.share_with(alice.person, eve.aspects.first) + get :read_all, :format => :html, "type" => "started_sharing" + response.should redirect_to(notifications_path) + end + it "should redirect back in the mobile version if it has > 0 notifications" do + FactoryGirl.create(:notification, :recipient => alice) + eve.share_with(alice.person, eve.aspects.first) + get :read_all, :format => :mobile, "type" => "started_sharing" + response.should redirect_to(notifications_path) + end + it "should redirect to stream in the html version if it has 0 notifications" do + FactoryGirl.create(:notification, :recipient => alice) + get :read_all, :format => :html + response.should redirect_to(stream_path) + end + it "should redirect back in the mobile version if it has 0 notifications" do + FactoryGirl.create(:notification, :recipient => alice) + get :read_all, :format => :mobile + response.should redirect_to(stream_path) + end + it "should return a dummy value in the json version" do + FactoryGirl.create(:notification, :recipient => alice) + get :read_all, :format => :json + response.should_not be_redirect + end + end end