Debian Codegraph @

extensions/Echo/modules/model/mw.echo.dm.SeenTimeModel.js

raw symbols SCIP
1 ( function () {
2 /**
3 * SeenTime model for Echo notifications
4 *
5 * @param {Object} [config] Configuration
6 * @param {string|string[]} [config.types='alert','message'] The types of notifications
7 * that this model handles
8 */
9 mw.echo.dm.SeenTimeModel = function MwEchoSeenTimeModel( config ) {
10 config = config || {};
11
12 // Mixin constructor
13 OO.EventEmitter.call( this );
14
15 this.types = [ 'alert', 'message' ];
16 if ( config.types ) {
17 this.types = Array.isArray( config.types ) ? config.types : [ config.types ];
18 }
19
20 this.seenTime = mw.config.get( 'wgEchoSeenTime' ) || {};
21 };
22
23 /* Initialization */
24
25 OO.initClass( mw.echo.dm.SeenTimeModel );
26 OO.mixinClass( mw.echo.dm.SeenTimeModel, OO.EventEmitter );
27
28 /* Events */
29
30 /**
31 * Seen time has been updated for the given source
32 *
33 * @event mw.echo.dm.SeenTimeModel#update
34 * @param {string} time Seen time, as a full UTC ISO 8601 timestamp.
35 */
36
37 /* Methods */
38
39 /**
40 * Get the global seenTime value
41 *
42 * @return {string} Seen time, as a full UTC ISO 8601 timestamp.
43 */
44 mw.echo.dm.SeenTimeModel.prototype.getSeenTime = function () {
45 return this.seenTime[ this.getTypes()[ 0 ] ] || 0;
46 };
47
48 /**
49 * Set the seen time value for the source
50 *
51 * @internal
52 * @param {string} time Seen time, as a full UTC ISO 8601 timestamp.
53 * @fires mw.echo.dm.SeenTimeModel#update
54 */
55 mw.echo.dm.SeenTimeModel.prototype.setSeenTime = function ( time ) {
56 let hasChanged = false;
57 this.getTypes().forEach( ( type ) => {
58 if ( this.seenTime[ type ] !== time ) {
59 this.seenTime[ type ] = time;
60 hasChanged = true;
61 }
62 } );
63
64 if ( hasChanged ) {
65 this.emit( 'update', time );
66 }
67 };
68
69 /**
70 * Get the types associated with this model
71 *
72 * @internal
73 * @return {string[]} Types for this model; an array of 'alert', 'message' or both.
74 */
75 mw.echo.dm.SeenTimeModel.prototype.getTypes = function () {
76 return this.types;
77 };
78
79 }() );