Consistently use the message when updating count

The current initial message in the button label is "Alerts (x)" or
"Notices (x)" but when the badge loaded, we changed that to only show
the rendered number. This is inconsistent; the badge should always
update the label properly, even if it's not visible in most cases.

Bug: T173970
Change-Id: I6a5e13fc36ddb1bf467c712fcf49af3b18e582d0
This commit is contained in:
Moriel Schottlender 2017-09-01 17:08:21 -07:00
parent 4696f3fb4d
commit 57f14931b6
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,