mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-09-24 18:59:40 +00:00
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
This commit is contained in:
parent
7f24836607
commit
dbd2f4ccf7
|
@ -46,6 +46,24 @@
|
||||||
|
|
||||||
/* Methods */
|
/* 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
|
* Get the current count
|
||||||
*
|
*
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
// Properties
|
// Properties
|
||||||
this.types = this.manager.getTypes();
|
this.types = this.manager.getTypes();
|
||||||
|
|
||||||
this.maxNotificationCount = mw.config.get( 'wgEchoMaxNotificationCount' );
|
|
||||||
this.numItems = config.numItems || 0;
|
this.numItems = config.numItems || 0;
|
||||||
this.badgeLabel = config.badgeLabel || this.numItems;
|
this.badgeLabel = config.badgeLabel || this.numItems;
|
||||||
this.hasRunFirstTime = false;
|
this.hasRunFirstTime = false;
|
||||||
|
@ -232,22 +231,6 @@
|
||||||
this.popup.toggle();
|
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
|
* Respond to SeenTime model update event
|
||||||
*/
|
*/
|
||||||
|
@ -282,9 +265,9 @@
|
||||||
var unreadCount, cappedUnreadCount, badgeLabel;
|
var unreadCount, cappedUnreadCount, badgeLabel;
|
||||||
|
|
||||||
unreadCount = this.manager.getUnreadCounter().getCount();
|
unreadCount = this.manager.getUnreadCounter().getCount();
|
||||||
cappedUnreadCount = this.getCappedNotificationCount( unreadCount );
|
cappedUnreadCount = this.manager.getUnreadCounter().getCappedNotificationCount( unreadCount );
|
||||||
cappedUnreadCount = mw.language.convertNumber( cappedUnreadCount );
|
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.setLabel( badgeLabel );
|
||||||
this.badgeButton.setCount( unreadCount, badgeLabel );
|
this.badgeButton.setCount( unreadCount, badgeLabel );
|
||||||
|
|
Loading…
Reference in a new issue