Mooeypoo has uploaded a new change for review.

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

Change subject: Prevent the badge icon from flashing red when updating 
notifications
......................................................................

Prevent the badge icon from flashing red when updating notifications

If the popup is open, whatever is coming in is immediately 'seen',
so we shouldn't flash the badge as red.

Bug: T112823
Change-Id: I9fe78ed11506de3c82043141f994e1ca96c5880b
---
M modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
1 file changed, 30 insertions(+), 7 deletions(-)


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

diff --git a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js 
b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
index 3ae932b..4c4f407 100644
--- a/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
+++ b/modules/ooui/mw.echo.ui.NotificationBadgeWidget.js
@@ -197,12 +197,32 @@
         */
        mw.echo.ui.NotificationBadgeWidget.prototype.updateBadge = function () {
                var unseenCount = this.notificationsModel.getUnseenCount(),
-                       unreadCount = this.notificationsModel.getUnreadCount();
+                       unreadCount = this.notificationsModel.getUnreadCount(),
+                       oldUnreadCount = this.badgeButton.getLabel();
 
                // Update numbers and seen/unseen state
-               this.badgeButton.setFlags( { unseen: !!unseenCount } );
-               this.badgeButton.setLabel( mw.language.convertNumber( 
unreadCount ) );
-               this.updateIcon( !!unseenCount );
+               // If the popup is open, only allow a "demotion" of the badge
+               // to grey; ignore change of color to 'unseen'
+               if ( this.isPopupOpen ) {
+                       if ( !unseenCount ) {
+                               this.badgeButton.setFlags( { unseen: false } );
+                               this.updateIcon( false );
+                       }
+               } else {
+                       this.badgeButton.setFlags( { unseen: !!unseenCount } );
+                       this.updateIcon( !!unseenCount );
+               }
+
+               // Update badge count
+               if ( this.markReadWhenSeen && this.isPopupOpen ) {
+                       // If the notifications are markedReadWhenSeen and the 
popup is open
+                       // only display decrease of numbers
+                       if ( unreadCount < oldUnreadCount ) {
+                               this.badgeButton.setLabel( 
mw.language.convertNumber( unreadCount ) );
+                       }
+               } else {
+                       this.badgeButton.setLabel( mw.language.convertNumber( 
unreadCount ) );
+               }
 
                // Check if we need to display the 'mark all unread' button
                this.markAllReadButton.toggle( !!unreadCount );
@@ -244,13 +264,15 @@
                                        
mw.echo.logger.logNotificationImpressions( this.type, idArray, 
mw.echo.Logger.static.context.popup );
 
                                        // // Mark notifications as 'read' if 
markReadWhenSeen is set to true
-                                       if ( widget.markReadWhenSeen ) {
+                                       if ( widget.isPopupOpen && 
widget.markReadWhenSeen ) {
                                                return 
widget.notificationsModel.markAllRead();
                                        }
                                } )
                                .then( function () {
-                                       // Update seen time
-                                       
widget.notificationsModel.updateSeenTime();
+                                       if ( widget.isPopupOpen ) {
+                                               // Update seen time
+                                               
widget.notificationsModel.updateSeenTime();
+                                       }
                                } )
                                .then(
                                        // Success
@@ -283,6 +305,7 @@
         * Extend the response to button click so we can also update the 
notification list.
         */
        mw.echo.ui.NotificationBadgeWidget.prototype.onPopupToggle = function ( 
isVisible ) {
+               this.isPopupOpen = isVisible;
                if ( !isVisible ) {
                        // If the popup is closing, leave
                        return;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9fe78ed11506de3c82043141f994e1ca96c5880b
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