Debian Codegraph @

extensions/Echo/modules/mobile/list.js

raw symbols SCIP
1 const mobile = require( 'mobile.startup' ),
2 View = mobile.View,
3 promisedView = mobile.promisedView;
4
5 /**
6 * @module module:ext.echo.mobile
7 */
8
9 /**
10 * @typedef {Function} FunctionCountChangeCallback
11 * @memberof module:ext.echo.mobile
12 * @param {number} count a capped (0-99 or 99+) count
13 */
14
15 /**
16 * List of notifications
17 *
18 * @param {mw.echo} echo class
19 * @param {OO.ui.ButtonWidget} markAllReadButton - a button that will be associated with the
20 * read status of the notifications list.
21 * @param {module:ext.echo.mobile.FunctionCountChangeCallback} onCountChange callback.
22 * @return {View}
23 */
24 function notificationsList( echo, markAllReadButton, onCountChange ) {
25 const maxNotificationCount = require( './config.json' ).EchoMaxNotificationCount,
26 echoApi = new echo.api.EchoApi(),
27 unreadCounter = new echo.dm.UnreadNotificationCounter( echoApi, 'all', maxNotificationCount ),
28 modelManager = new echo.dm.ModelManager( unreadCounter, { type: [ 'message', 'alert' ] } ),
29 controller = new echo.Controller(
30 echoApi,
31 modelManager,
32 {
33 type: [ 'message', 'alert' ]
34 }
35 ),
36 markAsReadHandler = function () {
37 markAllReadButton.toggle(
38 controller.manager.hasLocalUnread()
39 );
40 markAllReadButton.setTitle(
41 mw.msg( 'echo-mark-all-as-read', unreadCounter.getCount() )
42 );
43 },
44 // Create a container which will be revealed when "more options" (...)
45 // is clicked on a notification. Hidden by default.
46 $moreOptions = $( '<div>' )
47 .addClass( 'notifications-overlay-overlay position-fixed skin-invert' );
48
49 echo.config.maxPrioritizedActions = 1;
50
51 const wrapperWidget = new echo.ui.NotificationsWrapper( controller, modelManager, {
52 $overlay: $moreOptions
53 } );
54
55 // Events
56 unreadCounter.on( 'countChange', ( count ) => {
57 onCountChange(
58 controller.manager.getUnreadCounter().getCappedNotificationCount( count )
59 );
60 markAsReadHandler();
61 } );
62 markAllReadButton.on( 'click', () => {
63 const numNotifications = controller.manager.getLocalUnread().length;
64
65 controller.markLocalNotificationsRead()
66 .then( () => {
67 mw.notify( mw.msg( 'echo-mark-all-as-read-confirmation', numNotifications ) );
68 markAllReadButton.toggle( false );
69 }, () => {
70 markAllReadButton.toggle( false );
71 } );
72 } );
73
74 return promisedView(
75 // Populate notifications
76 wrapperWidget.populate().then( () => {
77 controller.updateSeenTime();
78 markAsReadHandler();
79 // Connect event here as we know that everything loaded correctly
80 modelManager.on( 'update', markAsReadHandler );
81 return View.make( {}, [ wrapperWidget.$element, $moreOptions ] );
82 } )
83 );
84 }
85
86 module.exports = notificationsList;