From 1efce2cede3e6a8135dcc3d0c029e5b89067837f Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 11 Jan 2012 12:11:00 -0800 Subject: [PATCH] Revert "Merge pull request #2547 from stwf/unread_notifications" This reverts commit c61e84bc5047ee34a3494385ad177083c099566e, reversing changes made to b88899ff2af2cea0ccd522b938442a92dc24bec6. --- app/controllers/notifications_controller.rb | 4 +- app/views/notifications/index.html.haml | 2 +- app/views/notifications/index.mobile.haml | 2 +- .../widgets/notifications-badge.js | 9 ++--- public/javascripts/widgets/notifications.js | 40 +++++-------------- public/stylesheets/sass/application.sass | 2 - .../notifications_controller_spec.rb | 23 +---------- .../javascripts/widgets/notifications-spec.js | 33 +-------------- 8 files changed, 18 insertions(+), 97 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index deeb59e1b..c27df96c7 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -11,8 +11,8 @@ class NotificationsController < VannaController def update(opts=params) note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first if note - note.update_attributes(:unread => opts[:unread] == "true" ) - { :guid => note.id, :unread => note.unread } + note.update_attributes(:unread => false) + {} else Response.new :status => 404 end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 0935dea0e..88a098ab2 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -21,7 +21,7 @@ .span-8.notifications_for_day - notes.each do |note| - .stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : 'read'}"} + .stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : ''}"} - if note.type == "Notifications::StartedSharing" && contact = current_user.contact_for(note[:target]) .right = aspect_membership_dropdown(contact, note[:target], 'left') diff --git a/app/views/notifications/index.mobile.haml b/app/views/notifications/index.mobile.haml index 3f27eb8bc..18ea33fef 100644 --- a/app/views/notifications/index.mobile.haml +++ b/app/views/notifications/index.mobile.haml @@ -8,7 +8,7 @@ = day %ul.notifications_for_day - notes.each do |note| - .stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : 'read'}"} + .stream_element{:data=>{:guid => note.id}, :class => "#{note.unread ? 'unread' : ''}"} = person_image_link(note.actors.last) diff --git a/public/javascripts/widgets/notifications-badge.js b/public/javascripts/widgets/notifications-badge.js index f8499ffce..e64d5da39 100644 --- a/public/javascripts/widgets/notifications-badge.js +++ b/public/javascripts/widgets/notifications-badge.js @@ -63,7 +63,6 @@ $.each(notifications, function(index, notification) { var notificationElement = $("
") .addClass("notification_element") - .data( "guid", notification.id ) .html(notification.translation) .prepend($("", { src: notification.actors[0].avatar })) .append("
") @@ -74,18 +73,16 @@ .appendTo(self.dropdownNotifications); notificationElement.find("abbr.timeago").timeago(); - notificationElement.click(Diaspora.page.header.notifications.messageClick); if(notification.unread) { notificationElement.addClass("unread"); $.ajax({ url: "/notifications/" + notification.id, type: "PUT", - data: { unread: false }, - success: Diaspora.page.header.notifications.clickSuccess + success: function() { + Diaspora.page.header.notifications.decrementCount(); + } }); - } else { - notificationElement.addClass("read"); } }); }); diff --git a/public/javascripts/widgets/notifications.js b/public/javascripts/widgets/notifications.js index e16136d2a..fff80b404 100644 --- a/public/javascripts/widgets/notifications.js +++ b/public/javascripts/widgets/notifications.js @@ -15,7 +15,14 @@ notificationArea: notificationArea }); - $(".stream_element.unread,.stream_element.read").live("mousedown", self.messageClick); + $(".stream_element.unread").live("mousedown", function() { + self.decrementCount(); + + $.ajax({ + url: "notifications/" + $(this).removeClass("unread").data("guid"), + type: "PUT" + }); + }); $("a.more").live("click", function(evt) { evt.preventDefault(); @@ -24,33 +31,7 @@ .removeClass("hidden"); }); }); - this.messageClick = function() { - $.ajax({ - url: "notifications/" + $(this).data("guid"), - data: { unread: $(this).hasClass("read") }, - type: "PUT", - success: self.clickSuccess - }); - }; - this.clickSuccess = function( data ) { - var jsList = jQuery.parseJSON(data); - var itemID = jsList["guid"] - var isUnread = jsList["unread"] - if ( isUnread ) { - self.incrementCount(); - }else{ - self.decrementCount(); - } - $('.read,.unread').each(function(index) { - if ( $(this).data("guid") == itemID ) { - if ( isUnread ) { - $(this).removeClass("read").addClass( "unread" ) - } else { - $(this).removeClass("unread").addClass( "read" ) - } - } - }); - }; + this.showNotification = function(notification) { $(notification.html).prependTo(this.notificationArea) .fadeIn(200) @@ -69,15 +50,12 @@ if(self.badge.text() !== "") { self.badge.text(self.count); - $( ".notification_count" ).text(self.count); if(self.count === 0) { self.badge.addClass("hidden"); - $( ".notification_count" ).removeClass("unread"); } else if(self.count === 1) { self.badge.removeClass("hidden"); - $( ".notification_count" ).addClass("unread"); } } }; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index b7e83bde6..055205445 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -3138,8 +3138,6 @@ a.toggle_selector .notification_element :padding 10px :min-height 30px - &:hover - :background-color #FAFAFA > img :height 30px diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index d7dce0014..3f1e64b1f 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -14,32 +14,11 @@ describe NotificationsController do end describe '#update' do - it 'marks a notification as read if it gets no other information' do + it 'marks a notification as read' do note = Factory(:notification, :recipient => @user) @controller.update :id => note.id Notification.first.unread.should == false end - it 'marks a notification as read if it is told to' do - note = Factory(:notification, :recipient => @user) - @controller.update :id => note.id, :unread => "false" - Notification.first.unread.should == false - end - it 'marks a notification as unread if it is told to' do - note = Factory(:notification, :recipient => @user) - @controller.update :id => note.id, :unread => "true" - Notification.first.unread.should == true - end - - it 'should return the item guid' do - note = Factory(:notification, :recipient => @user) - answer = @controller.update :id => note.id - answer[:guid].should == note.id - end - it 'should return the unread state' do - note = Factory(:notification, :recipient => @user) - answer = @controller.update :id => note.id, :unread => "true" - answer[:unread].should == true - end it 'only lets you read your own notifications' do user2 = bob diff --git a/spec/javascripts/widgets/notifications-spec.js b/spec/javascripts/widgets/notifications-spec.js index f9ae7ee80..cbb962180 100644 --- a/spec/javascripts/widgets/notifications-spec.js +++ b/spec/javascripts/widgets/notifications-spec.js @@ -3,44 +3,13 @@ * the COPYRIGHT file. */ describe("Diaspora.Widgets.Notifications", function() { - var changeNotificationCountSpy, notifications, incrementCountSpy, decrementCountSpy; + var changeNotificationCountSpy, notifications; beforeEach(function() { spec.loadFixture("aspects_index"); notifications = Diaspora.BaseWidget.instantiate("Notifications", $("#notifications"), $("#notification_badge .badge_count")); changeNotificationCountSpy = spyOn(notifications, "changeNotificationCount").andCallThrough(); - incrementCountSpy = spyOn(notifications, "incrementCount").andCallThrough(); - decrementCountSpy = spyOn(notifications, "decrementCount").andCallThrough(); - }); - - describe("clickSuccess", function(){ - it("changes the css to a read cell", function() { - $(".notifications").html( - '
' + - '
' - ); - notifications.clickSuccess(JSON.stringify({guid:2,unread:false})); - expect( $('.stream_element#2')).toHaveClass("read"); - }); - it("changes the css to an unread cell", function() { - $(".notifications").html( - '
' + - '
' - ); - notifications.clickSuccess(JSON.stringify({guid:1,unread:true})); - expect( $('.stream_element#1')).toHaveClass("unread"); - }); - - - it("calls Notifications.decrementCount on a read cell", function() { - notifications.clickSuccess(JSON.stringify({guid:1,unread:false})); - expect(notifications.decrementCount).toHaveBeenCalled(); - }); - it("calls Notifications.incrementCount on a unread cell", function() { - notifications.clickSuccess(JSON.stringify({guid:1,unread:true})); - expect(notifications.incrementCount).toHaveBeenCalled(); - }); }); describe("decrementCount", function() {