Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/235885

Change subject: Fix the badge icon update
......................................................................

Fix the badge icon update

Make sure that when the seen state changes, the badge icon adjusts
in case there are two different icons for seen and unseen states.
Also organize a bit the unseen/unread status in initialization.

Bug: T111432
Change-Id: I891a36c6eace9302b370a3efaf5aa6f57192c17f
---
M modules/ext.echo.init.js
M modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
2 files changed, 22 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/85/235885/1

diff --git a/modules/ext.echo.init.js b/modules/ext.echo.init.js
index 2c5e016..e3f955d 100644
--- a/modules/ext.echo.init.js
+++ b/modules/ext.echo.init.js
@@ -17,8 +17,8 @@
                        $existingMessageLink = $( '#pt-notifications_message a' 
),
                        numAlerts = $existingAlertLink.text(),
                        numMessages = $existingMessageLink.text(),
-                       hasUnreadAlerts = $existingAlertLink.hasClass( 
'mw-echo-unseen-notifications' ),
-                       hasUnreadMessages = $existingMessageLink.hasClass( 
'mw-echo-unseen-notifications' ),
+                       hasUnseenAlerts = $existingAlertLink.hasClass( 
'mw-echo-unseen-notifications' ),
+                       hasUnseenMessages = $existingMessageLink.hasClass( 
'mw-echo-unseen-notifications' ),
                        // Store links
                        links = {
                                notifications: $( '#pt-notifications_message a' 
).attr( 'href' ),
@@ -30,7 +30,7 @@
                                type: 'message',
                                markReadWhenSeen: false,
                                numItems: numMessages,
-                               hasUnread: hasUnreadMessages,
+                               hasUnseen: hasUnseenMessages,
                                badgeIcon: 'speechBubble',
                                links: links
                        } );
@@ -41,7 +41,7 @@
                        type: 'alert',
                        markReadWhenSeen: true,
                        numItems: numAlerts,
-                       hasUnread: hasUnreadAlerts,
+                       hasUnseen: hasUnseenAlerts,
                        badgeIcon: {
                                read: 'bell',
                                unread: 'bellOn'
diff --git a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js 
b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
index a464175..de55b35 100644
--- a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
+++ b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
@@ -9,7 +9,7 @@
         * @param {Object} [config] Configuration object
         * @cfg {string} [type='alert'] Notification type 'alert' or 'message'
         * @cfg {number} [numItems=0] How many items are in the button display
-        * @cfg {boolean} [hasUnread=false] Whether there are unread items
+        * @cfg {boolean} [hasUnseen=false] Whether there are unseen items
         * @cfg {boolean} [markReadWhenSeen=false] Mark all notifications as 
read on open
         * @cfg {string|Object} [badgeIcon] The icons to use for this button.
         *  If this is a string, it will be used as the icon regardless of the 
state.
@@ -31,14 +31,13 @@
 
                this.type = config.type || 'alert';
                this.numItems = config.numItems || 0;
-               this.hasUnread = !!config.hasUnread;
                this.badgeIcon = config.badgeIcon || {};
                this.markReadWhenSeen = !!config.markReadWhenSeen;
 
                this.hasRunFirstTime = false;
 
                buttonFlags = [ 'primary' ];
-               if ( this.hasUnread ) {
+               if ( !!config.hasUnseen ) {
                        buttonFlags.push( 'unseen' );
                }
 
@@ -89,11 +88,6 @@
                        framed: false,
                        flags: buttonFlags,
                        label: this.numItems,
-                       icon: (
-                               typeof this.badgeIcon === 'string' ?
-                               this.badgeIcon :
-                               this.badgeIcon[ this.hasUnread ? 'unread' : 
'read' ]
-                       ),
                        popup: {
                                $content: this.notificationsWidget.$element,
                                $footer: $footer,
@@ -104,6 +98,7 @@
                                label: mw.msg( 'echo-notification-' + this.type 
+ '-text-only' )
                        }
                }, config ) );
+               this.updateIcon( !!config.hasUnseen );
 
                // HACK: Add an icon to the popup head label
                this.popup.$head.prepend( new OO.ui.IconWidget( { icon: 'bell' 
} ).$element );
@@ -119,7 +114,7 @@
                this.popup.closeButton.toggle( false );
                // Add the 'mark all as read' button to the header
                this.popup.$head.append( this.markAllReadButton.$element );
-               this.markAllReadButton.toggle( !this.markReadWhenSeen && 
this.hasUnread );
+               this.markAllReadButton.toggle( !this.markReadWhenSeen && 
!!config.hasUnseen );
 
                // Events
                this.markAllReadButton.connect( this, { click: 
'onMarkAllReadButtonClick' } );
@@ -143,6 +138,19 @@
        OO.mixinClass( mw.echo.ui.NotificationBadgeWidget, 
OO.ui.mixin.PendingElement );
 
        /**
+        * Update the badge icon with the read/unread versions if they exist.
+        *
+        * @param {boolean} hasUnseen Widget has unseen notifications
+        */
+       mw.echo.ui.NotificationBadgeWidget.prototype.updateIcon = function ( 
hasUnseen ) {
+               this.setIcon(
+                       typeof this.badgeIcon === 'string' ?
+                       this.badgeIcon :
+                       this.badgeIcon[ hasUnseen ? 'unread' : 'read' ]
+               );
+       };
+
+       /**
         * Update the badge state and label based on changes to the model
         */
        mw.echo.ui.NotificationBadgeWidget.prototype.updateBadge = function () {
@@ -152,6 +160,7 @@
                // Update numbers and seen/unseen state
                this.setFlags( { unseen: !!unseenCount } );
                this.setLabel( String( unreadCount ) );
+               this.updateIcon( !!unseenCount );
        };
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/235885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I891a36c6eace9302b370a3efaf5aa6f57192c17f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to