mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-12 09:26:05 +00:00
Merge "Include cross-wiki notifications in unread count"
This commit is contained in:
commit
b301ae9a0c
3
Echo.php
3
Echo.php
|
@ -110,6 +110,9 @@ $wgHooks['LinksUpdateAfterInsert'][] = 'EchoHooks::onLinksUpdateAfterInsert';
|
||||||
// Beta features
|
// Beta features
|
||||||
$wgHooks['GetBetaFeaturePreferences'][] = 'EchoHooks::getBetaFeaturePreferences';
|
$wgHooks['GetBetaFeaturePreferences'][] = 'EchoHooks::getBetaFeaturePreferences';
|
||||||
|
|
||||||
|
// Global config vars
|
||||||
|
$wgHooks['ResourceLoaderGetConfigVars'][] = 'EchoHooks::onResourceLoaderGetConfigVars';
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
|
|
||||||
// Whether to turn on email batch function
|
// Whether to turn on email batch function
|
||||||
|
|
|
@ -1160,4 +1160,10 @@ class EchoHooks {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function onResourceLoaderGetConfigVars( &$vars ) {
|
||||||
|
global $wgEchoMaxNotificationCount;
|
||||||
|
$vars['wgEchoMaxNotificationCount'] = $wgEchoMaxNotificationCount;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,7 @@ $wgResourceModules += array(
|
||||||
'oojs-ui.styles.icons-content',
|
'oojs-ui.styles.icons-content',
|
||||||
),
|
),
|
||||||
'messages' => array(
|
'messages' => array(
|
||||||
|
'echo-notification-count',
|
||||||
'echo-overlay-link',
|
'echo-overlay-link',
|
||||||
'echo-mark-all-as-read',
|
'echo-mark-all-as-read',
|
||||||
'echo-more-info',
|
'echo-more-info',
|
||||||
|
|
|
@ -208,7 +208,9 @@
|
||||||
mw.echo.ui.NotificationBadgeWidget.prototype.updateBadge = function () {
|
mw.echo.ui.NotificationBadgeWidget.prototype.updateBadge = function () {
|
||||||
var unseenCount = this.notificationsModel.getUnseenCount(),
|
var unseenCount = this.notificationsModel.getUnseenCount(),
|
||||||
unreadCount = this.notificationsModel.getUnreadCount(),
|
unreadCount = this.notificationsModel.getUnreadCount(),
|
||||||
nonBundledUnreadCount = this.notificationsModel.getNonbundledUnreadCount();
|
nonBundledUnreadCount = this.notificationsModel.getNonbundledUnreadCount(),
|
||||||
|
wgEchoMaxNotificationCount,
|
||||||
|
badgeLabel;
|
||||||
|
|
||||||
// Update numbers and seen/unseen state
|
// Update numbers and seen/unseen state
|
||||||
// If the popup is open, only allow a "demotion" of the badge
|
// If the popup is open, only allow a "demotion" of the badge
|
||||||
|
@ -225,7 +227,13 @@
|
||||||
|
|
||||||
// Update badge count
|
// Update badge count
|
||||||
if ( !this.markReadWhenSeen || !this.popup.isVisible() || unreadCount < this.currentUnreadCountInBadge ) {
|
if ( !this.markReadWhenSeen || !this.popup.isVisible() || unreadCount < this.currentUnreadCountInBadge ) {
|
||||||
this.badgeButton.setLabel( mw.language.convertNumber( unreadCount ) );
|
wgEchoMaxNotificationCount = mw.config.get( 'wgEchoMaxNotificationCount' );
|
||||||
|
if ( unreadCount > wgEchoMaxNotificationCount ) {
|
||||||
|
badgeLabel = mw.message( 'echo-notification-count', wgEchoMaxNotificationCount ).text();
|
||||||
|
} else {
|
||||||
|
badgeLabel = mw.language.convertNumber( unreadCount );
|
||||||
|
}
|
||||||
|
this.badgeButton.setLabel( badgeLabel );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we need to display the 'mark all unread' button
|
// Check if we need to display the 'mark all unread' button
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
this.resetLoadingOption( mw.msg( 'echo-notification-placeholder' ) );
|
this.resetLoadingOption( mw.msg( 'echo-notification-placeholder' ) );
|
||||||
} else {
|
} else {
|
||||||
// If failure, check if the failure is due to login
|
// If failure, check if the failure is due to login
|
||||||
// so we can display a more complrehensive error
|
// so we can display a more comprehensive error
|
||||||
// message in that case
|
// message in that case
|
||||||
if ( result.errCode === 'notlogin-required' ) {
|
if ( result.errCode === 'notlogin-required' ) {
|
||||||
// Login error
|
// Login error
|
||||||
|
|
|
@ -40,7 +40,8 @@
|
||||||
return b.getId() - a.getId();
|
return b.getId() - a.getId();
|
||||||
} );
|
} );
|
||||||
this.aggregate( {
|
this.aggregate( {
|
||||||
empty: 'groupEmpty'
|
empty: 'groupEmpty',
|
||||||
|
itemRead: 'groupItemRead'
|
||||||
} );
|
} );
|
||||||
this.connect( this, {
|
this.connect( this, {
|
||||||
groupEmpty: 'onGroupEmpty'
|
groupEmpty: 'onGroupEmpty'
|
||||||
|
@ -50,7 +51,7 @@
|
||||||
this.sources = sources;
|
this.sources = sources;
|
||||||
this.networkHandler = networkHandler;
|
this.networkHandler = networkHandler;
|
||||||
this.notifModels = {};
|
this.notifModels = {};
|
||||||
this.count = config.count || 0;
|
this.anticipatedCount = config.count || 0;
|
||||||
|
|
||||||
// Create notification models for each source
|
// Create notification models for each source
|
||||||
for ( source in this.sources ) {
|
for ( source in this.sources ) {
|
||||||
|
@ -88,12 +89,18 @@
|
||||||
* @event empty
|
* @event empty
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of item read in a group changed
|
||||||
|
*
|
||||||
|
* @event groupItemRead
|
||||||
|
*/
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Respond to notification model being empty
|
* Respond to notification model being empty
|
||||||
*
|
*
|
||||||
* @param {mw.echo.dm.NotificationModel} notifModel Notification model
|
* @param {mw.echo.dm.NotificationsModel} notifModel Notifications model
|
||||||
*/
|
*/
|
||||||
mw.echo.dm.NotificationGroupItem.prototype.onGroupEmpty = function ( notifModel ) {
|
mw.echo.dm.NotificationGroupItem.prototype.onGroupEmpty = function ( notifModel ) {
|
||||||
if ( this.removeReadNotifications ) {
|
if ( this.removeReadNotifications ) {
|
||||||
|
@ -130,6 +137,9 @@
|
||||||
|
|
||||||
// Wait for all fetch processes to finish before we resolve this promise
|
// Wait for all fetch processes to finish before we resolve this promise
|
||||||
return mw.echo.dm.NetworkHandler.static.waitForAllPromises( fetchPromises );
|
return mw.echo.dm.NetworkHandler.static.waitForAllPromises( fetchPromises );
|
||||||
|
} )
|
||||||
|
.then( function () {
|
||||||
|
model.anticipatedCount = null;
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -208,12 +218,20 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the anticipated count of items in this group item
|
* Get the anticipated count of items in this group item,
|
||||||
|
* or actual count if is has been loaded.
|
||||||
*
|
*
|
||||||
* @return {number} Anticipated item count
|
* @return {number} count
|
||||||
*/
|
*/
|
||||||
mw.echo.dm.NotificationGroupItem.prototype.getCount = function () {
|
mw.echo.dm.NotificationGroupItem.prototype.getCount = function () {
|
||||||
return this.count;
|
if ( this.anticipatedCount !== null ) {
|
||||||
|
return this.anticipatedCount;
|
||||||
|
}
|
||||||
|
var sum = 0;
|
||||||
|
this.getItems().forEach( function ( notificationsModel ) {
|
||||||
|
sum += notificationsModel.getUnreadCount();
|
||||||
|
} );
|
||||||
|
return sum;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -264,4 +264,13 @@
|
||||||
mw.echo.dm.NotificationItem.prototype.getSource = function () {
|
mw.echo.dm.NotificationItem.prototype.getSource = function () {
|
||||||
return this.source;
|
return this.source;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of notifications represented by this object
|
||||||
|
*
|
||||||
|
* @return {number} Notification count
|
||||||
|
*/
|
||||||
|
mw.echo.dm.NotificationItem.prototype.getCount = function () {
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
}( mediaWiki, jQuery ) );
|
}( mediaWiki, jQuery ) );
|
||||||
|
|
|
@ -23,4 +23,21 @@
|
||||||
OO.initClass( mw.echo.dm.NotificationList );
|
OO.initClass( mw.echo.dm.NotificationList );
|
||||||
OO.mixinClass( mw.echo.dm.NotificationList, OO.EventEmitter );
|
OO.mixinClass( mw.echo.dm.NotificationList, OO.EventEmitter );
|
||||||
OO.mixinClass( mw.echo.dm.NotificationList, mw.echo.dm.List );
|
OO.mixinClass( mw.echo.dm.NotificationList, mw.echo.dm.List );
|
||||||
|
|
||||||
|
/* Methods */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count the number of notifications by asking all contained objects
|
||||||
|
* how many notifications they each represent. Some are single, some
|
||||||
|
* are groups.
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
mw.echo.dm.NotificationList.prototype.getNotificationCount = function () {
|
||||||
|
var sum = 0;
|
||||||
|
this.getItems().forEach( function ( notificationItem ) {
|
||||||
|
sum += notificationItem.getCount();
|
||||||
|
} );
|
||||||
|
return sum;
|
||||||
|
};
|
||||||
|
|
||||||
} )( mediaWiki );
|
} )( mediaWiki );
|
||||||
|
|
|
@ -55,7 +55,8 @@
|
||||||
this.aggregate( {
|
this.aggregate( {
|
||||||
seen: 'itemSeen',
|
seen: 'itemSeen',
|
||||||
read: 'itemRead',
|
read: 'itemRead',
|
||||||
empty: 'itemGroupEmpty'
|
empty: 'itemGroupEmpty',
|
||||||
|
groupItemRead: 'unreadChange'
|
||||||
} );
|
} );
|
||||||
|
|
||||||
this.connect( this, {
|
this.connect( this, {
|
||||||
|
@ -221,6 +222,7 @@
|
||||||
// In this case, the notification is a "cross wiki" notification, which
|
// In this case, the notification is a "cross wiki" notification, which
|
||||||
// goes away when it is empty
|
// goes away when it is empty
|
||||||
this.removeItems( [ item ] );
|
this.removeItems( [ item ] );
|
||||||
|
this.emit( 'unreadChange' );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -257,7 +259,7 @@
|
||||||
* @return {number} Number of unseen notifications
|
* @return {number} Number of unseen notifications
|
||||||
*/
|
*/
|
||||||
mw.echo.dm.NotificationsModel.prototype.getUnseenCount = function () {
|
mw.echo.dm.NotificationsModel.prototype.getUnseenCount = function () {
|
||||||
return this.unseenNotifications.getItemCount();
|
return this.unseenNotifications.getNotificationCount();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -266,7 +268,7 @@
|
||||||
* @return {number} Number of unread notifications
|
* @return {number} Number of unread notifications
|
||||||
*/
|
*/
|
||||||
mw.echo.dm.NotificationsModel.prototype.getUnreadCount = function () {
|
mw.echo.dm.NotificationsModel.prototype.getUnreadCount = function () {
|
||||||
return this.unreadNotifications.getItemCount();
|
return this.unreadNotifications.getNotificationCount();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue