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

View file

@ -10,6 +10,7 @@
* @cfg {string} [type] The notification types this button represents; * @cfg {string} [type] The notification types this button represents;
* 'message', 'alert' or 'all' * 'message', 'alert' or 'all'
* @cfg {string} [href] URL the badge links to * @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 ) { mw.echo.ui.BadgeLinkWidget = function MwEchoUiBadgeLinkWidget( config ) {
config = config || {}; config = config || {};
@ -28,7 +29,7 @@
this.count = 0; this.count = 0;
this.type = config.type || 'alert'; 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 ) ) { if ( config.href !== undefined && OO.ui.isSafeUrl( config.href ) ) {
this.$element.attr( 'href', config.href ); this.$element.attr( 'href', config.href );
@ -47,22 +48,30 @@
* Set the count labels for this button. * Set the count labels for this button.
* *
* @param {number} numItems Number of items * @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 ) { mw.echo.ui.BadgeLinkWidget.prototype.setCount = function ( numItems, convertedNumber ) {
label = label || numItems; convertedNumber = convertedNumber !== undefined ? convertedNumber : numItems;
this.$element this.$element
.toggleClass( 'mw-echo-notifications-badge-all-read', !numItems ) .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-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 ) { if ( this.count !== numItems ) {
this.count = numItems; this.count = numItems;
// Fire badge count change hook // 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 ) ); }( mediaWiki, jQuery ) );

View file

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