2016-07-08 22:56:01 +00:00
|
|
|
( function ( mw ) {
|
|
|
|
/**
|
|
|
|
* SeenTime model for Echo notifications
|
|
|
|
*
|
|
|
|
* @param {Object} [config] Configuration
|
|
|
|
* @cfg {string|string[]} [types='alert','message'] The types of notifications
|
|
|
|
* that this model handles
|
|
|
|
*/
|
|
|
|
mw.echo.dm.SeenTimeModel = function MwEchoSeenTimeModel( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Mixin constructor
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
|
|
|
this.types = [ 'alert', 'message' ];
|
|
|
|
if ( config.types ) {
|
|
|
|
this.types = Array.isArray( config.types ) ? config.types : [ config.types ];
|
|
|
|
}
|
|
|
|
|
2016-09-13 23:18:29 +00:00
|
|
|
this.seenTime = mw.config.get( 'wgEchoSeenTime' ) || {};
|
2016-07-08 22:56:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.initClass( mw.echo.dm.SeenTimeModel );
|
|
|
|
OO.mixinClass( mw.echo.dm.SeenTimeModel, OO.EventEmitter );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event update
|
2016-07-22 18:59:10 +00:00
|
|
|
* @param {string} time Seen time, as a full UTC ISO 8601 timestamp.
|
2016-07-08 22:56:01 +00:00
|
|
|
*
|
|
|
|
* Seen time has been updated for the given source
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2016-09-13 23:18:29 +00:00
|
|
|
* Get the global seenTime value
|
2016-07-08 22:56:01 +00:00
|
|
|
*
|
2016-07-22 18:59:10 +00:00
|
|
|
* @return {string} Seen time, as a full UTC ISO 8601 timestamp.
|
2016-07-08 22:56:01 +00:00
|
|
|
*/
|
2016-09-13 23:18:29 +00:00
|
|
|
mw.echo.dm.SeenTimeModel.prototype.getSeenTime = function () {
|
|
|
|
return this.seenTime[ this.getTypes()[ 0 ] ] || 0;
|
2016-07-08 22:56:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the seen time value for the source
|
|
|
|
*
|
|
|
|
* @private
|
2016-07-22 18:59:10 +00:00
|
|
|
* @param {string} time Seen time, as a full UTC ISO 8601 timestamp.
|
2016-07-08 22:56:01 +00:00
|
|
|
* @fires update
|
|
|
|
*/
|
2016-09-13 23:18:29 +00:00
|
|
|
mw.echo.dm.SeenTimeModel.prototype.setSeenTime = function ( time ) {
|
2016-07-08 22:56:01 +00:00
|
|
|
var model = this,
|
|
|
|
hasChanged = false;
|
|
|
|
|
|
|
|
this.getTypes().forEach( function ( type ) {
|
2016-09-13 23:18:29 +00:00
|
|
|
if ( model.seenTime[ type ] !== time ) {
|
|
|
|
model.seenTime[ type ] = time;
|
2016-07-08 22:56:01 +00:00
|
|
|
hasChanged = true;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( hasChanged ) {
|
2016-09-13 23:18:29 +00:00
|
|
|
this.emit( 'update', time );
|
2016-07-08 22:56:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the types associated with this model
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @return {string[]} Types for this model; an array of 'alert', 'message' or both.
|
|
|
|
*/
|
|
|
|
mw.echo.dm.SeenTimeModel.prototype.getTypes = function () {
|
|
|
|
return this.types;
|
|
|
|
};
|
|
|
|
|
2016-11-18 21:16:43 +00:00
|
|
|
}( mediaWiki ) );
|