2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Cross-wiki notification item model. Contains a list of sources,
|
|
|
|
* that each contain a list of notification items from that source.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends mw.echo.dm.NotificationItem
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {number} id Notification id
|
|
|
|
* @param {Object} [config] Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {number} config.count The initial anticipated count of notifications through all
|
2016-04-10 13:31:02 +00:00
|
|
|
* of the sources.
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem = function MwEchoDmCrossWikiNotificationItem( id, config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.dm.CrossWikiNotificationItem.super.call( this, id, config );
|
2016-04-10 13:31:02 +00:00
|
|
|
|
|
|
|
this.foreign = true;
|
2016-07-08 22:56:01 +00:00
|
|
|
this.source = null;
|
2016-04-10 13:31:02 +00:00
|
|
|
this.count = config.count || 0;
|
2016-09-16 00:05:04 +00:00
|
|
|
this.modelName = config.modelName || 'xwiki';
|
2016-04-10 13:31:02 +00:00
|
|
|
|
|
|
|
this.list = new mw.echo.dm.NotificationGroupsList();
|
|
|
|
|
2016-07-14 00:03:57 +00:00
|
|
|
this.list.connect( this, { discard: 'onListDiscard' } );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.dm.CrossWikiNotificationItem, mw.echo.dm.NotificationItem );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
2016-07-14 00:03:57 +00:00
|
|
|
* A sub list has been discarded
|
2024-04-30 14:21:54 +00:00
|
|
|
*
|
|
|
|
* @event mw.echo.dm.CrossWikiNotificationItem#discard
|
|
|
|
* @param {string} name The symbolic name for the list model that was discarded
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to list being removed from the cross-wiki bundle.
|
|
|
|
*
|
|
|
|
* @param {mw.echo.dm.NotificationGroupsList} sourceModel The source model that was removed
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.dm.CrossWikiNotificationItem#discard
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
2016-07-14 00:03:57 +00:00
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.onListDiscard = function ( sourceModel ) {
|
|
|
|
this.emit( 'discard', sourceModel.getName() );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of sources
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.NotificationGroupsList} List of sources
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.getList = function () {
|
|
|
|
return this.list;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an array of source names that are in the cross-wiki list
|
|
|
|
*
|
|
|
|
* @return {string[]} Source names
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.getSourceNames = function () {
|
2024-06-03 12:22:48 +00:00
|
|
|
const sourceNames = [],
|
2016-04-10 13:31:02 +00:00
|
|
|
sourceLists = this.list.getItems();
|
|
|
|
|
2024-06-03 12:22:48 +00:00
|
|
|
for ( let i = 0; i < sourceLists.length; i++ ) {
|
2016-06-08 23:53:20 +00:00
|
|
|
sourceNames.push( sourceLists[ i ].getName() );
|
2016-04-10 13:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sourceNames;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a specific item from the list by its source name
|
|
|
|
*
|
|
|
|
* @param {string} sourceName Source name
|
|
|
|
* @return {mw.echo.dm.NotificationGroupsList} Source item
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.getItemBySource = function ( sourceName ) {
|
2016-07-14 00:03:57 +00:00
|
|
|
return this.list.getGroupByName( sourceName );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get expected item count from all sources
|
|
|
|
*
|
|
|
|
* @return {number} Item count
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.getCount = function () {
|
|
|
|
return this.count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if there are unseen items in any of the cross wiki source lists.
|
|
|
|
* This method is required for all models that are managed by the
|
|
|
|
* mw.echo.dm.ModelManager.
|
|
|
|
*
|
|
|
|
* @return {boolean} There are unseen items
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.hasUnseen = function () {
|
2024-06-03 12:22:48 +00:00
|
|
|
const sourceLists = this.getList().getItems();
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2024-06-03 12:22:48 +00:00
|
|
|
for ( let i = 0; i < sourceLists.length; i++ ) {
|
|
|
|
const items = sourceLists[ i ].getItems();
|
|
|
|
for ( let j = 0; j < items.length; j++ ) {
|
2016-04-10 13:31:02 +00:00
|
|
|
if ( !items[ j ].isSeen() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2016-09-13 23:18:29 +00:00
|
|
|
/**
|
|
|
|
* Set all notifications in all groups to seen
|
|
|
|
*
|
|
|
|
* @param {number} timestamp New seen timestamp
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.updateSeenState = function ( timestamp ) {
|
2024-06-03 12:26:18 +00:00
|
|
|
this.getList().getItems().forEach( ( source ) => {
|
|
|
|
source.getItems().forEach( ( notification ) => {
|
2016-09-13 23:18:29 +00:00
|
|
|
notification.toggleSeen(
|
|
|
|
notification.isRead() || notification.getTimestamp() < timestamp
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
/**
|
|
|
|
* Get all items in the cross wiki notification bundle
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.NotificationItem[]} All items across all sources
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.getItems = function () {
|
2024-06-03 12:22:48 +00:00
|
|
|
let notifications = [];
|
2024-06-03 12:26:18 +00:00
|
|
|
this.list.getItems().forEach( ( sourceList ) => {
|
2016-06-29 23:36:03 +00:00
|
|
|
notifications = notifications.concat( sourceList.getItems() );
|
|
|
|
} );
|
|
|
|
|
|
|
|
return notifications;
|
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* This item is a group.
|
|
|
|
* This method is required for all models that are managed by the
|
|
|
|
* mw.echo.dm.ModelManager.
|
|
|
|
*
|
|
|
|
* @return {boolean} This item is a group
|
|
|
|
*/
|
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.isGroup = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2016-07-14 00:03:57 +00:00
|
|
|
mw.echo.dm.CrossWikiNotificationItem.prototype.isEmpty = function () {
|
|
|
|
return this.getList().isEmpty();
|
|
|
|
};
|
|
|
|
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|