From dbd2f4ccf727fe99071ef298792c6a88cf345e0a Mon Sep 17 00:00:00 2001 From: Moriel Schottlender Date: Mon, 12 Sep 2016 14:06:49 -0700 Subject: [PATCH] Generalize getCappedNotificationCount and move to counter This follows the generalization we made in the back-end and allows us to always use the same method to get capped notification count in the display. Bug: T144707 Change-Id: I4d7f406b05a195972dca0d2088bde2ff739d313d --- .../mw.echo.dm.UnreadNotificationCounter.js | 18 ++++++++++++++++ .../ui/mw.echo.ui.NotificationBadgeWidget.js | 21 ++----------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/modules/model/mw.echo.dm.UnreadNotificationCounter.js b/modules/model/mw.echo.dm.UnreadNotificationCounter.js index 9a4fea189..eaafa0f67 100644 --- a/modules/model/mw.echo.dm.UnreadNotificationCounter.js +++ b/modules/model/mw.echo.dm.UnreadNotificationCounter.js @@ -46,6 +46,24 @@ /* Methods */ + /** + * Normalizes for a capped count in case the requested count + * is higher than the cap. + * + * This is the client-side version of + * NotificationController::getCappedNotificationCount. + * + * @param {number} count Count before cap is applied + * @return {number} Count with cap applied + */ + mw.echo.dm.UnreadNotificationCounter.prototype.getCappedNotificationCount = function ( count ) { + if ( count <= this.max ) { + return count; + } else { + return this.max + 1; + } + }; + /** * Get the current count * diff --git a/modules/ui/mw.echo.ui.NotificationBadgeWidget.js b/modules/ui/mw.echo.ui.NotificationBadgeWidget.js index c05338bfc..dad261c70 100644 --- a/modules/ui/mw.echo.ui.NotificationBadgeWidget.js +++ b/modules/ui/mw.echo.ui.NotificationBadgeWidget.js @@ -50,7 +50,6 @@ // Properties this.types = this.manager.getTypes(); - this.maxNotificationCount = mw.config.get( 'wgEchoMaxNotificationCount' ); this.numItems = config.numItems || 0; this.badgeLabel = config.badgeLabel || this.numItems; this.hasRunFirstTime = false; @@ -232,22 +231,6 @@ this.popup.toggle(); }; - // Client-side version of NotificationController::getCappedNotificationCount. - /** - * Gets the count to use for display - * - * @param {number} count Count before cap is applied - * - * @return {number} Count with cap applied - */ - mw.echo.ui.NotificationBadgeWidget.prototype.getCappedNotificationCount = function ( count ) { - if ( count <= this.maxNotificationCount ) { - return count; - } else { - return this.maxNotificationCount + 1; - } - }; - /** * Respond to SeenTime model update event */ @@ -282,9 +265,9 @@ var unreadCount, cappedUnreadCount, badgeLabel; unreadCount = this.manager.getUnreadCounter().getCount(); - cappedUnreadCount = this.getCappedNotificationCount( unreadCount ); + cappedUnreadCount = this.manager.getUnreadCounter().getCappedNotificationCount( unreadCount ); cappedUnreadCount = mw.language.convertNumber( cappedUnreadCount ); - badgeLabel = mw.message( 'echo-badge-count', cappedUnreadCount ).text(); + badgeLabel = mw.message( 'echo-badge-count', mw.language.convertNumber( cappedUnreadCount ) ).text(); this.badgeButton.setLabel( badgeLabel ); this.badgeButton.setCount( unreadCount, badgeLabel );