Merge "Consistently use the message when updating count"

This commit is contained in:
jenkins-bot 2017-09-18 15:08:17 +00:00 committed by Gerrit Code Review
commit 31709919e4
3 changed files with 19 additions and 11 deletions

View file

@ -76,7 +76,7 @@
numItems: Number( numMessages ),
hasUnseen: hasUnseenMessages,
badgeIcon: 'tray',
badgeLabel: badgeLabelMessages,
convertedNumber: badgeLabelMessages,
links: links,
href: $existingMessageLink.attr( 'href' )
}
@ -93,7 +93,7 @@
alertModelManager,
{
numItems: Number( numAlerts ),
badgeLabel: badgeLabelAlerts,
convertedNumber: badgeLabelAlerts,
hasUnseen: hasUnseenAlerts,
badgeIcon: 'bell',
links: links,

View file

@ -10,6 +10,7 @@
* @cfg {string} [type] The notification types this button represents;
* 'message', 'alert' or 'all'
* @cfg {string} [href] URL the badge links to
* @cfg {string} [convertedNumber] A converted version of the initial count
*/
mw.echo.ui.BadgeLinkWidget = function MwEchoUiBadgeLinkWidget( config ) {
config = config || {};
@ -28,7 +29,7 @@
this.count = 0;
this.type = config.type || 'alert';
this.setCount( config.numItems, config.label );
this.setCount( config.numItems, config.convertedNumber );
if ( config.href !== undefined && OO.ui.isSafeUrl( config.href ) ) {
this.$element.attr( 'href', config.href );
@ -47,22 +48,30 @@
* Set the count labels for this button.
*
* @param {number} numItems Number of items
* @param {string} [label] Label of the button. Defaults to the item number.
* @param {string} [convertedNumber] Label of the button. Defaults to the default message
* showing the item number.
*/
mw.echo.ui.BadgeLinkWidget.prototype.setCount = function ( numItems, label ) {
label = label || numItems;
mw.echo.ui.BadgeLinkWidget.prototype.setCount = function ( numItems, convertedNumber ) {
convertedNumber = convertedNumber !== undefined ? convertedNumber : numItems;
this.$element
.toggleClass( 'mw-echo-notifications-badge-all-read', !numItems )
.toggleClass( 'mw-echo-notifications-badge-long-label', label.length > 2 )
.toggleClass( 'mw-echo-notifications-badge-long-label', convertedNumber.length > 2 )
.attr( 'data-counter-num', numItems )
.attr( 'data-counter-text', label );
.attr( 'data-counter-text', convertedNumber );
this.setLabel( mw.msg(
this.type === 'alert' ?
'echo-notification-alert' :
'echo-notification-notice',
convertedNumber
) );
if ( this.count !== numItems ) {
this.count = numItems;
// Fire badge count change hook
mw.hook( 'ext.echo.badge.countChange' ).fire( this.type, this.count, label );
mw.hook( 'ext.echo.badge.countChange' ).fire( this.type, this.count, convertedNumber );
}
};
}( mediaWiki, jQuery ) );

View file

@ -51,7 +51,6 @@
this.types = this.manager.getTypes();
this.numItems = config.numItems || 0;
this.badgeLabel = config.badgeLabel || this.numItems;
this.hasRunFirstTime = false;
buttonFlags = [];
@ -60,7 +59,7 @@
}
this.badgeButton = new mw.echo.ui.BadgeLinkWidget( {
label: this.badgeLabel,
convertedNumber: config.convertedNumber,
type: this.manager.getTypeString(),
numItems: this.numItems,
flags: buttonFlags,