Debian Codegraph @

extensions/Echo/modules/controller/mw.echo.Controller.js

raw symbols SCIP
1 ( function () {
2 /* global moment:false */
3 /**
4 * Controller for Echo notifications
5 *
6 * @param {mw.echo.api.EchoApi} echoApi Echo API
7 * @param {mw.echo.dm.ModelManager} manager Model manager
8 */
9 mw.echo.Controller = function MwEchoController( echoApi, manager ) {
10 this.api = echoApi;
11 this.manager = manager;
12 };
13
14 /* Initialization */
15
16 OO.initClass( mw.echo.Controller );
17
18 /**
19 * Update a filter value.
20 * The method accepts a filter name and as many arguments
21 * as needed.
22 *
23 * @param {string} filter Filter name
24 */
25 mw.echo.Controller.prototype.setFilter = function ( filter ) {
26 const filtersModel = this.manager.getFiltersModel(),
27 values = Array.prototype.slice.call( arguments );
28
29 values.shift();
30
31 if ( filter === 'readState' ) {
32 filtersModel.setReadState( values[ 0 ] );
33 } else if ( filter === 'sourcePage' ) {
34 filtersModel.setCurrentSourcePage( values[ 0 ], values[ 1 ] );
35 this.manager.getLocalCounter().setSource( filtersModel.getSourcePagesModel().getCurrentSource() );
36 }
37
38 // Reset pagination
39 this.manager.getPaginationModel().reset();
40 };
41
42 /**
43 * Fetch the next page by date
44 *
45 * @return {jQuery.Promise} A promise that resolves with an object where the keys are
46 * days and the items are item IDs.
47 */
48 mw.echo.Controller.prototype.fetchNextPageByDate = function () {
49 this.manager.getPaginationModel().forwards();
50 return this.fetchLocalNotificationsByDate();
51 };
52
53 /**
54 * Fetch the previous page by date
55 *
56 * @return {jQuery.Promise} A promise that resolves with an object where the keys are
57 * days and the items are item IDs.
58 */
59 mw.echo.Controller.prototype.fetchPrevPageByDate = function () {
60 this.manager.getPaginationModel().backwards();
61 return this.fetchLocalNotificationsByDate();
62 };
63
64 /**
65 * Fetch the first page by date
66 *
67 * @return {jQuery.Promise} A promise that resolves with an object where the keys are
68 * days and the items are item IDs.
69 */
70 mw.echo.Controller.prototype.fetchFirstPageByDate = function () {
71 this.manager.getPaginationModel().setCurrPageIndex( 0 );
72 return this.fetchLocalNotificationsByDate();
73 };
74
75 /**
76 * Fetch unread pages in all wikis and create foreign API sources
77 * as needed.
78 *
79 * @return {jQuery.Promise} A promise that resolves when the page filter
80 * model is updated with the unread notification count per page per wiki
81 */
82 mw.echo.Controller.prototype.fetchUnreadPagesByWiki = function () {
83 const filterModel = this.manager.getFiltersModel(),
84 sourcePageModel = filterModel.getSourcePagesModel();
85
86 return this.api.fetchUnreadNotificationPages()
87 .then( ( data ) => {
88 const result = {},
89 foreignSources = {};
90
91 for ( const source in data ) {
92 if ( source !== mw.config.get( 'wgWikiID' ) ) {
93 // Collect sources for API
94 foreignSources[ source ] = data[ source ].source;
95 }
96 result[ source === mw.config.get( 'wgWikiID' ) ? 'local' : source ] = data[ source ];
97 }
98
99 // Register the foreign sources in the API
100 this.api.registerForeignSources( foreignSources, false );
101
102 // Register pages
103 sourcePageModel.setAllSources( result );
104 } );
105 };
106
107 /**
108 * Fetch notifications from the local API and sort them by date.
109 * This method ignores cross-wiki notifications and bundles.
110 *
111 * @param {number} [page] Page number. If not given, it defaults to the current
112 * page.
113 * @return {jQuery.Promise} A promise that resolves with an object where the keys are
114 * days and the items are item IDs.
115 */
116 mw.echo.Controller.prototype.fetchLocalNotificationsByDate = function ( page ) {
117 const pagination = this.manager.getPaginationModel(),
118 filters = this.manager.getFiltersModel(),
119 currentSource = filters.getSourcePagesModel().getCurrentSource(),
120 continueValue = pagination.getPageContinue( page || pagination.getCurrPageIndex() );
121
122 pagination.setItemsPerPage( this.api.getLimit() );
123
124 return this.api.fetchFilteredNotifications(
125 this.manager.getTypeString(),
126 currentSource,
127 {
128 continue: continueValue,
129 readState: filters.getReadState(),
130 titles: filters.getSourcePagesModel().getGroupedPagesForCurrentTitle()
131 }
132 )
133 .then( ( data ) => {
134 const dateItemIds = {},
135 dateItems = {},
136 models = {};
137
138 data = data || { list: [] };
139
140 // Go over the data
141 for ( let i = 0; i < data.list.length; i++ ) {
142 const notifData = data.list[ i ];
143
144 // Set source's seenTime
145 // TODO: This query brings up mixed alert and message notifications.
146 // Regularly, each of those will have a different seenTime that is
147 // calculated for each badge, but for this page, both are fetched.
148 // For the moment, we are picking the max seenTime from
149 // either alert or notice and updating both, since the page gives
150 // us a mixed view which will update both seenTime to be the same
151 // anyways.
152 const maxSeenTime = data.seenTime.alert < data.seenTime.notice ?
153 data.seenTime.notice : data.seenTime.alert;
154 this.manager.getSeenTimeModel().setSeenTime(
155 maxSeenTime
156 );
157
158 // Collect common data
159 const newNotifData = this.createNotificationData( notifData );
160 if ( notifData.type !== 'foreign' ) {
161 const localizedDate = moment.utc( newNotifData.timestamp ).local().format( 'YYYYMMDD' );
162
163 newNotifData.modelName = 'local_' + localizedDate;
164 newNotifData.source = currentSource;
165
166 // Single notifications
167 const itemModel = new mw.echo.dm.NotificationItem(
168 notifData.id,
169 newNotifData
170 );
171
172 dateItems[ localizedDate ] = dateItems[ localizedDate ] || [];
173 dateItems[ localizedDate ].push( itemModel );
174
175 dateItemIds[ localizedDate ] = dateItemIds[ localizedDate ] || [];
176 dateItemIds[ localizedDate ].push( notifData.id );
177 }
178 }
179
180 // Fill in the models
181 for ( const date in dateItems ) {
182 const symbolicName = 'local_' + date;
183
184 // Set up model
185 models[ symbolicName ] = new mw.echo.dm.NotificationsList( {
186 type: this.manager.getTypes(),
187 name: symbolicName,
188 source: currentSource,
189 title: date,
190 timestamp: date,
191 sortingCallback: function ( a, b ) {
192 // Reverse sorting. In the special page we want the
193 // items sorted only by timestamp, regardless of
194 // read/unread state
195 if ( b.getTimestamp() < a.getTimestamp() ) {
196 return -1;
197 } else if ( b.getTimestamp() > a.getTimestamp() ) {
198 return 1;
199 }
200
201 // Fallback on IDs
202 return b.getId() - a.getId();
203 }
204 } );
205 models[ symbolicName ].setItems( dateItems[ date ] );
206 }
207
208 // Register local sources
209 this.api.registerLocalSources( Object.keys( models ) );
210
211 // Update the manager
212 this.manager.setNotificationModels( models );
213
214 // Update the pagination
215 pagination.setNextPageContinue( data.continue );
216
217 // Update the local counter
218 this.manager.getLocalCounter().update();
219
220 return dateItemIds;
221 } )
222 .then(
223 null,
224 ( errCode, errObj ) => ( {
225 errCode: errCode,
226 errInfo: OO.getProp( errObj, 'error', 'info' )
227 } )
228 );
229 };
230 /**
231 * Fetch notifications from the local API and update the notifications list.
232 *
233 * @param {boolean} [isForced] Force a renewed fetching promise. If set to false, the
234 * model will request the stored/cached fetching promise from the API. A 'true' value
235 * will force the API to re-request that information from the server and update the
236 * notifications.
237 * @return {jQuery.Promise} A promise that resolves with an array of notification IDs
238 */
239 mw.echo.Controller.prototype.fetchLocalNotifications = function ( isForced ) {
240 // Create a new local list model
241 const localListModel = new mw.echo.dm.NotificationsList( {
242 type: this.manager.getTypes()
243 } ),
244 localItems = [],
245 idArray = [];
246
247 this.manager.counter.update();
248
249 // Fetch the notifications from the database
250 // Initially, we're going to have to split the operation
251 // between local notifications and x-wiki notifications
252 // until the backend gives us the x-wiki notifications as
253 // part of the original response.
254 return this.api.fetchNotifications( this.manager.getTypeString(), 'local', !!isForced, { unreadFirst: true, bundle: true } /* filters */ )
255 .then(
256 // Success
257 ( data ) => {
258 const allModels = { local: localListModel },
259 createBundledNotification = ( modelName, rawBundledNotifData ) => {
260 const bundleNotifData = this.createNotificationData( rawBundledNotifData );
261 bundleNotifData.bundled = true;
262 bundleNotifData.modelName = modelName;
263 return new mw.echo.dm.NotificationItem(
264 rawBundledNotifData.id,
265 bundleNotifData
266 );
267 };
268
269 data = data || { list: [] };
270
271 // Go over the data
272 for ( let i = 0; i < data.list.length; i++ ) {
273 const notifData = data.list[ i ];
274
275 // Set source's seenTime
276 this.manager.getSeenTimeModel().setSeenTime(
277 this.getTypes().length > 1 ?
278 (
279 data.seenTime.alert < data.seenTime.notice ?
280 data.seenTime.notice : data.seenTime.alert
281 ) :
282 data.seenTime[ this.getTypeString() ]
283 );
284
285 // Collect common data
286 const newNotifData = this.createNotificationData( notifData );
287 if ( notifData.type === 'foreign' ) {
288 // x-wiki notification multi-group
289 // We need to request a new list model
290 newNotifData.name = 'xwiki';
291 const foreignListModel = allModels.xwiki = new mw.echo.dm.CrossWikiNotificationItem( notifData.id, newNotifData );
292 foreignListModel.setForeign( true );
293
294 // Register foreign sources
295 this.api.registerForeignSources( notifData.sources, true );
296 // Add the lists according to the sources
297 for ( const source in notifData.sources ) {
298 foreignListModel.getList().addGroup(
299 source,
300 notifData.sources[ source ]
301 );
302 }
303
304 } else if ( Array.isArray( newNotifData.bundledNotifications ) ) {
305 // local bundle
306 newNotifData.modelName = 'bundle_' + notifData.id;
307 const itemModel = new mw.echo.dm.BundleNotificationItem(
308 notifData.id,
309 newNotifData.bundledNotifications.map( createBundledNotification.bind( null, newNotifData.modelName ) ),
310 newNotifData
311 );
312 allModels[ newNotifData.modelName ] = itemModel;
313 } else {
314 // Local single notifications
315 const itemModel = new mw.echo.dm.NotificationItem(
316 notifData.id,
317 newNotifData
318 );
319
320 idArray.push( notifData.id );
321 localItems.push( itemModel );
322
323 if ( newNotifData.bundledNotifications ) {
324 // This means that bundledNotifications is truthy
325 // but is not an array. We should log this in the console
326 mw.log.warn(
327 'newNotifData.bundledNotifications is expected to be an array,' +
328 'but instead received "' + typeof newNotifData.bundledNotifications + '"'
329 );
330 }
331 }
332
333 }
334
335 // Refresh local items
336 localListModel.addItems( localItems );
337
338 // Update the this
339 this.manager.setNotificationModels( allModels );
340
341 return idArray;
342 },
343 // Failure
344 ( errCode, errObj ) => {
345 if ( !this.manager.getNotificationModel( 'local' ) ) {
346 // Update the this
347 this.manager.setNotificationModels( { local: localListModel } );
348 }
349 return {
350 errCode: errCode,
351 errInfo: OO.getProp( errObj, 'error', 'info' )
352 };
353 }
354 );
355 };
356
357 /**
358 * Create notification data config object for notification items from the
359 * given API data.
360 *
361 * @param {Object} apiData API data
362 * @return {Object} Notification config data object
363 */
364 mw.echo.Controller.prototype.createNotificationData = function ( apiData ) {
365 const content = apiData[ '*' ] || {};
366
367 let utcTimestamp;
368 if ( apiData.timestamp.utciso8601 ) {
369 utcTimestamp = apiData.timestamp.utciso8601;
370 } else {
371 // Temporary until c05133283af0486e08c9a97a468bc075e238f2d2 rolls out to the
372 // whole WMF cluster
373 const utcIsoMoment = moment.utc( apiData.timestamp.utcunix * 1000 );
374 utcTimestamp = utcIsoMoment.format( 'YYYY-MM-DD[T]HH:mm:ss[Z]' );
375 }
376
377 return {
378 type: apiData.section,
379 foreign: false,
380 source: 'local',
381 count: apiData.count,
382 read: !!apiData.read,
383 seen: (
384 !!apiData.read ||
385 utcTimestamp <= this.manager.getSeenTime()
386 ),
387 timestamp: utcTimestamp,
388 category: apiData.category,
389 content: {
390 header: content.header,
391 compactHeader: content.compactHeader,
392 body: content.body
393 },
394 iconUrl: content.iconUrl,
395 iconType: content.icon,
396 primaryUrl: OO.getProp( content.links, 'primary', 'url' ),
397 secondaryUrls: OO.getProp( content.links, 'secondary' ) || [],
398 bundledIds: apiData.bundledIds,
399 bundledNotifications: apiData.bundledNotifications
400 };
401 };
402
403 /**
404 * Mark all items within a given list model as read.
405 *
406 * NOTE: This method is strictly for list models, and will not work for
407 * group list models. To mark items as read in the xwiki model, whether
408 * it is pre-populated or not, please see #markEntireCrossWikiItemAsRead
409 *
410 * @param {string} [modelName] Symbolic name for the model
411 * @param {boolean} [isRead=true]
412 * @return {jQuery.Promise} Promise that is resolved when all items
413 * were marked as read.
414 */
415 mw.echo.Controller.prototype.markEntireListModelRead = function ( modelName, isRead ) {
416 const itemIds = [],
417 model = this.manager.getNotificationModel( modelName || 'local' );
418
419 if ( !model ) {
420 // Model doesn't exist
421 return $.Deferred().reject();
422 }
423
424 // Default to true
425 isRead = isRead === undefined ? true : isRead;
426
427 const items = model.getItems();
428 for ( let i = 0; i < items.length; i++ ) {
429 const item = items[ i ];
430 if ( item.isRead() !== isRead ) {
431 itemIds.push( item.getId() );
432 }
433 }
434
435 return this.markItemsRead( itemIds, model.getName(), isRead );
436 };
437
438 /**
439 * Mark all notifications of a certain source as read, even those that
440 * are not currently displayed.
441 *
442 * @param {string} [source] Notification source. If not given, the currently
443 * selected source is used.
444 * @return {jQuery.Promise} A promise that is resolved after
445 * all notifications for the given source were marked as read
446 */
447 mw.echo.Controller.prototype.markAllRead = function ( source ) {
448 const itemIds = [],
449 readState = this.manager.getFiltersModel().getReadState(),
450 localCounter = this.manager.getLocalCounter();
451
452 source = source || this.manager.getFiltersModel().getSourcePagesModel().getCurrentSource();
453
454 this.manager.getNotificationsBySource( source ).forEach( ( notification ) => {
455 if ( !notification.isRead() ) {
456 itemIds.push( ...notification.getAllIds() );
457 notification.toggleRead( true );
458
459 if ( readState === 'unread' ) {
460 // Remove the items if we are in 'unread' filter state
461 const model = this.manager.getNotificationModel( notification.getModelName() );
462 model.discardItems( notification );
463 }
464 }
465 } );
466
467 // Update pagination count
468 this.manager.updateCurrentPageItemCount();
469
470 localCounter.estimateChange( -itemIds.length );
471 return this.api.markAllRead(
472 source,
473 this.getTypes()
474 ).then(
475 this.refreshUnreadCount.bind( this )
476 ).then(
477 localCounter.update.bind( localCounter, true )
478 );
479 };
480
481 /**
482 * Mark all local notifications as read
483 *
484 * @return {jQuery.Promise} Promise that is resolved when all
485 * local notifications have been marked as read.
486 */
487 mw.echo.Controller.prototype.markLocalNotificationsRead = function () {
488 const readState = this.manager.getFiltersModel().getReadState(),
489 modelItems = {};
490
491 this.manager.getLocalNotifications().forEach( ( notification ) => {
492 if ( !notification.isRead() ) {
493 notification.toggleRead( true );
494
495 const modelName = notification.getModelName();
496 modelItems[ modelName ] = modelItems[ modelName ] || [];
497 modelItems[ modelName ].push( notification );
498 }
499 } );
500
501 // Remove the items if we are in 'unread' filter state
502 if ( readState === 'unread' ) {
503 for ( const name in modelItems ) {
504 const model = this.manager.getNotificationModel( name );
505 model.discardItems( modelItems[ name ] );
506 }
507 }
508
509 // Update pagination count
510 this.manager.updateCurrentPageItemCount();
511
512 this.manager.getLocalCounter().setCount( 0, false );
513 return this.api.markAllRead( 'local', this.getTypeString() ).then( this.refreshUnreadCount.bind( this ) );
514 };
515
516 /**
517 * Fetch notifications from the cross-wiki sources.
518 *
519 * @return {jQuery.Promise} Promise that is resolved when all items
520 * from the cross-wiki sources are populated into the cross-wiki
521 * model.
522 */
523 mw.echo.Controller.prototype.fetchCrossWikiNotifications = function () {
524 const xwikiModel = this.manager.getNotificationModel( 'xwiki' );
525
526 if ( !xwikiModel ) {
527 // There is no xwiki notifications model, so we can't
528 // fetch into it
529 return $.Deferred().reject().promise();
530 }
531
532 return this.api.fetchNotificationGroups( xwikiModel.getSourceNames(), this.manager.getTypeString(), true )
533 .then(
534 ( groupList ) => {
535 for ( const group in groupList ) {
536 const listModel = xwikiModel.getItemBySource( group );
537 const groupItems = groupList[ group ];
538
539 const items = [];
540 for ( let i = 0; i < groupItems.length; i++ ) {
541 const notifData = this.createNotificationData( groupItems[ i ] );
542 items.push(
543 new mw.echo.dm.NotificationItem( groupItems[ i ].id, Object.assign( notifData, {
544 modelName: 'xwiki',
545 source: group,
546 bundled: true,
547 foreign: true
548 } ) )
549 );
550 }
551 // Add items
552 listModel.setItems( items );
553 }
554 },
555 ( errCode, errObj ) => ( {
556 errCode: errCode,
557 errInfo: errCode === 'http' ?
558 mw.msg( 'echo-api-failure-cross-wiki' ) :
559 OO.getProp( errObj, 'error', 'info' )
560 } )
561 );
562 };
563
564 /**
565 * Mark local items as read in the API.
566 *
567 * @param {string[]|string} itemIds An array of item IDs, or a single item ID, to mark as read
568 * @param {string} modelName The name of the model that these items belong to
569 * @param {boolean} [isRead=true] The read state of the item; true for marking the
570 * item as read, false for marking the item as unread
571 * @return {jQuery.Promise} A promise that is resolved when the operation
572 * is complete, with the number of unread notifications still remaining
573 * for the set type of this controller, in the given source.
574 */
575 mw.echo.Controller.prototype.markItemsRead = function ( itemIds, modelName, isRead ) {
576 const model = this.manager.getNotificationModel( modelName ),
577 readState = this.manager.getFiltersModel().getReadState(),
578 allIds = [];
579
580 itemIds = Array.isArray( itemIds ) ? itemIds : [ itemIds ];
581
582 // Default to true
583 isRead = isRead === undefined ? true : isRead;
584
585 const items = model.findByIds( itemIds );
586
587 // If we are only looking at specific read state,
588 // then we need to make sure the items are removed
589 // from the visible list, because they no longer
590 // correspond with the chosen state filter
591 if ( readState === 'read' && !isRead ) {
592 model.discardItems( items );
593 } else if ( readState === 'unread' && isRead ) {
594 model.discardItems( items );
595 // TODO: We should also find a way to update the pagination
596 // here properly. Do we pull more items from the next page
597 // when items are cleared? Do we set some threshhold for
598 // removed items where if it is reached, we update the list
599 // to reflect the new pagination? etc.
600 }
601
602 items.forEach( ( notification ) => {
603 allIds.push( ...notification.getAllIds() );
604 if ( readState === 'all' ) {
605 notification.toggleRead( isRead );
606 }
607 } );
608
609 // Update pagination count
610 this.manager.updateCurrentPageItemCount();
611
612 this.manager.getUnreadCounter().estimateChange( isRead ? -allIds.length : allIds.length );
613 if ( modelName !== 'xwiki' ) {
614 // For the local counter, we should only estimate the change if the items
615 // are not cross-wiki
616 this.manager.getLocalCounter().estimateChange( isRead ? -allIds.length : allIds.length );
617 }
618
619 return this.api.markItemsRead( allIds, model.getSource(), isRead ).then( this.refreshUnreadCount.bind( this ) );
620 };
621
622 /**
623 * Mark cross-wiki items as read in the API.
624 *
625 * @param {string[]|string} itemIds An array of item IDs, or a single item ID, to mark as read
626 * @param {string} source The name for the source list that these items belong to
627 * @return {jQuery.Promise} A promise that is resolved when the operation
628 * is complete, with the number of unread notifications still remaining
629 * for the set type of this controller, in the given source.
630 */
631 mw.echo.Controller.prototype.markCrossWikiItemsRead = function ( itemIds, source ) {
632 const allIds = [],
633 xwikiModel = this.manager.getNotificationModel( 'xwiki' );
634
635 if ( !xwikiModel ) {
636 return $.Deferred().reject().promise();
637 }
638 itemIds = Array.isArray( itemIds ) ? itemIds : [ itemIds ];
639
640 const sourceModel = xwikiModel.getList().getGroupByName( source );
641 const notifs = sourceModel.findByIds( itemIds );
642 sourceModel.discardItems( notifs );
643 // Update pagination count
644 this.manager.updateCurrentPageItemCount();
645
646 notifs.forEach( ( notif ) => {
647 allIds.push( ...notif.getAllIds() );
648 } );
649 this.manager.getUnreadCounter().estimateChange( -allIds.length );
650 return this.api.markItemsRead( allIds, source, true )
651 .then( this.refreshUnreadCount.bind( this ) );
652 };
653
654 /**
655 * Mark all cross-wiki notifications from all sources as read
656 *
657 * @return {jQuery.Promise} Promise that is resolved when all notifications
658 * are marked as read
659 */
660 mw.echo.Controller.prototype.markEntireCrossWikiItemAsRead = function () {
661 const xwikiModel = this.manager.getNotificationModel( 'xwiki' );
662
663 if ( !xwikiModel ) {
664 return $.Deferred().reject().promise();
665 }
666
667 this.manager.getUnreadCounter().estimateChange( -xwikiModel.getCount() );
668
669 return this.api.fetchNotificationGroups( xwikiModel.getSourceNames(), this.manager.getTypeString() )
670 .then( ( groupList ) => {
671 const promises = [];
672
673 for ( const group in groupList ) {
674 const listModel = xwikiModel.getItemBySource( group );
675 const groupItems = groupList[ group ];
676
677 const idArray = [];
678 for ( let i = 0; i < groupItems.length; i++ ) {
679 idArray.push( groupItems[ i ].id, ...( groupItems[ i ].bundledIds || [] ) );
680 }
681
682 // Mark items as read in the API
683 promises.push(
684 this.api.markItemsRead( idArray, listModel.getName(), true )
685 );
686 }
687
688 // Synchronously remove this model from the widget
689 this.removeCrossWikiItem();
690
691 return mw.echo.api.NetworkHandler.static.waitForAllPromises( promises ).then(
692 this.refreshUnreadCount.bind( this )
693 );
694 } );
695 };
696
697 /**
698 * Remove the entire cross-wiki model.
699 */
700 mw.echo.Controller.prototype.removeCrossWikiItem = function () {
701 this.manager.removeNotificationModel( 'xwiki' );
702 };
703
704 /**
705 * Refresh the unread notifications counter
706 *
707 * @return {jQuery.Promise} A promise that is resolved when the counter
708 * is updated with the actual unread count from the server.
709 */
710 mw.echo.Controller.prototype.refreshUnreadCount = function () {
711 return this.manager.getUnreadCounter().update();
712 };
713
714 /**
715 * Update global seenTime for all sources
716 *
717 * @return {jQuery.Promise} A promise that is resolved when the
718 * seenTime was updated for all the controller's types and sources.
719 */
720 mw.echo.Controller.prototype.updateSeenTime = function () {
721 return this.api.updateSeenTime(
722 this.getTypes(),
723 // For consistency, use current source, though seenTime
724 // will be updated globally
725 this.manager.getFiltersModel().getSourcePagesModel().getCurrentSource()
726 )
727 .then( ( time ) => {
728 this.manager.getSeenTimeModel().setSeenTime( time );
729 } );
730 };
731
732 /**
733 * Perform a dynamic action
734 *
735 * @param {Object} data Action data for the network
736 * @param {string} [source] Requested source to query. Defaults to currently
737 * selected source.
738 * @return {jQuery.Promise} jQuery promise that resolves when the action is done
739 */
740 mw.echo.Controller.prototype.performDynamicAction = function ( data, source ) {
741 source = source || this.manager.getFiltersModel().getSourcePagesModel().getCurrentSource();
742 return this.api.queryAPI( data, source );
743 };
744
745 /**
746 * Get the types associated with the controller and model
747 *
748 * @return {string[]} Notification types
749 */
750 mw.echo.Controller.prototype.getTypes = function () {
751 return this.manager.getTypes();
752 };
753
754 /**
755 * Return a string representation of the notification type.
756 * It could be 'alert', 'message' or, if both are set, 'all'
757 *
758 * @return {string} String representation of notifications type
759 */
760 mw.echo.Controller.prototype.getTypeString = function () {
761 return this.manager.getTypeString();
762 };
763 }() );