From 17b4f21ff057e9aef8cbb40a8479da51b63e541b Mon Sep 17 00:00:00 2001 From: Rummskartoffel Date: Sun, 4 Aug 2024 17:58:41 +0200 Subject: [PATCH] Immediately show middle-clicked notifications as read Before this patch, middle-clicking notifications would still mark them as read, but the user would only find out upon closing and re-opening the notification tray or reloading the page. Bug: T340179 Change-Id: Ic29af0c70354087cf5f783b5a7370241a86b4bf3 --- .../ui/mw.echo.ui.NotificationItemWidget.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/ui/mw.echo.ui.NotificationItemWidget.js b/modules/ui/mw.echo.ui.NotificationItemWidget.js index bf6946d6b..cdc2d1605 100644 --- a/modules/ui/mw.echo.ui.NotificationItemWidget.js +++ b/modules/ui/mw.echo.ui.NotificationItemWidget.js @@ -208,7 +208,8 @@ if ( this.model.getPrimaryUrl() ) { this.$element .attr( 'href', this.model.getPrimaryUrl() ) - .on( 'click', this.onPrimaryLinkClick.bind( this ) ); + .on( 'click', this.onPrimaryLinkClick.bind( this ) ) + .on( 'auxclick', this.onPrimaryLinkAuxclick.bind( this ) ); } }; @@ -227,6 +228,24 @@ return true; }; + /** + * Respond to primary link middle-click by immediately marking as read, + * then let the browser open the link in a new tab as normal. + * Opening the link would also mark as read, but this way the user gets immediate feedback. + * + * @param {Event} event + * + * @return {boolean} true + */ + mw.echo.ui.NotificationItemWidget.prototype.onPrimaryLinkAuxclick = function ( event ) { + if ( event.button === 1 ) { + this.$element.removeClass( 'mw-echo-ui-notificationItemWidget-initiallyUnseen' ); + this.markRead( true ); + } + // Don't prevent default action, let the browser take care of opening a new tab. + return true; + }; + /** * Manage a click on a dynamic secondary link. * We can't know what the link intends us to do in the API, so we trust the 'apiParams'