From 535954dcc2e5dce23d0f6aebc9e64d3adf59af8a Mon Sep 17 00:00:00 2001 From: Dan Hansen Date: Sat, 7 May 2011 07:28:52 -0500 Subject: [PATCH] make incrementing the notification count optional --- public/javascripts/web-socket-receiver.js | 5 +++-- public/javascripts/widgets/notifications.js | 7 +++++-- spec/javascripts/widgets/notifications-spec.js | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index c0bfdc578..505afadfb 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -8,8 +8,9 @@ var WebSocketReceiver = { ws.onclose = function() { Diaspora.widgets.notifications.showNotification({ html: '
' + - Diaspora.widgets.i18n.t("web_sockets.disconnected") + - '
' + Diaspora.widgets.i18n.t("web_sockets.disconnected") + + '', + incrementCount: false }); WSR.debug("socket closed"); diff --git a/public/javascripts/widgets/notifications.js b/public/javascripts/widgets/notifications.js index 0091720e3..70bf9136b 100644 --- a/public/javascripts/widgets/notifications.js +++ b/public/javascripts/widgets/notifications.js @@ -32,14 +32,17 @@ }; }; - Notifications.prototype.showNotification = function(notification) { $(notification.html).prependTo(this.notificationArea) + Notifications.prototype.showNotification = function(notification) { + $(notification.html).prependTo(this.notificationArea) .fadeIn(200) .delay(8000) .fadeOut(200, function() { $(this).detach(); }); - this.incrementCount(); + if(typeof notification.incrementCount === "undefined" || notification.incrementCount) { + this.incrementCount(); + } }; Notifications.prototype.changeNotificationCount = function(change) { diff --git a/spec/javascripts/widgets/notifications-spec.js b/spec/javascripts/widgets/notifications-spec.js index aeedf1d57..c68854205 100644 --- a/spec/javascripts/widgets/notifications-spec.js +++ b/spec/javascripts/widgets/notifications-spec.js @@ -50,6 +50,18 @@ describe("Diaspora", function() { expect($("#notifications div").length).toEqual(1); }); + + it("only increments the notification count if specified to do so", function() { + var originalCount = Diaspora.widgets.notifications.count; + + Diaspora.widgets.notifications.showNotification({ + html: '
', + incrementCount: false + }); + + expect(Diaspora.widgets.notifications.count).toEqual(originalCount); + + }); }); }); });