2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* A container that manages all models that are involved in creating
|
|
|
|
* the notification list. There are currently two types of models:
|
|
|
|
* * mw.echo.dm.SortedList - This currently includes the local model
|
|
|
|
* or any model that has individual messages.
|
|
|
|
* * mw.echo.dm.CrossWikiNotificationItem - This is a model for the
|
|
|
|
* cross wiki notification, which acts as an item but itself contains
|
|
|
|
* a list.
|
|
|
|
*
|
2016-05-31 00:12:31 +00:00
|
|
|
* All notification models that are managed by the manager must implement the
|
|
|
|
* following methods:
|
2016-06-08 23:53:20 +00:00
|
|
|
* * getName - This should retrieve the model's name for the manager to fetch
|
2016-04-10 13:31:02 +00:00
|
|
|
* * isGroup - This should be true for xwiki model and local bundles
|
|
|
|
* * hasUnseen - This should iterate in the model's items and check whether
|
|
|
|
* there are any unseen notifications within them.
|
2016-05-31 00:12:31 +00:00
|
|
|
* * getCount - Get a total count of available notifications currently in the model
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @mixins OO.EventEmitter
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {mw.echo.dm.UnreadNotificationCounter} counter Unread counter
|
|
|
|
* @param {Object} [config] Configuration object
|
|
|
|
* @cfg {string|string[]} [type="message"] The type of the notifications in
|
|
|
|
* the models that this manager handles.
|
2016-07-14 00:03:57 +00:00
|
|
|
* @cfg {number} [itemsPerPage=25] Number of items per page
|
2017-04-19 13:13:11 +00:00
|
|
|
* @cfg {string} [readState] Notifications read state. Pass through to mw.echo.dm.FiltersModel
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager = function MwEchoDmModelManager( counter, config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Mixin constructor
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
|
|
|
this.counter = counter;
|
|
|
|
// Keep types in an array
|
|
|
|
this.types = config.type || 'message';
|
|
|
|
this.types = Array.isArray( this.types ) ?
|
|
|
|
config.type : [ this.types ];
|
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
this.seenTimeModel = new mw.echo.dm.SeenTimeModel( { types: this.types } );
|
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
this.notificationModels = {};
|
2016-07-14 00:03:57 +00:00
|
|
|
this.paginationModel = new mw.echo.dm.PaginationModel( {
|
|
|
|
itemsPerPage: config.itemsPerPage || 25
|
|
|
|
} );
|
2016-05-31 22:32:16 +00:00
|
|
|
this.filtersModel = new mw.echo.dm.FiltersModel( {
|
2017-04-19 13:13:11 +00:00
|
|
|
selectedSource: 'local',
|
|
|
|
readState: config.readState
|
2016-05-31 22:32:16 +00:00
|
|
|
} );
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
// Events
|
|
|
|
this.seenTimeModel.connect( this, { update: 'onSeenTimeUpdate' } );
|
2016-06-29 23:36:03 +00:00
|
|
|
|
|
|
|
this.localCounter = config.localCounter || new mw.echo.dm.UnreadNotificationCounter();
|
|
|
|
this.localCounter.connect( this, { countChange: [ 'emit', 'localCountChange' ] } );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
OO.initClass( mw.echo.dm.ModelManager );
|
|
|
|
OO.mixinClass( mw.echo.dm.ModelManager, OO.EventEmitter );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event update
|
2016-03-16 22:47:20 +00:00
|
|
|
* @param {Object[]} Current available notifications
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
|
|
|
* The model has been rebuilt or has been updated
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2016-07-14 00:03:57 +00:00
|
|
|
* @event discard
|
|
|
|
* @param {string} modelId Discard model id
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
2016-07-14 00:03:57 +00:00
|
|
|
* A model has been permanently removed
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event seen
|
2016-07-08 22:56:01 +00:00
|
|
|
* @param {string} source Source where seenTime was updated
|
2016-07-22 18:59:10 +00:00
|
|
|
* @param {number} timestamp The new seen timestamp, as a full UTC ISO 8601 timestamp
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
2016-07-22 18:59:10 +00:00
|
|
|
* All notifications in that source are seen
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event allTalkRead
|
|
|
|
*
|
|
|
|
* There are no more local talk page notifications
|
|
|
|
*/
|
|
|
|
|
2016-07-14 00:03:57 +00:00
|
|
|
/**
|
|
|
|
* @event modelItemUpdate
|
|
|
|
* @param {string} modelId Model ID
|
|
|
|
* @param {mw.echo.dm.NotificationItem} item Updated item
|
|
|
|
*
|
|
|
|
* A specific item inside a notifications model has been updated
|
|
|
|
*/
|
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
/**
|
|
|
|
* @event localCountChange
|
|
|
|
*
|
|
|
|
* There was a change in the count of local unread notifications
|
|
|
|
*/
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
/**
|
|
|
|
* Respond to seen time change for a given source
|
|
|
|
*
|
2016-07-22 18:59:10 +00:00
|
|
|
* @param {string} timestamp Seen time, as a full UTC ISO 8601 timestamp
|
2016-09-13 23:18:29 +00:00
|
|
|
* @fires seen
|
2016-07-08 22:56:01 +00:00
|
|
|
*/
|
2016-09-13 23:18:29 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.onSeenTimeUpdate = function ( timestamp ) {
|
|
|
|
var modelId,
|
|
|
|
models = this.getAllNotificationModels();
|
|
|
|
|
|
|
|
for ( modelId in models ) {
|
|
|
|
models[ modelId ].updateSeenState( timestamp );
|
|
|
|
}
|
2016-07-08 22:56:01 +00:00
|
|
|
|
2016-09-13 23:18:29 +00:00
|
|
|
this.emit( 'seen', timestamp );
|
2016-07-08 22:56:01 +00:00
|
|
|
};
|
|
|
|
|
2016-07-14 00:03:57 +00:00
|
|
|
/**
|
|
|
|
* Respond to a notification model discarding items.
|
|
|
|
*
|
|
|
|
* @param {string} modelId Model name
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.onModelDiscardItems = function ( modelId ) {
|
|
|
|
var model = this.getNotificationModel( modelId );
|
|
|
|
|
|
|
|
// If the model is empty, remove it
|
|
|
|
if ( model.isEmpty() ) {
|
|
|
|
this.removeNotificationModel( modelId );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
2016-03-16 22:47:20 +00:00
|
|
|
* Get the notifications
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
2016-03-16 22:47:20 +00:00
|
|
|
* @return {Object} Object of notification models and their symbolic names
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
2016-03-16 22:47:20 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.getAllNotificationModels = function () {
|
|
|
|
return this.notificationModels;
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the models in the manager.
|
|
|
|
*
|
|
|
|
* @param {Object} modelDefinitions An object defining the models
|
|
|
|
* The format for the definition object is:
|
|
|
|
* {
|
2018-11-27 22:48:32 +00:00
|
|
|
* 'modelId': {mw.echo.dm.SortedList},
|
|
|
|
* ...
|
2016-04-10 13:31:02 +00:00
|
|
|
* }
|
|
|
|
*/
|
2016-03-16 22:47:20 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.setNotificationModels = function ( modelDefinitions ) {
|
2016-07-14 00:03:57 +00:00
|
|
|
var modelId;
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
this.resetNotificationModels();
|
2016-04-10 13:31:02 +00:00
|
|
|
|
|
|
|
for ( modelId in modelDefinitions ) {
|
2016-03-16 22:47:20 +00:00
|
|
|
this.notificationModels[ modelId ] = modelDefinitions[ modelId ];
|
2016-07-14 00:03:57 +00:00
|
|
|
this.notificationModels[ modelId ].connect( this, {
|
|
|
|
discard: [ 'onModelDiscardItems', modelId ],
|
|
|
|
itemUpdate: [ 'onModelItemUpdate', modelId ]
|
|
|
|
} );
|
2016-04-10 13:31:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-14 00:03:57 +00:00
|
|
|
// Update pagination count
|
|
|
|
this.updateCurrentPageItemCount();
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
this.emit( 'update', this.getAllNotificationModels() );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
/**
|
|
|
|
* Respond to model update event
|
|
|
|
*
|
|
|
|
* @param {string} modelName Model name
|
|
|
|
* @param {mw.echo.dm.notificationItem} item Notification item
|
|
|
|
* @fires modelUpdate
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.onModelItemUpdate = function ( modelName, item ) {
|
|
|
|
this.checkLocalUnreadTalk();
|
2016-07-14 00:03:57 +00:00
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
this.emit( 'modelItemUpdate', modelName, item );
|
2016-07-14 00:03:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the current page item count based on available items
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.updateCurrentPageItemCount = function () {
|
|
|
|
this.getPaginationModel().setCurrentPageItemCount( this.getAllNotificationCount() );
|
|
|
|
};
|
|
|
|
|
2016-05-31 00:12:31 +00:00
|
|
|
/**
|
|
|
|
* Go over all the notification models and return the total number of
|
|
|
|
* available notifications.
|
|
|
|
*
|
|
|
|
* @return {number} A count of all notifications
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getAllNotificationCount = function () {
|
|
|
|
var model,
|
|
|
|
count = 0,
|
|
|
|
models = this.getAllNotificationModels();
|
|
|
|
|
|
|
|
for ( model in models ) {
|
|
|
|
count += models[ model ].getCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
};
|
2016-06-29 23:36:03 +00:00
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Get a notification model.
|
|
|
|
*
|
|
|
|
* @param {string} modelName Unique model name
|
|
|
|
* @return {mw.echo.dm.SortedList} Notifications model
|
|
|
|
*/
|
2016-03-16 22:47:20 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.getNotificationModel = function ( modelName ) {
|
|
|
|
return this.notificationModels[ modelName ];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the pagination model
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.PaginationModel} Pagination model
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getPaginationModel = function () {
|
|
|
|
return this.paginationModel;
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
2016-05-20 04:22:41 +00:00
|
|
|
/**
|
|
|
|
* Get the filters model
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.FiltersModel} Filters model
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getFiltersModel = function () {
|
|
|
|
return this.filtersModel;
|
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Remove a model from the manager
|
|
|
|
*
|
|
|
|
* @param {string} modelName Symbolic name of the model
|
|
|
|
* @fires remove
|
|
|
|
*/
|
2016-03-16 22:47:20 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.removeNotificationModel = function ( modelName ) {
|
|
|
|
delete this.notificationModels[ modelName ];
|
2016-07-14 00:03:57 +00:00
|
|
|
|
|
|
|
this.emit( 'discard', modelName );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset all models
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
2016-03-16 22:47:20 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.resetNotificationModels = function () {
|
2016-04-10 13:31:02 +00:00
|
|
|
var model;
|
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
for ( model in this.notificationModels ) {
|
2018-09-11 22:46:52 +00:00
|
|
|
if ( Object.prototype.hasOwnProperty.call( this.notificationModels, model ) ) {
|
2016-03-16 22:47:20 +00:00
|
|
|
this.notificationModels[ model ].disconnect( this );
|
|
|
|
delete this.notificationModels[ model ];
|
2016-04-10 13:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the unread notification counter
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.UnreadNotificationCounter} Unread notification counter
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getUnreadCounter = function () {
|
|
|
|
return this.counter;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the local model has any unread notifications.
|
|
|
|
*
|
|
|
|
* @return {boolean} Local model has unread notifications.
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.hasLocalUnread = function () {
|
2016-06-07 20:08:16 +00:00
|
|
|
var isUnread = function ( item ) {
|
2016-11-18 21:16:43 +00:00
|
|
|
return !item.isRead();
|
|
|
|
};
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
return this.getLocalNotifications().some( isUnread );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
2016-09-06 20:07:57 +00:00
|
|
|
/**
|
|
|
|
* Get local unread notifications
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.NotificationItem[]} Local unread notifications
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getLocalUnread = function () {
|
|
|
|
var isUnread = function ( item ) {
|
2016-11-18 21:16:43 +00:00
|
|
|
return !item.isRead();
|
|
|
|
};
|
2016-09-06 20:07:57 +00:00
|
|
|
|
|
|
|
return this.getLocalNotifications().filter( isUnread );
|
|
|
|
};
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Check whether there are talk notifications, and emit an event
|
|
|
|
* in case there aren't any left.
|
|
|
|
*
|
|
|
|
* @fires allTalkRead
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.checkLocalUnreadTalk = function () {
|
|
|
|
if ( !this.hasLocalUnreadTalk() ) {
|
|
|
|
this.emit( 'allTalkRead' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the local model has any unread talk page notifications.
|
|
|
|
*
|
|
|
|
* @return {boolean} Local model has unread talk page notifications.
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.hasLocalUnreadTalk = function () {
|
2016-06-07 20:08:16 +00:00
|
|
|
var isUnreadUserTalk = function ( item ) {
|
2016-11-18 21:16:43 +00:00
|
|
|
return !item.isRead() && item.getCategory() === 'edit-user-talk';
|
|
|
|
};
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
return this.getLocalNotifications().some( isUnreadUserTalk );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a model has any unseen notifications.
|
|
|
|
*
|
|
|
|
* @param {string} modelId Model ID
|
|
|
|
* @return {boolean} The given model has unseen notifications.
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.hasUnseenInModel = function ( modelId ) {
|
2016-03-16 22:47:20 +00:00
|
|
|
var model = this.getNotificationModel( modelId || 'local' );
|
2016-04-10 13:31:02 +00:00
|
|
|
|
|
|
|
return model && model.hasUnseen();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-07-08 22:56:01 +00:00
|
|
|
* Check if a model has any unseen notifications.
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
2016-07-08 22:56:01 +00:00
|
|
|
* @param {string} [source='local'] Model source
|
|
|
|
* @return {boolean} The given models has unseen notifications.
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
2016-07-08 22:56:01 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.hasUnseenInSource = function ( source ) {
|
|
|
|
var i, modelNames;
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
source = source || 'local';
|
|
|
|
modelNames = this.getModelsBySource( source );
|
|
|
|
|
|
|
|
for ( i = 0; i < modelNames.length; i++ ) {
|
|
|
|
if ( this.getNotificationModel( modelNames[ i ] ).hasUnseen() ) {
|
2016-04-10 13:31:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-07-08 22:56:01 +00:00
|
|
|
* Check if there are unseen notifications in any of the models
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
2016-07-08 22:56:01 +00:00
|
|
|
* @return {boolean} Local model has unseen notifications.
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
2016-07-08 22:56:01 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.hasUnseenInAnyModel = function () {
|
|
|
|
var model,
|
|
|
|
models = this.getAllNotificationModels();
|
2016-04-10 13:31:02 +00:00
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
for ( model in models ) {
|
|
|
|
if ( models[ model ].hasUnseen() ) {
|
|
|
|
return true;
|
2016-04-10 13:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
return false;
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the system seen time
|
|
|
|
*
|
2016-07-08 22:56:01 +00:00
|
|
|
* @param {string} [source='local'] Seen time source
|
2016-07-22 18:59:10 +00:00
|
|
|
* @return {string} Seen time, as a full UTC ISO 8601 timestamp
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
2016-07-08 22:56:01 +00:00
|
|
|
mw.echo.dm.ModelManager.prototype.getSeenTime = function ( source ) {
|
|
|
|
return this.getSeenTimeModel().getSeenTime( source );
|
2016-04-10 13:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the array of model types
|
|
|
|
*
|
|
|
|
* @return {string[]} Model types
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getTypes = function () {
|
|
|
|
return this.types;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the model types string; 'message', 'alert', or 'all'
|
|
|
|
*
|
|
|
|
* @return {string} Model types
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getTypeString = function () {
|
|
|
|
return (
|
|
|
|
this.types.length === 1 ?
|
|
|
|
this.types[ 0 ] :
|
|
|
|
'all'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2016-06-29 23:36:03 +00:00
|
|
|
/**
|
|
|
|
* Get the local counter
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.UnreadNotificationCounter} Local counter
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getLocalCounter = function () {
|
|
|
|
return this.localCounter;
|
|
|
|
};
|
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
/**
|
|
|
|
* Get all local notifications
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.NotificationItem[]} all local notifications
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getLocalNotifications = function () {
|
2016-07-08 22:56:01 +00:00
|
|
|
return this.getNotificationsBySource( 'local' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all notifications that come from a given source
|
|
|
|
*
|
2016-11-18 21:16:43 +00:00
|
|
|
* @param {string} [source='local'] Source name
|
|
|
|
* @return {mw.echo.dm.NotificationItem[]} All notifications from that source
|
2016-07-08 22:56:01 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getNotificationsBySource = function ( source ) {
|
2016-06-07 20:08:16 +00:00
|
|
|
var notifications = [],
|
|
|
|
manager = this;
|
2016-07-08 22:56:01 +00:00
|
|
|
|
|
|
|
source = source || 'local';
|
|
|
|
|
2016-06-07 20:08:16 +00:00
|
|
|
Object.keys( this.getAllNotificationModels() ).forEach( function ( modelName ) {
|
|
|
|
var model = manager.getNotificationModel( modelName );
|
2016-07-08 22:56:01 +00:00
|
|
|
if ( model.getSource() === source ) {
|
2016-06-07 20:08:16 +00:00
|
|
|
notifications = notifications.concat( model.getItems() );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return notifications;
|
|
|
|
};
|
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
/**
|
|
|
|
* Get all models that have a specific source
|
|
|
|
*
|
|
|
|
* @param {string} [source='local'] Given source
|
|
|
|
* @return {string[]} All model IDs that use this source
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getModelsBySource = function ( source ) {
|
|
|
|
var modelIds = [],
|
|
|
|
manager = this;
|
|
|
|
|
|
|
|
source = source || 'local';
|
|
|
|
|
|
|
|
Object.keys( this.getAllNotificationModels() ).forEach( function ( modelName ) {
|
|
|
|
var model = manager.getNotificationModel( modelName );
|
|
|
|
if ( model.getSource() === source ) {
|
|
|
|
modelIds.push( modelName );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return modelIds;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the SeenTime model
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.SeenTimeModel} SeenTime model
|
|
|
|
*/
|
|
|
|
mw.echo.dm.ModelManager.prototype.getSeenTimeModel = function () {
|
|
|
|
return this.seenTimeModel;
|
2016-06-29 23:36:03 +00:00
|
|
|
|
2016-07-08 22:56:01 +00:00
|
|
|
};
|
|
|
|
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|